This source candidate declares SDK peer ^2.4.1 || ^3.0.0 || ^4.0.1. SDK3 remains
a coordinated proposal; see the qualification and migration limits
before adopting it.
@bsv/sigma-permission-module is a BRC-98 wallet permission module for the
scheme sigma. A wallet host installs it under permissionModules: { sigma };
applications then call the wallet's existing encrypt method and receive a
public point or a zero-knowledge proof in { ciphertext }. The secret scalar
never leaves the wallet. This lets Bitcoin Script contracts that verify
Schnorr-style Sigma-protocol proofs ("s-puzzles") be unlocked with a
wallet-held key.
The specification is BRC-230 (in review).
The proof scalar is derived from the BRC-42 child key and is never the child key itself (scalar isolation).
npm install @bsv/sigma-permission-module @bsv/wallet-toolbox-client @bsv/sdkApplications call encrypt with a protocol name of this form inside the normal
BRC-43 [securityLevel, protocolName] tuple:
p sigma <operation> <logicalProtocolID>operation is one of key, schnorr, dleq or or. The logical protocol ID
is lowercase letters, digits and single spaces, 5 to 272 characters, and does
not end in protocol. The key ID is 1 to 800 bytes of UTF-8. The counterparty,
privileged selection and privileged reason stay in their existing encrypt
fields. The wallet derives the BRC-42/43 child key for
[securityLevel, "p sigma " + logicalProtocolID], the key ID and the
counterparty. The operation is not part of the derivation, so every operation
under one logical protocol proves statements about the same point.
const { ciphertext } = await wallet.encrypt(
{
protocolID: [2, 'p sigma key example payout'],
keyID: 'member 1',
plaintext: []
},
'app.example'
)
// ciphertext: the 33-byte compressed statement point PUse level 1 or 2 for a key that guards value; level 0 needs no prompt (see Security and permissions).
The module is deterministic: the same request always returns the same bytes.
The plaintext of the encrypt call is a byte array. The challenge is the
SHA-256 of the operation's tag followed by its transcript, read as a
little-endian integer, modulo the group order. The tag is the 20 ASCII bytes
p sigma v1 challenge followed by the operation byte: 0x01 for schnorr,
0x02 for dleq, and 0x03 then n (one byte, the ring size) for or.
| Operation | Plaintext | Result | Transcript hashed for the challenge |
|---|---|---|---|
key | empty, or a 33-byte point H | P (33 bytes), or x·H (33 bytes); no proof | none |
schnorr | ctx | R ‖ s (96 bytes) | R ‖ P ‖ ctx |
dleq | H ‖ ctx | P2 ‖ R1 ‖ R2 ‖ s (224 bytes), with P2 = x·H | R1 ‖ R2 ‖ P ‖ P2 ‖ H ‖ ctx |
or | n ‖ i ‖ others ‖ ctx | R_1…R_n ‖ s_1…s_n ‖ e_1…e_(n−1) | R_1…R_n ‖ P_1…P_n ‖ ctx |
For or, n is one byte from 2 to 8 and i is one byte, the wallet's 1-based
position in the ring. others is the other n − 1 points in ring order, and
the wallet inserts its own point P at position i. The last challenge is not
returned; the verifier derives it. A ring that already contains the wallet's
point is refused.
ctx is 1 to 4,096 application-chosen bytes and is opaque to the module.
key results are compressed. The application expands them where a contract
takes 64 bytes.Create the module with the wallet's ordinary KeyDeriverApi and an
authorization callback, then register it under the sigma scheme:
import { createSigmaModule } from '@bsv/sigma-permission-module'
import { WalletPermissionsManager } from '@bsv/wallet-toolbox-client'
const sigma = createSigmaModule({
keyDeriver: setup.keyDeriver,
authorize: async request => {
return await showTrustedWalletPrompt({
originator: request.originator,
protocol: request.logicalProtocolID,
counterparty: request.counterparty,
privileged: request.privileged,
operation: request.operation,
applicationBase: request.applicationBase,
contextSha256: request.contextSha256,
inputSha256: request.inputSha256
})
},
privilegedKeyDeriver: async reason => {
return await acquirePrivilegedKeyDeriver(reason)
},
authorizationTTL: 5 * 60 * 1000,
proofAuthorization: 'each'
})
const wallet = new WalletPermissionsManager(setup.wallet, adminOriginator, {
permissionModules: { sigma }
})authorizationTTL is how long a remembered approval lasts, in milliseconds,
and defaults to five minutes.
proofAuthorization chooses how requests that need authorization are
authorized:
'each' (the default): an approved key request with no base is remembered
for authorizationTTL and covers only later key requests with no base.
Every key request with a base, and every schnorr, dleq and or
request, calls authorize, and its approval covers that one request.'grant': one approval is remembered as a grant covering every operation,
any context and any key ID under that logical protocol for
authorizationTTL.'each' is the default because a proof can release coins locked to its
statement point, and no spending authorization stands behind it. Any other
value is refused when the module is created.
Call sigma.dispose() when the host tears down the wallet. It clears cached
and pending authorization state, and the module refuses every later request,
security level 0 included, and including one whose prompt was still open; no
key is derived for it. Disposal is final: a host that needs to continue
constructs a new module.
The authorization request passed to authorize carries the originator, the
security level, the logical protocol ID, the key ID, the counterparty, the
privileged flag and reason, and the operation, plus:
contextSha256: the lowercase hex SHA-256 of ctx, for schnorr, dleq
and or.applicationBase: true when the application chose the base point, that
is for key with a base and for every dleq.inputSha256: the lowercase hex SHA-256 of the whole operation input, the
request's plaintext as received (for key with no base, the hash of zero
bytes).Authorization is scoped as follows; under proofAuthorization: 'grant' these
are BRC-43 permission semantics:
privilegedReason, separate from non-privileged
grants.seekPermission: false fails unless an applicable grant is already cached;
under 'each' that is possible only for key with no base.Under the default proofAuthorization: 'each', only a plain public-key
request is remembered; every proof, and every key request with a base, is
authorized on its own. Concurrent requests share one pending decision only
when they are identical: the same grant scope, operation, key ID,
counterparty and whole input.
Under proofAuthorization: 'grant', a grant is not scoped by operation or
context. Once granted, it covers every operation and any context under that
logical protocol until it expires, and concurrent requests in one grant scope
share one pending decision. The operation, contextSha256,
applicationBase and inputSha256 fields of an authorisation request are then
information for the prompt, not a limit on what the grant allows.
A proof spends whatever was locked to the statement point. Under 'grant', an
application with a grant can therefore spend those outputs without asking
again.
Limits to know before relying on a key:
key with a base and dleq return x·H for any base H the caller
chooses. That value is not a secret and must never be used as one.or proof hides which ring member proved only from
parties without that access.H must differ from the generator. Ring points must be distinct and must not
include the wallet's own point.true; any other value is a
denial.'each', each distinct
request in flight counts as one. A request beyond the limit fails with
"Sigma: authorization queue is full" until a pending decision settles.plaintext must be a plain array of byte values; a Uint8Array is refused.parsePoint33.The module accepts only encrypt. It refuses every other method the wallet
host routes to it, and every basket or label beginning p sigma that reaches
it. Authorization precedes key derivation. The module is trusted wallet code:
applications never receive a key deriver or a private scalar.
xkey with a base and dleq return x·H for a base H the application
chooses, so together they are a static Diffie–Hellman oracle on x:
x·H is not a secret and must not be used as one. Never reuse a sigma key as
a Diffie–Hellman secret.x. Applications that need the full strength of a long-lived
key should limit the number of distinct bases they request.proofAuthorization: 'each', the default, each one is authorized on its
own; under 'grant', one approval covers every such request until the
grant expires.applicationBase: true, so the
host can tell them apart and may bound their rate.The package exports the pure verifiers so that a contract author or test can
check a result off-chain. They take parsed points; parsePoint33 and point64
convert between the encodings above.
import { Utils } from '@bsv/sdk'
import { parsePoint33, verifySchnorr } from '@bsv/sigma-permission-module'
const ctx = Utils.toArray('payout 7', 'utf8')
const key = await wallet.encrypt(
{ protocolID: [2, 'p sigma key example payout'], keyID: 'member 1', plaintext: [] },
'app.example'
)
const proof = await wallet.encrypt(
{ protocolID: [2, 'p sigma schnorr example payout'], keyID: 'member 1', plaintext: ctx },
'app.example'
)
const P = parsePoint33(key.ciphertext, 'P')
verifySchnorr(P, ctx, proof.ciphertext) // trueverifyDleq(P, H, ctx, result) and verifyOr(ring, ctx, result) check the
other two proofs the same way.
| Export | Purpose |
|---|---|
SigmaPermissionModule | The module class; implements PermissionsModule. |
createSigmaModule | Creates a module from SigmaPermissionModuleOptions. |
verifySchnorr | Verifies a schnorr result against P and ctx. |
verifyDleq | Verifies a dleq result against P, H and ctx. |
verifyOr | Verifies an or result against the ring and ctx. |
parsePoint33 | Parses a 33-byte compressed point, rejecting the identity and off-curve points. |
point64 | Encodes a point as 64 bytes, x then y, big-endian. |
The types SigmaPermissionModuleOptions, SigmaAuthorizationRequest,
SigmaAuthorizationHandler, SigmaKeyDeriver, SigmaPrivilegedKeyDeriver,
SigmaProofAuthorization and SigmaOperation are exported too.
pnpm --filter @bsv/sdk build
pnpm --filter @bsv/wallet-toolbox-client build
pnpm --filter @bsv/sigma-permission-module typecheck
pnpm --filter @bsv/sigma-permission-module lint
pnpm --filter @bsv/sigma-permission-module test:coverage
pnpm --filter @bsv/sigma-permission-module test:property
pnpm --filter @bsv/sigma-permission-module build
pnpm --filter @bsv/sigma-permission-module pack:checkApache License 2.0. See LICENSE.