setup

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package setup encodes Matter Onboarding Payloads per Matter Core Specification 1.5.1 §5.1 (Manual Pairing Code) and §5.7 (QR Code Onboarding Payload).

Two outputs:

  • QRCode returns the "MT:..." string. The bytes are a 88-bit little-endian struct (version, vendor_id, product_id, custom_flow, discovery_caps, discriminator, passcode, padding) base38-encoded with the alphabet from §5.7.4.

  • ManualCode returns the 11-digit decimal code with a Verhoeff check digit at position 11. The 4-bit upper discriminator and the 27-bit passcode are split across the first 10 digits per §5.1.4; digit 1 carries the version + vendor/product flag.

Index

Constants

View Source
const MaxDiscriminator = 0x0FFF

MaxDiscriminator is the widest value the commissioning discriminator carries. matter.js declares the field as `BitField(45, 12)` in the QR-code payload and rejects anything above 4095 outright (packages/types/src/schema/PairingCodeSchema.ts: the QrPairingCode bit map, and the manual-pairing-code encoder's "discriminator value must be less than 4096").

It is exported because the config validator has to reject an out-of-range discriminator before the daemon boots, and a second spelling there would be a copy of this package's own bit-width rule.

View Source
const MaxQRCodeLength = 255

MaxQRCodeLength is the longest single onboarding payload, "MT:" prefix counted. Mirrors matter.js packages/types/src/schema/PairingCodeSchema.ts:40 (MATTER_QR_CODE_SINGLE_PAYLOAD_MAX_LENGTH).

Variables

View Source
var ErrInvalidCode = errors.New("setup: invalid pairing code")

ErrInvalidCode wraps every decode failure of DecodeQRCode, DecodeQRCodes and DecodeManualCode.

Functions

func IsValidPasscode added in v0.4.0

func IsValidPasscode(passcode uint32) bool

IsValidPasscode reports whether passcode is a usable setup passcode: 0x0000001..0x5F5E0FE and not one of the trivial codes. Mirrors matter.js packages/types/src/schema/PairingCodeSchema.ts:171-178 (isValidPasscode) and its list :160-162 (INVALID_PASSCODES); it is IsValidSetupPIN.

func IsValidSetupPIN

func IsValidSetupPIN(passcode uint32) bool

IsValidSetupPIN returns true when passcode is a legal Matter Setup PIN: non-zero, within the 27-bit range 1..99999998, and not in the trivial-code blacklist. Mirrors chip src/crypto/CHIPCryptoPAL.cpp IsValidSetupPIN.

func ManualCode

func ManualCode(discriminator uint16, passcode uint32) (string, error)

ManualCode returns the 11-digit manual pairing code per Matter §5.1.4.

Layout:

digit 1   :  (versionFlag<<2) | (discriminator >> 10) & 0x3
digits 2-6:  ((discriminator & 0x300) << 6) | (passcode & 0x3FFF), 5 digits
digits 7-10: passcode >> 14, 4 digits
digit 11  :  Verhoeff check digit over digits 1..10

versionFlag is 0 here (vendor + product not embedded); ManualCodeLong writes the 21-digit form that carries them. A trivial passcode is refused, as matter.js's encoder refuses it (ManualPairingCodeSchema.validate, PairingCodeSchema.ts:429-430 at b25ed960).

func ManualCodeLong added in v0.6.0

func ManualCodeLong(discriminator uint16, passcode uint32, vendorID, productID uint16) (string, error)

ManualCodeLong returns the 21-digit manual pairing code, which carries the vendor and product id after the 10 digits of the short form and sets the VID_PID_PRESENT bit of the first digit. Mirrors matter.js ManualPairingCodeSchema.encodeInternal (PairingCodeSchema.ts:440-454 at b25ed960): the first digit is (discriminator >> 10) | 1 << 2, the vendor and product id are five digits each, and the Verhoeff check digit closes the code.

func QRCode

func QRCode(p Payload) (string, error)

QRCode encodes p into the "MT:..." onboarding string per Matter §5.7. Errors out when p fails Validate, and refuses what matter.js's encoder refuses: a version other than 0 and an invalid passcode (QrPairingCodeSchema.validate, PairingCodeSchema.ts:279-286 at db021da0, INVALID_PASSCODES :160-162). The vendor/product identity rules bind a code being read only (validateDecoded, :288-293): DecodeQRCode applies them, the encoder does not.

Types

type DiscoveryCaps

type DiscoveryCaps uint8

DiscoveryCaps is the bitmap exposed in the QR onboarding payload (Matter §5.7.4 RendezvousInformation). A node advertises ON_NETWORK (bit 2), and BLE (bit 1) beside it when it has a BLE radio (node.Network.BLE, ADR 0031); Soft-AP is not served.

const (
	// DiscoveryNone disables the bitmap (commissioner-driven discovery).
	DiscoveryNone DiscoveryCaps = 0
	// DiscoverySoftAP advertises an open Soft-AP for BLE-less commissioning.
	DiscoverySoftAP DiscoveryCaps = 1 << 0
	// DiscoveryBLE advertises BLE commissioning availability.
	DiscoveryBLE DiscoveryCaps = 1 << 1
	// DiscoveryOnIP advertises mDNS commissionable.
	DiscoveryOnIP DiscoveryCaps = 1 << 2
)

type Extra added in v0.4.0

type Extra struct {
	// Raw is the TLV data as the code carries it. [QRCode] appends it
	// unchanged after the header.
	Raw []byte
	// SerialNumber is tag 0x00. The wire carries a UTF-8 string or an
	// unsigned integer; an integer is rendered in decimal and
	// SerialNumberNumeric is set.
	SerialNumber        string
	SerialNumberNumeric bool
	// PBKDFIterations (tag 0x01) and PBKDFSalt (tag 0x02) are present
	// together or not at all; 0 / nil is absent.
	PBKDFIterations uint32
	PBKDFSalt       []byte
	// NumberOfDevices is tag 0x03; 0 is absent.
	NumberOfDevices uint8
	// CommissioningTimeout is tag 0x04 in seconds;
	// HasCommissioningTimeout tells an explicit 0 from absent.
	CommissioningTimeout    uint16
	HasCommissioningTimeout bool
	// Vendor holds every manufacturer-specific element (tags 0x80..0xFF)
	// as its encoded TLV bytes, context tag included.
	Vendor map[uint8][]byte
}

Extra is the optional TLV data of a QR onboarding payload (Matter Core §5.1.5): an anonymous structure after the 88-bit header. It mirrors matter.js packages/types/src/schema/PairingCodeSchema.ts:122-142 (QrCodeTlvDataDefaultFields) plus the manufacturer-specific elements the default schema does not name.

func DecodeExtra added in v0.4.0

func DecodeExtra(b []byte) (Extra, error)

DecodeExtra decodes a QR payload's TLV data (§5.1.5). Mirrors matter.js packages/types/src/schema/PairingCodeSchema.ts:354-377 (decodeTlvData): the tag ranges of assertValidOnboardingTlvTags (:248-275), the default fields (:122-142), the PBKDF both-or-neither rule (:238-242) and a serial number that is a UTF-8 string or an unsigned integer (:358-375). Manufacturer-specific elements are kept in Extra.Vendor.

type ManualPayload added in v0.4.0

type ManualPayload struct {
	// ShortDiscriminator is the upper four bits of the 12-bit
	// discriminator, the only part a manual code carries.
	ShortDiscriminator uint8
	// Passcode is the 27-bit setup passcode.
	Passcode uint32
	// VendorID and ProductID are set by the 21-digit form only; 0 is
	// "unspecified" (§2.5.2, §2.5.3).
	VendorID  uint16
	ProductID uint16
	// HasVendorProduct is true for the 21-digit form (VID_PID_PRESENT).
	HasVendorProduct bool
}

ManualPayload is the content of a manual pairing code (Matter Core §5.1.4). Mirrors matter.js packages/types/src/schema/PairingCodeSchema.ts:409-421 (ManualPairingData) as decodeInternal fills it.

func DecodeManualCode added in v0.4.0

func DecodeManualCode(s string) (ManualPayload, error)

DecodeManualCode decodes an 11- or 21-digit manual pairing code, the inverse of ManualCode. Characters other than digits are ignored.

Mirrors matter.js packages/types/src/schema/PairingCodeSchema.ts:461-493 (ManualPairingCodeSchema.decodeInternal) followed by the default validation (packages/types/src/schema/Schema.ts:18-25): the passcode (:429-431) and the vendor/product identity (:457-459).

type Payload

type Payload struct {
	// Version is the onboarding payload format version. Matter 1.x
	// defines exactly one (0); reserved 3 bits.
	Version uint8
	// VendorID is the IANA-assigned vendor identifier (16 bits).
	VendorID uint16
	// ProductID is the vendor-assigned product identifier (16 bits).
	ProductID uint16
	// CustomFlow selects the commissioning flow. 0 = Standard, 1 =
	// User-Action-Required, 2 = Custom. 2 bits.
	CustomFlow uint8
	// DiscoveryCaps is the rendezvous bitmap. 8 bits.
	DiscoveryCaps DiscoveryCaps
	// Discriminator is the 12-bit Matter commissioning discriminator.
	Discriminator uint16
	// Passcode is the 27-bit Matter setup code (1..99999998).
	Passcode uint32
	// Extra is the optional TLV tail after the 88-bit header (§5.1.5):
	// the serial number, the PBKDF parameters and the vendor-specific
	// elements. [DecodeQRCode] fills it when the code carries a tail;
	// [QRCode] appends its Raw bytes when set. Nil means no tail.
	Extra *Extra
}

Payload is the input to QRCode. Field bit-widths match Matter §5.1.4.1.

func DecodeQRCode added in v0.4.0

func DecodeQRCode(s string) (Payload, error)

DecodeQRCode decodes a single "MT:…" onboarding payload, the inverse of QRCode. A concatenated code ("MT:a*b") is rejected; use DecodeQRCodes.

func DecodeQRCodes added in v0.4.0

func DecodeQRCodes(s string) ([]Payload, error)

DecodeQRCodes decodes an "MT:…" onboarding string, which may concatenate several payloads with '*'.

Mirrors matter.js packages/types/src/schema/PairingCodeSchema.ts:330-345 (QrPairingCodeSchema.decodeInternal) followed by the validation decode runs by default (packages/types/src/schema/Schema.ts:18-25): version 0 and a valid passcode (:279-286), the vendor/product identity (:289-293). A TLV tail is parsed with DecodeExtra when it decodes and kept as raw bytes otherwise.

func (Payload) Validate

func (p Payload) Validate() error

Validate returns nil when the payload's bit-widths are observed.

Jump to

Keyboard shortcuts

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