threadnetwork

package
v0.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Rendered for darwin/amd64

Overview

Package threadnetwork provides a fluent Go API over the macOS ThreadNetwork framework.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type THClient

type THClient struct {
	// contains filtered or unexported fields
}

A class that supports safely sharing Thread credentials between multiple clients. Request credentials for either a specific Thread network or for the _preferred network_ using `THClient`. The preferred network is the default Thread network chosen by the framework for a home. The ThreadNetwork framework maintains a database of network credentials. The class allows clients to store, list, and delete credentials for a given network from the database. Some methods in `THClient` use the _team ID_, a string that you store in your application’s `Info.plist`. The ThreadNetwork framework uses the team ID to preserve the privacy of the Thread network credentials across different clients. For example, credentials stored by one client can’t be deleted or modified by another client. - Important: Thread credentials give you the ability to add any device into the Thread network. Use this information responsibly.

THClient wraps raw.THClient with a fluent Go API.

func NewTHClient

func NewTHClient() *THClient

NewTHClient creates a new THClient.

func THClientFromID

func THClientFromID(id objc.ID) *THClient

THClientFromID adopts an existing object pointer as a THClient (nil for 0).

func (*THClient) CheckPreferredNetworkForActiveOperationalDatasetCompletion

func (x *THClient) CheckPreferredNetworkForActiveOperationalDatasetCompletion(activeOperationalDataSet *foundation.NSData, completion func(bool))

Determines if the essential operating parameters match the preferred network’s parameters. - Parameters: - activeOperationalDataSet: The essential operating parameters to compare against the preferred network’s parameters. - completion: The completion handler that returns the result of the comparison. > Concurrency Note: You can call this method from synchronous code using a completion handler, > as shown on this page, or you can call it as an asynchronous method that has the > following declaration: > > ```swift > func isPreferred(forActiveOperationalDataset activeOperationalDataSet: Data) async -> Bool > ``` > > For information about concurrency and asynchronous code in Swift, see <doc://com.apple.documentation/documentation/swift/calling-objective-c-apis-asynchronously>.

CheckPreferredNetworkForActiveOperationalDatasetCompletion calls the underlying CheckPreferredNetworkForActiveOperationalDatasetCompletion.

func (*THClient) DeleteCredentialsForBorderAgentCompletion

func (x *THClient) DeleteCredentialsForBorderAgentCompletion(ctx context.Context, borderAgentID *foundation.NSData) error

Deletes Thread network credentials from the framework database for a Border Agent. The Border Agent is the software component running in the Border Router responsible for advertising itself in the Wi-Fi or Ethernet network. - Parameters: - borderAgentID: The identifer of a Thread network Border Agent. - completion: The completion handler the framework calls after deleting the credentials. > Concurrency Note: You can call this method from synchronous code using a completion handler, > as shown on this page, or you can call it as an asynchronous method that has the > following declaration: > > ```swift > func deleteCredentials(forBorderAgent borderAgentID: Data) async throws > ``` > > For information about concurrency and asynchronous code in Swift, see <doc://com.apple.documentation/documentation/swift/calling-objective-c-apis-asynchronously>.

DeleteCredentialsForBorderAgentCompletion blocks until the operation completes or ctx is cancelled.

func (*THClient) ID

func (x *THClient) ID() objc.ID

ID returns the underlying Objective-C object pointer (objc.ID), for passing to C APIs that take an object or CFTypeRef pointer.

func (*THClient) IsPreferredNetworkAvailableWithCompletion

func (x *THClient) IsPreferredNetworkAvailableWithCompletion(completion func(bool))

Determines if the preferred network is available or not - Parameters: - completion: The completion handler that returns the result of the preferred network availability. > Concurrency Note: You can call this method from synchronous code using a completion handler, > as shown on this page, or you can call it as an asynchronous method that has the > following declaration: > > ```swift > func isPreferredAvailable() async -> Bool > ``` > > For information about concurrency and asynchronous code in Swift, see <doc://com.apple.documentation/documentation/swift/calling-objective-c-apis-asynchronously>.

IsPreferredNetworkAvailableWithCompletion calls the underlying IsPreferredNetworkAvailableWithCompletion.

func (*THClient) RetrieveAllActiveCredentials

func (x *THClient) RetrieveAllActiveCredentials(ctx context.Context) (*foundation.NSSet[*raw.THCredentials], error)

Requests all Thread credentials with active border routers around from the framework. The framework identifies the developer by the team ID. When calling this method, you will receive credentials for active border routers around. You receive credentials for your team ID only. - Parameters: - completion: The completion handler the framework calls when the credentials become available. > Concurrency Note: You can call this method from synchronous code using a completion handler, > as shown on this page, or you can call it as an asynchronous method that has the > following declaration: > > ```swift > func allActiveCredentials() async throws -> Set<THCredentials> > ``` > > For information about concurrency and asynchronous code in Swift, see <doc://com.apple.documentation/documentation/swift/calling-objective-c-apis-asynchronously>.

RetrieveAllActiveCredentials blocks until the operation completes or ctx is cancelled.

func (*THClient) RetrieveAllCredentials

func (x *THClient) RetrieveAllCredentials(ctx context.Context) (*foundation.NSSet[*raw.THCredentials], error)

Requests all Thread credentials from the framework. The framework identifies the developer by the team ID. When calling this method, you receive credentials for your team ID only. - Parameters: - completion: The completion handler the framework calls when the credentials become available. > Concurrency Note: You can call this method from synchronous code using a completion handler, > as shown on this page, or you can call it as an asynchronous method that has the > following declaration: > > ```swift > func allCredentials() async throws -> Set<THCredentials> > ``` > > For information about concurrency and asynchronous code in Swift, see <doc://com.apple.documentation/documentation/swift/calling-objective-c-apis-asynchronously>.

RetrieveAllCredentials blocks until the operation completes or ctx is cancelled.

func (*THClient) RetrieveCredentialsForBorderAgentCompletion

func (x *THClient) RetrieveCredentialsForBorderAgentCompletion(ctx context.Context, borderAgentID *foundation.NSData) (*THCredentials, error)

Requests Thread credentials for a Border Agent. The framework identifies the developer by the team ID. When calling this method, you receive credentials for your team ID only. - Parameters: - borderAgentID: The identifer of a Thread network Border Agent. - completion: The completion handler the framework calls when the credentials become available. > Concurrency Note: You can call this method from synchronous code using a completion handler, > as shown on this page, or you can call it as an asynchronous method that has the > following declaration: > > ```swift > func credentials(forBorderAgentID borderAgentID: Data) async throws -> THCredentials > ``` > > For information about concurrency and asynchronous code in Swift, see <doc://com.apple.documentation/documentation/swift/calling-objective-c-apis-asynchronously>.

RetrieveCredentialsForBorderAgentCompletion blocks until the operation completes or ctx is cancelled.

func (*THClient) RetrieveCredentialsForExtendedPANIDCompletion

func (x *THClient) RetrieveCredentialsForExtendedPANIDCompletion(ctx context.Context, extendedPANID *foundation.NSData) (*THCredentials, error)

Requests Thread credentials for an extended Personal Area Network (PAN) ID. When calling this method, an alert appears asking for user permission to access credentials. - Parameters: - extendedPANID: The extended PAN identifier. - completion: The completion handler the framework calls when the credentials become available. > Concurrency Note: You can call this method from synchronous code using a completion handler, > as shown on this page, or you can call it as an asynchronous method that has the > following declaration: > > ```swift > func credentials(forExtendedPANID extendedPANID: Data) async throws -> THCredentials > ``` > > For information about concurrency and asynchronous code in Swift, see <doc://com.apple.documentation/documentation/swift/calling-objective-c-apis-asynchronously>.

RetrieveCredentialsForExtendedPANIDCompletion blocks until the operation completes or ctx is cancelled.

func (*THClient) RetrievePreferredCredentials

func (x *THClient) RetrievePreferredCredentials(ctx context.Context) (*THCredentials, error)

Requests Thread credentials for the preferred network. When you call this method, an alert appears asking for user permission to access credentials. - Parameters: - completion: The completion handler the framework calls when the credentials become available. > Concurrency Note: You can call this method from synchronous code using a completion handler, > as shown on this page, or you can call it as an asynchronous method that has the > following declaration: > > ```swift > func preferredCredentials() async throws -> THCredentials > ``` > > For information about concurrency and asynchronous code in Swift, see <doc://com.apple.documentation/documentation/swift/calling-objective-c-apis-asynchronously>.

RetrievePreferredCredentials blocks until the operation completes or ctx is cancelled.

func (*THClient) StoreCredentialsForBorderAgentActiveOperationalDataSetCompletion

func (x *THClient) StoreCredentialsForBorderAgentActiveOperationalDataSetCompletion(ctx context.Context, borderAgentID *foundation.NSData, activeOperationalDataSet *foundation.NSData) error

Stores Thread network credentials into the framework database that a Border Agent provides. The Border Agent is the software component running in the Border Router responsible for advertising itself in the Wi-Fi or Ethernet network. The framework only stores credentials if it can find an mDNS record for the Border Agent that contains the specified Border Agent identifier. - Parameters: - borderAgentID: The identifer of an active Thread network Border Agent. - activeOperationalDataSet: The essential operational parameters for the Thread network. - completion: The completion handler the framework calls after storing the credentials. > Concurrency Note: You can call this method from synchronous code using a completion handler, > as shown on this page, or you can call it as an asynchronous method that has the > following declaration: > > ```swift > func storeCredentials(forBorderAgent borderAgentID: Data, activeOperationalDataSet: Data) async throws > ``` > > For information about concurrency and asynchronous code in Swift, see <doc://com.apple.documentation/documentation/swift/calling-objective-c-apis-asynchronously>.

StoreCredentialsForBorderAgentActiveOperationalDataSetCompletion blocks until the operation completes or ctx is cancelled.

func (*THClient) Unwrap

func (x *THClient) Unwrap() *raw.THClient

Unwrap returns the underlying raw.THClient.

type THClientable

type THClientable interface {
	Unwrap() *raw.THClient
	RetrieveAllCredentials(ctx context.Context) (*foundation.NSSet[*raw.THCredentials], error)
	RetrieveAllActiveCredentials(ctx context.Context) (*foundation.NSSet[*raw.THCredentials], error)
	DeleteCredentialsForBorderAgentCompletion(ctx context.Context, borderAgentID *foundation.NSData) error
	RetrieveCredentialsForBorderAgentCompletion(ctx context.Context, borderAgentID *foundation.NSData) (*THCredentials, error)
	StoreCredentialsForBorderAgentActiveOperationalDataSetCompletion(ctx context.Context, borderAgentID *foundation.NSData, activeOperationalDataSet *foundation.NSData) error
	RetrievePreferredCredentials(ctx context.Context) (*THCredentials, error)
	RetrieveCredentialsForExtendedPANIDCompletion(ctx context.Context, extendedPANID *foundation.NSData) (*THCredentials, error)
	CheckPreferredNetworkForActiveOperationalDatasetCompletion(activeOperationalDataSet *foundation.NSData, completion func(bool))
	IsPreferredNetworkAvailableWithCompletion(completion func(bool))
}

THClientable is the interface implemented by THClient, for mocking and DI.

type THCredentials

type THCredentials struct {
	// contains filtered or unexported fields
}

A class that contains credentials for a Thread network. A Thread network defines parameters that all connected devices use. “THCredentials“ provides these parameters.

THCredentials wraps raw.THCredentials with a fluent Go API.

func NewTHCredentials

func NewTHCredentials() *THCredentials

NewTHCredentials creates a new THCredentials.

func THCredentialsFromID

func THCredentialsFromID(id objc.ID) *THCredentials

THCredentialsFromID adopts an existing object pointer as a THCredentials (nil for 0).

func (*THCredentials) ActiveOperationalDataSet

func (x *THCredentials) ActiveOperationalDataSet() *foundation.NSData

The essential operational parameters for the Thread network. The framework parses this property, then extracts and sets “THCredentials/channel“, “THCredentials/extendedPANID“, “THCredentials/networkKey“, “THCredentials/networkName“, “THCredentials/panID“, and “THCredentials/PSKC“ when you call “THClient/storeCredentialsForBorderAgent:activeOperationalDataSet:completion:“.

ActiveOperationalDataSet calls the underlying ActiveOperationalDataSet.

func (*THCredentials) BorderAgentID

func (x *THCredentials) BorderAgentID() *foundation.NSData

The identifer of an active Thread network Border Agent. This property’s value is the MAC Extended Address, a random identifier that the active Thread network border router generates.

BorderAgentID calls the underlying BorderAgentID.

func (*THCredentials) Channel

func (x *THCredentials) Channel() uint8

The Thread network radio channel.

Channel calls the underlying Channel.

func (*THCredentials) CreationDate

func (x *THCredentials) CreationDate() *foundation.NSDate

The date and time that the framework stored the credential in the database.

CreationDate calls the underlying CreationDate.

func (*THCredentials) ExtendedPANID

func (x *THCredentials) ExtendedPANID() *foundation.NSData

The Thread network extended PAN identifier.

ExtendedPANID calls the underlying ExtendedPANID.

func (*THCredentials) ID

func (x *THCredentials) ID() objc.ID

ID returns the underlying Objective-C object pointer (objc.ID), for passing to C APIs that take an object or CFTypeRef pointer.

func (*THCredentials) LastModificationDate

func (x *THCredentials) LastModificationDate() *foundation.NSDate

The date and time that the framework updated the credential in the database.

LastModificationDate calls the underlying LastModificationDate.

func (*THCredentials) NetworkKey

func (x *THCredentials) NetworkKey() *foundation.NSData

The sixteen byte Thread network key.

NetworkKey calls the underlying NetworkKey.

func (*THCredentials) NetworkName

func (x *THCredentials) NetworkName() string

The Thread network name.

NetworkName calls the underlying NetworkName.

func (*THCredentials) PSKC

func (x *THCredentials) PSKC() *foundation.NSData

The sixteen byte Thread network pre-shared key for the Commissioner.

PSKC calls the underlying PSKC.

func (*THCredentials) PanID

func (x *THCredentials) PanID() *foundation.NSData

The two byte Thead network PAN identifier.

PanID calls the underlying PanID.

func (*THCredentials) SetChannel

func (x *THCredentials) SetChannel(channel uint8)

SetChannel calls the underlying SetChannel.

func (*THCredentials) Unwrap

func (x *THCredentials) Unwrap() *raw.THCredentials

Unwrap returns the underlying raw.THCredentials.

func (*THCredentials) WithChannel

func (x *THCredentials) WithChannel(channel uint8) *THCredentials

The Thread network radio channel.

WithChannel sets the channel property and returns the receiver for chaining.

type THCredentialsable

type THCredentialsable interface {
	Unwrap() *raw.THCredentials
	WithChannel(channel uint8) *THCredentials
	NetworkName() string
	ExtendedPANID() *foundation.NSData
	BorderAgentID() *foundation.NSData
	ActiveOperationalDataSet() *foundation.NSData
	NetworkKey() *foundation.NSData
	PSKC() *foundation.NSData
	Channel() uint8
	SetChannel(channel uint8)
	PanID() *foundation.NSData
	CreationDate() *foundation.NSDate
	LastModificationDate() *foundation.NSDate
}

THCredentialsable is the interface implemented by THCredentials, for mocking and DI.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL