@did-btcr2/method 0.26.0 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +86 -233
- package/dist/.tsbuildinfo +1 -1
- package/dist/browser.js +24111 -20342
- package/dist/browser.mjs +24111 -20342
- package/dist/cjs/index.js +2463 -2174
- package/dist/esm/core/aggregation/cohort.js +178 -0
- package/dist/esm/core/aggregation/cohort.js.map +1 -0
- package/dist/esm/core/aggregation/errors.js +22 -0
- package/dist/esm/core/aggregation/errors.js.map +1 -0
- package/dist/esm/core/{beacon/aggregation/cohort → aggregation}/messages/base.js +0 -1
- package/dist/esm/core/aggregation/messages/base.js.map +1 -0
- package/dist/esm/core/aggregation/messages/constants.js +26 -0
- package/dist/esm/core/aggregation/messages/constants.js.map +1 -0
- package/dist/esm/core/aggregation/messages/factories.js +113 -0
- package/dist/esm/core/aggregation/messages/factories.js.map +1 -0
- package/dist/esm/core/aggregation/messages/guards.js +37 -0
- package/dist/esm/core/aggregation/messages/guards.js.map +1 -0
- package/dist/esm/core/aggregation/messages/index.js +5 -0
- package/dist/esm/core/aggregation/messages/index.js.map +1 -0
- package/dist/esm/core/aggregation/participant.js +376 -0
- package/dist/esm/core/aggregation/participant.js.map +1 -0
- package/dist/esm/core/aggregation/phases.js +39 -0
- package/dist/esm/core/aggregation/phases.js.map +1 -0
- package/dist/esm/core/aggregation/runner/events.js +2 -0
- package/dist/esm/core/aggregation/runner/events.js.map +1 -0
- package/dist/esm/core/aggregation/runner/index.js +5 -0
- package/dist/esm/core/aggregation/runner/index.js.map +1 -0
- package/dist/esm/core/aggregation/runner/participant-runner.js +282 -0
- package/dist/esm/core/aggregation/runner/participant-runner.js.map +1 -0
- package/dist/esm/core/aggregation/runner/service-runner.js +290 -0
- package/dist/esm/core/aggregation/runner/service-runner.js.map +1 -0
- package/dist/esm/core/aggregation/runner/typed-emitter.js +80 -0
- package/dist/esm/core/aggregation/runner/typed-emitter.js.map +1 -0
- package/dist/esm/core/aggregation/service.js +416 -0
- package/dist/esm/core/aggregation/service.js.map +1 -0
- package/dist/esm/core/aggregation/signing-session.js +133 -0
- package/dist/esm/core/aggregation/signing-session.js.map +1 -0
- package/dist/esm/core/aggregation/transport/didcomm.js +32 -0
- package/dist/esm/core/aggregation/transport/didcomm.js.map +1 -0
- package/dist/esm/core/aggregation/transport/error.js +12 -0
- package/dist/esm/core/aggregation/transport/error.js.map +1 -0
- package/dist/esm/core/aggregation/transport/factory.js +20 -0
- package/dist/esm/core/aggregation/transport/factory.js.map +1 -0
- package/dist/esm/core/aggregation/transport/index.js +6 -0
- package/dist/esm/core/aggregation/transport/index.js.map +1 -0
- package/dist/esm/core/aggregation/transport/nostr.js +262 -0
- package/dist/esm/core/aggregation/transport/nostr.js.map +1 -0
- package/dist/esm/core/aggregation/transport/transport.js +2 -0
- package/dist/esm/core/aggregation/transport/transport.js.map +1 -0
- package/dist/esm/core/beacon/beacon.js +80 -0
- package/dist/esm/core/beacon/beacon.js.map +1 -1
- package/dist/esm/core/beacon/cas-beacon.js +15 -56
- package/dist/esm/core/beacon/cas-beacon.js.map +1 -1
- package/dist/esm/core/beacon/error.js +0 -10
- package/dist/esm/core/beacon/error.js.map +1 -1
- package/dist/esm/core/beacon/fee-estimator.js +30 -0
- package/dist/esm/core/beacon/fee-estimator.js.map +1 -0
- package/dist/esm/core/beacon/singleton-beacon.js +10 -53
- package/dist/esm/core/beacon/singleton-beacon.js.map +1 -1
- package/dist/esm/core/beacon/smt-beacon.js +85 -9
- package/dist/esm/core/beacon/smt-beacon.js.map +1 -1
- package/dist/esm/core/identifier.js +13 -0
- package/dist/esm/core/identifier.js.map +1 -1
- package/dist/esm/core/resolver.js +9 -0
- package/dist/esm/core/resolver.js.map +1 -1
- package/dist/esm/index.js +14 -24
- package/dist/esm/index.js.map +1 -1
- package/dist/types/core/aggregation/cohort.d.ts +94 -0
- package/dist/types/core/aggregation/cohort.d.ts.map +1 -0
- package/dist/types/core/aggregation/errors.d.ts +14 -0
- package/dist/types/core/aggregation/errors.d.ts.map +1 -0
- package/dist/types/core/{beacon/aggregation/cohort → aggregation}/messages/base.d.ts +7 -1
- package/dist/types/core/aggregation/messages/base.d.ts.map +1 -0
- package/dist/types/core/aggregation/messages/constants.d.ts +23 -0
- package/dist/types/core/aggregation/messages/constants.d.ts.map +1 -0
- package/dist/types/core/aggregation/messages/factories.d.ts +177 -0
- package/dist/types/core/aggregation/messages/factories.d.ts.map +1 -0
- package/dist/types/core/aggregation/messages/guards.d.ts +11 -0
- package/dist/types/core/aggregation/messages/guards.d.ts.map +1 -0
- package/dist/types/core/aggregation/messages/index.d.ts +5 -0
- package/dist/types/core/aggregation/messages/index.d.ts.map +1 -0
- package/dist/types/core/aggregation/participant.d.ts +101 -0
- package/dist/types/core/aggregation/participant.d.ts.map +1 -0
- package/dist/types/core/aggregation/phases.d.ts +49 -0
- package/dist/types/core/aggregation/phases.d.ts.map +1 -0
- package/dist/types/core/aggregation/runner/events.d.ts +89 -0
- package/dist/types/core/aggregation/runner/events.d.ts.map +1 -0
- package/dist/types/core/aggregation/runner/index.d.ts +5 -0
- package/dist/types/core/aggregation/runner/index.d.ts.map +1 -0
- package/dist/types/core/aggregation/runner/participant-runner.d.ts +107 -0
- package/dist/types/core/aggregation/runner/participant-runner.d.ts.map +1 -0
- package/dist/types/core/aggregation/runner/service-runner.d.ts +102 -0
- package/dist/types/core/aggregation/runner/service-runner.d.ts.map +1 -0
- package/dist/types/core/aggregation/runner/typed-emitter.d.ts +41 -0
- package/dist/types/core/aggregation/runner/typed-emitter.d.ts.map +1 -0
- package/dist/types/core/aggregation/service.d.ts +112 -0
- package/dist/types/core/aggregation/service.d.ts.map +1 -0
- package/dist/types/core/aggregation/signing-session.d.ts +69 -0
- package/dist/types/core/aggregation/signing-session.d.ts.map +1 -0
- package/dist/types/core/aggregation/transport/didcomm.d.ts +20 -0
- package/dist/types/core/aggregation/transport/didcomm.d.ts.map +1 -0
- package/dist/types/core/{beacon/aggregation/communication → aggregation/transport}/error.d.ts +2 -2
- package/dist/types/core/aggregation/transport/error.d.ts.map +1 -0
- package/dist/types/core/aggregation/transport/factory.d.ts +13 -0
- package/dist/types/core/aggregation/transport/factory.d.ts.map +1 -0
- package/dist/types/core/aggregation/transport/index.d.ts +6 -0
- package/dist/types/core/aggregation/transport/index.d.ts.map +1 -0
- package/dist/types/core/aggregation/transport/nostr.d.ts +55 -0
- package/dist/types/core/aggregation/transport/nostr.d.ts.map +1 -0
- package/dist/types/core/aggregation/transport/transport.d.ts +37 -0
- package/dist/types/core/aggregation/transport/transport.d.ts.map +1 -0
- package/dist/types/core/beacon/beacon.d.ts +37 -2
- package/dist/types/core/beacon/beacon.d.ts.map +1 -1
- package/dist/types/core/beacon/cas-beacon.d.ts +19 -7
- package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -1
- package/dist/types/core/beacon/error.d.ts +0 -6
- package/dist/types/core/beacon/error.d.ts.map +1 -1
- package/dist/types/core/beacon/fee-estimator.d.ts +40 -0
- package/dist/types/core/beacon/fee-estimator.d.ts.map +1 -0
- package/dist/types/core/beacon/interfaces.d.ts +8 -0
- package/dist/types/core/beacon/interfaces.d.ts.map +1 -1
- package/dist/types/core/beacon/singleton-beacon.d.ts +9 -2
- package/dist/types/core/beacon/singleton-beacon.d.ts.map +1 -1
- package/dist/types/core/beacon/smt-beacon.d.ts +27 -7
- package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -1
- package/dist/types/core/identifier.d.ts +8 -0
- package/dist/types/core/identifier.d.ts.map +1 -1
- package/dist/types/core/interfaces.d.ts +2 -2
- package/dist/types/core/resolver.d.ts +11 -1
- package/dist/types/core/resolver.d.ts.map +1 -1
- package/dist/types/index.d.ts +9 -24
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +31 -30
- package/src/core/aggregation/cohort.ts +247 -0
- package/src/core/aggregation/errors.ts +25 -0
- package/src/core/{beacon/aggregation/cohort → aggregation}/messages/base.ts +8 -3
- package/src/core/aggregation/messages/constants.ts +28 -0
- package/src/core/aggregation/messages/factories.ts +240 -0
- package/src/core/aggregation/messages/guards.ts +55 -0
- package/src/core/aggregation/messages/index.ts +4 -0
- package/src/core/aggregation/participant.ts +510 -0
- package/src/core/aggregation/phases.ts +82 -0
- package/src/core/aggregation/runner/events.ts +77 -0
- package/src/core/aggregation/runner/index.ts +4 -0
- package/src/core/aggregation/runner/participant-runner.ts +360 -0
- package/src/core/aggregation/runner/service-runner.ts +365 -0
- package/src/core/aggregation/runner/typed-emitter.ts +87 -0
- package/src/core/aggregation/service.ts +547 -0
- package/src/core/aggregation/signing-session.ts +209 -0
- package/src/core/aggregation/transport/didcomm.ts +42 -0
- package/src/core/aggregation/transport/error.ts +13 -0
- package/src/core/aggregation/transport/factory.ts +29 -0
- package/src/core/aggregation/transport/index.ts +5 -0
- package/src/core/aggregation/transport/nostr.ts +333 -0
- package/src/core/aggregation/transport/transport.ts +46 -0
- package/src/core/beacon/beacon.ts +122 -2
- package/src/core/beacon/cas-beacon.ts +28 -76
- package/src/core/beacon/error.ts +0 -12
- package/src/core/beacon/fee-estimator.ts +52 -0
- package/src/core/beacon/interfaces.ts +10 -1
- package/src/core/beacon/singleton-beacon.ts +14 -75
- package/src/core/beacon/smt-beacon.ts +109 -11
- package/src/core/identifier.ts +17 -0
- package/src/core/interfaces.ts +2 -2
- package/src/core/resolver.ts +25 -2
- package/src/index.ts +15 -29
- package/dist/esm/core/beacon/aggregation/cohort/index.js +0 -237
- package/dist/esm/core/beacon/aggregation/cohort/index.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/base.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/constants.js +0 -11
- package/dist/esm/core/beacon/aggregation/cohort/messages/constants.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/index.js +0 -98
- package/dist/esm/core/beacon/aggregation/cohort/messages/index.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js +0 -31
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js +0 -29
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js +0 -27
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js +0 -23
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js +0 -28
- package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js +0 -29
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js +0 -30
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js +0 -30
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js +0 -30
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js +0 -31
- package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/cohort/status.js +0 -8
- package/dist/esm/core/beacon/aggregation/cohort/status.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js +0 -121
- package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js +0 -245
- package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/communication/error.js +0 -12
- package/dist/esm/core/beacon/aggregation/communication/error.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/communication/factory.js +0 -21
- package/dist/esm/core/beacon/aggregation/communication/factory.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/communication/service.js +0 -2
- package/dist/esm/core/beacon/aggregation/communication/service.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/coordinator.js +0 -343
- package/dist/esm/core/beacon/aggregation/coordinator.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/participant.js +0 -435
- package/dist/esm/core/beacon/aggregation/participant.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/session/index.js +0 -244
- package/dist/esm/core/beacon/aggregation/session/index.js.map +0 -1
- package/dist/esm/core/beacon/aggregation/session/status.js +0 -11
- package/dist/esm/core/beacon/aggregation/session/status.js.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/index.d.ts +0 -136
- package/dist/types/core/beacon/aggregation/cohort/index.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/base.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/constants.d.ts +0 -11
- package/dist/types/core/beacon/aggregation/cohort/messages/constants.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/index.d.ts +0 -65
- package/dist/types/core/beacon/aggregation/cohort/messages/index.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts +0 -29
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts +0 -26
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts +0 -24
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts +0 -20
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts +0 -25
- package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts +0 -25
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts +0 -26
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts +0 -26
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts +0 -26
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts +0 -27
- package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/cohort/status.d.ts +0 -8
- package/dist/types/core/beacon/aggregation/cohort/status.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts +0 -89
- package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts +0 -103
- package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/communication/error.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/communication/factory.d.ts +0 -10
- package/dist/types/core/beacon/aggregation/communication/factory.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/communication/service.d.ts +0 -36
- package/dist/types/core/beacon/aggregation/communication/service.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/coordinator.d.ts +0 -116
- package/dist/types/core/beacon/aggregation/coordinator.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/participant.d.ts +0 -192
- package/dist/types/core/beacon/aggregation/participant.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/session/index.d.ts +0 -156
- package/dist/types/core/beacon/aggregation/session/index.d.ts.map +0 -1
- package/dist/types/core/beacon/aggregation/session/status.d.ts +0 -11
- package/dist/types/core/beacon/aggregation/session/status.d.ts.map +0 -1
- package/src/core/beacon/aggregation/cohort/index.ts +0 -305
- package/src/core/beacon/aggregation/cohort/messages/constants.ts +0 -12
- package/src/core/beacon/aggregation/cohort/messages/index.ts +0 -143
- package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.ts +0 -44
- package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.ts +0 -40
- package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.ts +0 -35
- package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in.ts +0 -34
- package/src/core/beacon/aggregation/cohort/messages/keygen/subscribe.ts +0 -36
- package/src/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.ts +0 -39
- package/src/core/beacon/aggregation/cohort/messages/sign/authorization-request.ts +0 -40
- package/src/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.ts +0 -40
- package/src/core/beacon/aggregation/cohort/messages/sign/request-signature.ts +0 -40
- package/src/core/beacon/aggregation/cohort/messages/sign/signature-authorization.ts +0 -41
- package/src/core/beacon/aggregation/cohort/status.ts +0 -7
- package/src/core/beacon/aggregation/communication/adapter/did-comm.ts +0 -148
- package/src/core/beacon/aggregation/communication/adapter/nostr.ts +0 -323
- package/src/core/beacon/aggregation/communication/error.ts +0 -13
- package/src/core/beacon/aggregation/communication/factory.ts +0 -25
- package/src/core/beacon/aggregation/communication/service.ts +0 -42
- package/src/core/beacon/aggregation/coordinator.ts +0 -419
- package/src/core/beacon/aggregation/participant.ts +0 -517
- package/src/core/beacon/aggregation/session/index.ts +0 -301
- package/src/core/beacon/aggregation/session/status.ts +0 -18
|
@@ -1,301 +0,0 @@
|
|
|
1
|
-
import * as musig2 from '@scure/btc-signer/musig2';
|
|
2
|
-
import { Transaction } from 'bitcoinjs-lib';
|
|
3
|
-
import { AggregateBeaconError } from '../../error.js';
|
|
4
|
-
import type { AggregateBeaconCohort } from '../cohort/index.js';
|
|
5
|
-
import { BeaconCohortAuthorizationRequestMessage } from '../cohort/messages/sign/authorization-request.js';
|
|
6
|
-
import type { SIGNING_SESSION_STATUS_TYPE } from './status.js';
|
|
7
|
-
import { SIGNING_SESSION_STATUS } from './status.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Convert a big-endian byte array into a bigint.
|
|
11
|
-
* @param bytes - The input Uint8Array representing a big-endian integer.
|
|
12
|
-
* @returns The integer value as a bigint.
|
|
13
|
-
*/
|
|
14
|
-
export function bigEndianToInt(bytes: Uint8Array): bigint {
|
|
15
|
-
return bytes.reduce((num, b) => (num << 8n) + BigInt(b), 0n);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Convert a bigint to a big-endian Uint8Array of specified length.
|
|
20
|
-
* @param xInit - The bigint to convert.
|
|
21
|
-
* @param length - The desired length of the output array in bytes.
|
|
22
|
-
* @returns A Uint8Array representing the bigint in big-endian form.
|
|
23
|
-
*/
|
|
24
|
-
export function intToBigEndian(xInit: bigint, length: number): Uint8Array {
|
|
25
|
-
let x = xInit;
|
|
26
|
-
const result = new Uint8Array(length);
|
|
27
|
-
for (let i = length - 1; i >= 0; i--) {
|
|
28
|
-
result[i] = Number(x & 0xffn);
|
|
29
|
-
x >>= 8n;
|
|
30
|
-
}
|
|
31
|
-
return result;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
type PublicKeyHex = string;
|
|
35
|
-
type Nonce = Uint8Array;
|
|
36
|
-
type NonceContributions = Map<PublicKeyHex, Nonce>;
|
|
37
|
-
type PartialSignatures = Map<string, Uint8Array>;
|
|
38
|
-
type ProcessedRequests = Record<string, string>;
|
|
39
|
-
|
|
40
|
-
export interface SigningSession {
|
|
41
|
-
id?: string;
|
|
42
|
-
cohort: AggregateBeaconCohort;
|
|
43
|
-
pendingTx: Transaction;
|
|
44
|
-
nonceContributions?: NonceContributions;
|
|
45
|
-
aggregatedNonce?: Uint8Array;
|
|
46
|
-
partialSignatures?: PartialSignatures;
|
|
47
|
-
signature?: Uint8Array;
|
|
48
|
-
status?: SIGNING_SESSION_STATUS_TYPE;
|
|
49
|
-
processedRequests?: ProcessedRequests;
|
|
50
|
-
nonceSecrets?: bigint;
|
|
51
|
-
}
|
|
52
|
-
export class BeaconCohortSigningSession implements SigningSession {
|
|
53
|
-
/**
|
|
54
|
-
* Unique identifier for the signing session.
|
|
55
|
-
* @type {string}
|
|
56
|
-
*/
|
|
57
|
-
public id: string;
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* DID of the coordinator.
|
|
61
|
-
* @type {AggregateBeaconCohort}
|
|
62
|
-
*/
|
|
63
|
-
public cohort: AggregateBeaconCohort;
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Pending transaction to be signed.
|
|
67
|
-
* @type {Transaction}
|
|
68
|
-
*/
|
|
69
|
-
public pendingTx: Transaction;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Map of nonce contributions from participants.
|
|
73
|
-
* @type {Map<PublicKeyHex, Nonce>}
|
|
74
|
-
*/
|
|
75
|
-
public nonceContributions: Map<PublicKeyHex, Nonce> = new Map();
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Aggregated nonce from all participants.
|
|
79
|
-
* @type {Uint8Array}
|
|
80
|
-
*/
|
|
81
|
-
public aggregatedNonce?: Uint8Array;
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Map of partial signatures from participants.
|
|
85
|
-
* @type {Map<string, Uint8Array>}
|
|
86
|
-
*/
|
|
87
|
-
public partialSignatures: Map<string, Uint8Array> = new Map();
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Final signature for the transaction.
|
|
91
|
-
* @type {Uint8Array}
|
|
92
|
-
*/
|
|
93
|
-
public signature?: Uint8Array;
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Current status of the signing session.
|
|
97
|
-
* @type {SIGNING_SESSION_STATUS_TYPE}
|
|
98
|
-
*/
|
|
99
|
-
public status: SIGNING_SESSION_STATUS_TYPE;
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Map of processed requests from participants.
|
|
103
|
-
* @type {Record<string, string>}
|
|
104
|
-
*/
|
|
105
|
-
public processedRequests: Record<string, string>;
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Secrets for nonces contributed by participants.
|
|
109
|
-
* @type {Array<bigint>}
|
|
110
|
-
*/
|
|
111
|
-
public nonceSecrets?: bigint;
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Musig2 session for signing operations.
|
|
115
|
-
* @type {musig2.Session}
|
|
116
|
-
*/
|
|
117
|
-
public musig2Session?: musig2.Session;
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Creates a new instance of BeaconCohortSigningSession.
|
|
121
|
-
* @param {SigningSession} params Parameters to initialize the signing session.
|
|
122
|
-
* @param {Transaction} params.pendingTx The pending transaction to be signed.
|
|
123
|
-
* @param {string} [params.id] Optional unique identifier for the signing session. If not provided, a new UUID will be generated.
|
|
124
|
-
* @param {AggregateBeaconCohort} [params.cohort] The cohort associated with the signing session.
|
|
125
|
-
* @param {Record<string, string>} [params.processedRequests] Map of processed requests from participants.
|
|
126
|
-
* @param {SIGNING_SESSION_STATUS_TYPE} [params.status] The current status of the signing session. Defaults to AWAITING_NONCE_CONTRIBUTIONS.
|
|
127
|
-
*/
|
|
128
|
-
constructor({ id, cohort, pendingTx, processedRequests, status }: SigningSession) {
|
|
129
|
-
this.id = id || crypto.randomUUID();
|
|
130
|
-
this.cohort = cohort;
|
|
131
|
-
this.pendingTx = pendingTx;
|
|
132
|
-
this.processedRequests = processedRequests || {};
|
|
133
|
-
this.status = status || SIGNING_SESSION_STATUS.AWAITING_NONCE_CONTRIBUTIONS;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Gets the authorization request message for a participant.
|
|
138
|
-
* @param {string} to The public key of the participant to whom the request is sent.
|
|
139
|
-
* @param {string} from The public key of the participant sending the request.
|
|
140
|
-
* @returns {AuthorizationRequest} The authorization request message.
|
|
141
|
-
*/
|
|
142
|
-
public getAuthorizationRequest(to: string, from: string): BeaconCohortAuthorizationRequestMessage {
|
|
143
|
-
const txHex = this.pendingTx instanceof Transaction ? this.pendingTx?.toHex() : this.pendingTx;
|
|
144
|
-
return new BeaconCohortAuthorizationRequestMessage({
|
|
145
|
-
to,
|
|
146
|
-
from,
|
|
147
|
-
sessionId : this.id,
|
|
148
|
-
cohortId : this.cohort?.id,
|
|
149
|
-
pendingTx : txHex,
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Adds a nonce contribution from a participant to the session.
|
|
155
|
-
* @param {string} from The public key of the participant contributing the nonce.
|
|
156
|
-
* @param {Array<string>} nonceContribution The nonce contribution from the participant.
|
|
157
|
-
* @throws {Error} If the session is not awaiting nonce contributions or if the contribution is invalid.
|
|
158
|
-
*/
|
|
159
|
-
public addNonceContribution(from: string, nonceContribution: Uint8Array): void {
|
|
160
|
-
if(this.status !== SIGNING_SESSION_STATUS.AWAITING_NONCE_CONTRIBUTIONS) {
|
|
161
|
-
throw new AggregateBeaconError(`Nonce contributions already received. Current status: ${this.status}`);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if(nonceContribution.length !== 2) {
|
|
165
|
-
throw new AggregateBeaconError(`Invalid nonce contribution. Expected 2 points, received ${nonceContribution.length}.`);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (this.nonceContributions.get(from)) {
|
|
169
|
-
console.warn(`WARNING: Nonce contribution already received from ${from}.`);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
this.nonceContributions.set(from, nonceContribution);
|
|
173
|
-
|
|
174
|
-
if(this.nonceContributions.size === this.cohort?.participants.length) {
|
|
175
|
-
this.status = SIGNING_SESSION_STATUS.NONCE_CONTRIBUTIONS_RECEIVED;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Generates the aggregated nonce from all nonce contributions for the session.
|
|
181
|
-
* @returns {Uint8Array} The aggregated nonce.
|
|
182
|
-
* @throws {AggregateBeaconError} If not all nonce contributions have been received.
|
|
183
|
-
*/
|
|
184
|
-
public generateAggregatedNonce(): Uint8Array {
|
|
185
|
-
if(this.status !== SIGNING_SESSION_STATUS.NONCE_CONTRIBUTIONS_RECEIVED) {
|
|
186
|
-
const missing = this.cohort?.participants.length - this.nonceContributions.size;
|
|
187
|
-
throw new AggregateBeaconError(
|
|
188
|
-
`Missing ${missing} nonce contributions. ` +
|
|
189
|
-
`Received ${this.cohort?.participants.length} of ${this.nonceContributions.size} nonce contributions. ` +
|
|
190
|
-
`Current status: ${this.status}`,
|
|
191
|
-
'NONCE_CONTRIBUTION_ERROR', this.toJSON()
|
|
192
|
-
);
|
|
193
|
-
}
|
|
194
|
-
const sortedPubkeys = musig2.sortKeys(this.cohort.cohortKeys);
|
|
195
|
-
const keyAggContext = musig2.keyAggregate(sortedPubkeys);
|
|
196
|
-
const aggPubkey = musig2.keyAggExport(keyAggContext);
|
|
197
|
-
this.aggregatedNonce = musig2.nonceAggregate(this.cohort.cohortKeys.map(key => musig2.nonceGen(key, undefined, aggPubkey, this.cohort.trMerkleRoot).public));
|
|
198
|
-
this.musig2Session = new musig2.Session(this.aggregatedNonce, this.cohort.cohortKeys, this.cohort.trMerkleRoot);
|
|
199
|
-
return this.aggregatedNonce;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Adds a partial signature from a participant to the session.
|
|
204
|
-
* @param {string} from The public key of the participant contributing the partial signature.
|
|
205
|
-
* @param {Uint8Array} partialSignature The partial signature from the participant.
|
|
206
|
-
*/
|
|
207
|
-
public addPartialSignature(from: string, partialSignature: Uint8Array): void {
|
|
208
|
-
if(this.status !== SIGNING_SESSION_STATUS.AWAITING_PARTIAL_SIGNATURES) {
|
|
209
|
-
throw new AggregateBeaconError(`Partial signatures not expected. Current status: ${this.status}`);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
if(this.partialSignatures.get(from)) {
|
|
213
|
-
console.warn(`WARNING: Partial signature already received from ${from}.`);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
this.partialSignatures.set(from, partialSignature);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* Generates the final signature from all partial signatures.
|
|
221
|
-
* @returns {Uint8Array} The final aggregated signature.
|
|
222
|
-
*/
|
|
223
|
-
public async generateFinalSignature(): Promise<Uint8Array> {
|
|
224
|
-
if(this.status !== SIGNING_SESSION_STATUS.PARTIAL_SIGNATURES_RECEIVED) {
|
|
225
|
-
throw new AggregateBeaconError(`Partial signatures not received. Current status: ${this.status}`);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
const inputIdx = (this.pendingTx?.ins?.length || 0) - 1;
|
|
229
|
-
if (inputIdx < 0) {
|
|
230
|
-
throw new AggregateBeaconError('No inputs in the pending transaction to sign.');
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
const prevoutScript = this.pendingTx?.ins[inputIdx].script;
|
|
234
|
-
if (!prevoutScript) {
|
|
235
|
-
throw new AggregateBeaconError('Previous output script is missing for the input to sign.');
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
const sigSum = [...this.partialSignatures.values()].reduce((sum, sig) => sum + bigEndianToInt(sig), 0n);
|
|
239
|
-
console.info(`Aggregated Signature computed: ${sigSum}`);
|
|
240
|
-
|
|
241
|
-
this.aggregatedNonce ??= this.generateAggregatedNonce();
|
|
242
|
-
|
|
243
|
-
const session = new musig2.Session(this.aggregatedNonce!, this.cohort.cohortKeys, this.cohort.trMerkleRoot);
|
|
244
|
-
this.signature = session.partialSigAgg([...this.partialSignatures.values()]);
|
|
245
|
-
|
|
246
|
-
return this.signature;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Generates a partial signature for the session using the participant's secret key.
|
|
251
|
-
* @param {Uint8Array} participantSk The secret key of the participant.
|
|
252
|
-
* @returns {Uint8Array} The partial signature generated by the participant.
|
|
253
|
-
*/
|
|
254
|
-
public generatePartialSignature(participantSk: Uint8Array): Uint8Array {
|
|
255
|
-
if (!this.aggregatedNonce) {
|
|
256
|
-
throw new AggregateBeaconError('Aggregated nonce is not available. Please generate it first.');
|
|
257
|
-
}
|
|
258
|
-
const sigHash = this.pendingTx?.hashForSignature(0, this.pendingTx?.ins[0].script, Transaction.SIGHASH_DEFAULT);
|
|
259
|
-
if(!sigHash) {
|
|
260
|
-
throw new AggregateBeaconError('Signature hash is not available. Please ensure the transaction is properly set up.');
|
|
261
|
-
}
|
|
262
|
-
const session = new musig2.Session(this.aggregatedNonce!, this.cohort.cohortKeys, this.cohort.trMerkleRoot);
|
|
263
|
-
return session.sign(this.aggregatedNonce, participantSk);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Converts the signing session instance to a JSON object representation.
|
|
268
|
-
* @returns {BeaconCohortSigningSession} The JSON object representation of the signing session.
|
|
269
|
-
*/
|
|
270
|
-
public toJSON(): Partial<BeaconCohortSigningSession> {
|
|
271
|
-
return {
|
|
272
|
-
id : this.id,
|
|
273
|
-
cohort : this.cohort,
|
|
274
|
-
pendingTx : this.pendingTx,
|
|
275
|
-
nonceContributions : this.nonceContributions,
|
|
276
|
-
aggregatedNonce : this.aggregatedNonce,
|
|
277
|
-
partialSignatures : this.partialSignatures,
|
|
278
|
-
signature : this.signature,
|
|
279
|
-
status : this.status,
|
|
280
|
-
processedRequests : this.processedRequests,
|
|
281
|
-
nonceSecrets : this.nonceSecrets,
|
|
282
|
-
musig2Session : this.musig2Session
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Checks if the signing session is a completed state.
|
|
288
|
-
* @returns {boolean} True if the session is complete, false otherwise.
|
|
289
|
-
*/
|
|
290
|
-
public isComplete(): boolean {
|
|
291
|
-
return this.status === SIGNING_SESSION_STATUS.SIGNATURE_COMPLETE;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* Checks if the signing session is in a failed state.
|
|
296
|
-
* @returns {boolean} True if the session has failed, false otherwise.
|
|
297
|
-
*/
|
|
298
|
-
public isFailed(): boolean {
|
|
299
|
-
return this.status === SIGNING_SESSION_STATUS.FAILED;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export type SIGNING_SESSION_STATUS_TYPE =
|
|
2
|
-
| 'AWAITING_NONCE_CONTRIBUTIONS'
|
|
3
|
-
| 'NONCE_CONTRIBUTION_SENT'
|
|
4
|
-
| 'NONCE_CONTRIBUTIONS_RECEIVED'
|
|
5
|
-
| 'AWAITING_PARTIAL_SIGNATURES'
|
|
6
|
-
| 'PARTIAL_SIGNATURES_RECEIVED'
|
|
7
|
-
| 'SIGNATURE_COMPLETE'
|
|
8
|
-
| 'FAILED'
|
|
9
|
-
|
|
10
|
-
export enum SIGNING_SESSION_STATUS {
|
|
11
|
-
AWAITING_NONCE_CONTRIBUTIONS = 'AWAITING_NONCE_CONTRIBUTIONS',
|
|
12
|
-
NONCE_CONTRIBUTION_SENT = 'NONCE_CONTRIBUTION_SENT',
|
|
13
|
-
NONCE_CONTRIBUTIONS_RECEIVED = 'NONCE_CONTRIBUTIONS_RECEIVED',
|
|
14
|
-
AWAITING_PARTIAL_SIGNATURES = 'AWAITING_PARTIAL_SIGNATURES',
|
|
15
|
-
PARTIAL_SIGNATURES_RECEIVED = 'PARTIAL_SIGNATURES_RECEIVED',
|
|
16
|
-
SIGNATURE_COMPLETE = 'SIGNATURE_COMPLETE',
|
|
17
|
-
FAILED = 'FAILED',
|
|
18
|
-
}
|