@did-btcr2/method 0.28.0 → 0.32.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 +13 -5
- package/dist/.tsbuildinfo +1 -1
- package/dist/browser.js +34125 -44647
- package/dist/browser.mjs +26409 -36931
- package/dist/cjs/index.js +2869 -679
- package/dist/esm/core/aggregation/beacon-strategy.js +62 -0
- package/dist/esm/core/aggregation/beacon-strategy.js.map +1 -0
- package/dist/esm/core/aggregation/cohort.js +31 -8
- package/dist/esm/core/aggregation/cohort.js.map +1 -1
- package/dist/esm/core/aggregation/logger.js +15 -0
- package/dist/esm/core/aggregation/logger.js.map +1 -0
- package/dist/esm/core/aggregation/messages/base.js +12 -1
- package/dist/esm/core/aggregation/messages/base.js.map +1 -1
- package/dist/esm/core/aggregation/messages/bodies.js +90 -0
- package/dist/esm/core/aggregation/messages/bodies.js.map +1 -0
- package/dist/esm/core/aggregation/messages/factories.js.map +1 -1
- package/dist/esm/core/aggregation/messages/index.js +1 -0
- package/dist/esm/core/aggregation/messages/index.js.map +1 -1
- package/dist/esm/core/aggregation/participant.js +39 -46
- package/dist/esm/core/aggregation/participant.js.map +1 -1
- package/dist/esm/core/aggregation/runner/participant-runner.js +33 -7
- package/dist/esm/core/aggregation/runner/participant-runner.js.map +1 -1
- package/dist/esm/core/aggregation/runner/service-runner.js +198 -19
- package/dist/esm/core/aggregation/runner/service-runner.js.map +1 -1
- package/dist/esm/core/aggregation/service.js +143 -15
- package/dist/esm/core/aggregation/service.js.map +1 -1
- package/dist/esm/core/aggregation/signing-session.js +44 -5
- package/dist/esm/core/aggregation/signing-session.js.map +1 -1
- package/dist/esm/core/aggregation/transport/didcomm.js +9 -0
- package/dist/esm/core/aggregation/transport/didcomm.js.map +1 -1
- package/dist/esm/core/aggregation/transport/factory.js +15 -6
- package/dist/esm/core/aggregation/transport/factory.js.map +1 -1
- package/dist/esm/core/aggregation/transport/http/client.js +350 -0
- package/dist/esm/core/aggregation/transport/http/client.js.map +1 -0
- package/dist/esm/core/aggregation/transport/http/envelope.js +126 -0
- package/dist/esm/core/aggregation/transport/http/envelope.js.map +1 -0
- package/dist/esm/core/aggregation/transport/http/errors.js +11 -0
- package/dist/esm/core/aggregation/transport/http/errors.js.map +1 -0
- package/dist/esm/core/aggregation/transport/http/inbox-buffer.js +45 -0
- package/dist/esm/core/aggregation/transport/http/inbox-buffer.js.map +1 -0
- package/dist/esm/core/aggregation/transport/http/index.js +12 -0
- package/dist/esm/core/aggregation/transport/http/index.js.map +1 -0
- package/dist/esm/core/aggregation/transport/http/nonce-cache.js +38 -0
- package/dist/esm/core/aggregation/transport/http/nonce-cache.js.map +1 -0
- package/dist/esm/core/aggregation/transport/http/protocol.js +28 -0
- package/dist/esm/core/aggregation/transport/http/protocol.js.map +1 -0
- package/dist/esm/core/aggregation/transport/http/rate-limiter.js +45 -0
- package/dist/esm/core/aggregation/transport/http/rate-limiter.js.map +1 -0
- package/dist/esm/core/aggregation/transport/http/request-auth.js +100 -0
- package/dist/esm/core/aggregation/transport/http/request-auth.js.map +1 -0
- package/dist/esm/core/aggregation/transport/http/server.js +481 -0
- package/dist/esm/core/aggregation/transport/http/server.js.map +1 -0
- package/dist/esm/core/aggregation/transport/http/sse-stream.js +110 -0
- package/dist/esm/core/aggregation/transport/http/sse-stream.js.map +1 -0
- package/dist/esm/core/aggregation/transport/http/sse-writer.js +25 -0
- package/dist/esm/core/aggregation/transport/http/sse-writer.js.map +1 -0
- package/dist/esm/core/aggregation/transport/index.js +1 -0
- package/dist/esm/core/aggregation/transport/index.js.map +1 -1
- package/dist/esm/core/aggregation/transport/nostr.js +245 -16
- package/dist/esm/core/aggregation/transport/nostr.js.map +1 -1
- package/dist/esm/core/beacon/beacon.js +295 -63
- package/dist/esm/core/beacon/beacon.js.map +1 -1
- package/dist/esm/core/beacon/cas-beacon.js +3 -3
- package/dist/esm/core/beacon/cas-beacon.js.map +1 -1
- package/dist/esm/core/beacon/singleton-beacon.js +3 -3
- package/dist/esm/core/beacon/singleton-beacon.js.map +1 -1
- package/dist/esm/core/beacon/smt-beacon.js +3 -3
- package/dist/esm/core/beacon/smt-beacon.js.map +1 -1
- package/dist/esm/core/beacon/utils.js +14 -9
- package/dist/esm/core/beacon/utils.js.map +1 -1
- package/dist/esm/core/updater.js +63 -55
- package/dist/esm/core/updater.js.map +1 -1
- package/dist/esm/did-btcr2.js +0 -4
- package/dist/esm/did-btcr2.js.map +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/did-document.js +2 -2
- package/dist/esm/utils/did-document.js.map +1 -1
- package/dist/types/core/aggregation/beacon-strategy.d.ts +52 -0
- package/dist/types/core/aggregation/beacon-strategy.d.ts.map +1 -0
- package/dist/types/core/aggregation/cohort.d.ts +20 -3
- package/dist/types/core/aggregation/cohort.d.ts.map +1 -1
- package/dist/types/core/aggregation/logger.d.ts +22 -0
- package/dist/types/core/aggregation/logger.d.ts.map +1 -0
- package/dist/types/core/aggregation/messages/base.d.ts +13 -1
- package/dist/types/core/aggregation/messages/base.d.ts.map +1 -1
- package/dist/types/core/aggregation/messages/bodies.d.ts +130 -0
- package/dist/types/core/aggregation/messages/bodies.d.ts.map +1 -0
- package/dist/types/core/aggregation/messages/factories.d.ts +1 -0
- package/dist/types/core/aggregation/messages/factories.d.ts.map +1 -1
- package/dist/types/core/aggregation/messages/index.d.ts +1 -0
- package/dist/types/core/aggregation/messages/index.d.ts.map +1 -1
- package/dist/types/core/aggregation/participant.d.ts +2 -0
- package/dist/types/core/aggregation/participant.d.ts.map +1 -1
- package/dist/types/core/aggregation/runner/events.d.ts +32 -6
- package/dist/types/core/aggregation/runner/events.d.ts.map +1 -1
- package/dist/types/core/aggregation/runner/participant-runner.d.ts +7 -5
- package/dist/types/core/aggregation/runner/participant-runner.d.ts.map +1 -1
- package/dist/types/core/aggregation/runner/service-runner.d.ts +33 -3
- package/dist/types/core/aggregation/runner/service-runner.d.ts.map +1 -1
- package/dist/types/core/aggregation/service.d.ts +33 -2
- package/dist/types/core/aggregation/service.d.ts.map +1 -1
- package/dist/types/core/aggregation/signing-session.d.ts +5 -1
- package/dist/types/core/aggregation/signing-session.d.ts.map +1 -1
- package/dist/types/core/aggregation/transport/didcomm.d.ts +3 -0
- package/dist/types/core/aggregation/transport/didcomm.d.ts.map +1 -1
- package/dist/types/core/aggregation/transport/factory.d.ts +22 -7
- package/dist/types/core/aggregation/transport/factory.d.ts.map +1 -1
- package/dist/types/core/aggregation/transport/http/client.d.ts +48 -0
- package/dist/types/core/aggregation/transport/http/client.d.ts.map +1 -0
- package/dist/types/core/aggregation/transport/http/envelope.d.ts +64 -0
- package/dist/types/core/aggregation/transport/http/envelope.d.ts.map +1 -0
- package/dist/types/core/aggregation/transport/http/errors.d.ts +9 -0
- package/dist/types/core/aggregation/transport/http/errors.d.ts.map +1 -0
- package/dist/types/core/aggregation/transport/http/inbox-buffer.d.ts +32 -0
- package/dist/types/core/aggregation/transport/http/inbox-buffer.d.ts.map +1 -0
- package/dist/types/core/aggregation/transport/http/index.d.ts +12 -0
- package/dist/types/core/aggregation/transport/http/index.d.ts.map +1 -0
- package/dist/types/core/aggregation/transport/http/nonce-cache.d.ts +26 -0
- package/dist/types/core/aggregation/transport/http/nonce-cache.d.ts.map +1 -0
- package/dist/types/core/aggregation/transport/http/protocol.d.ts +53 -0
- package/dist/types/core/aggregation/transport/http/protocol.d.ts.map +1 -0
- package/dist/types/core/aggregation/transport/http/rate-limiter.d.ts +41 -0
- package/dist/types/core/aggregation/transport/http/rate-limiter.d.ts.map +1 -0
- package/dist/types/core/aggregation/transport/http/request-auth.d.ts +50 -0
- package/dist/types/core/aggregation/transport/http/request-auth.d.ts.map +1 -0
- package/dist/types/core/aggregation/transport/http/server.d.ts +110 -0
- package/dist/types/core/aggregation/transport/http/server.d.ts.map +1 -0
- package/dist/types/core/aggregation/transport/http/sse-stream.d.ts +34 -0
- package/dist/types/core/aggregation/transport/http/sse-stream.d.ts.map +1 -0
- package/dist/types/core/aggregation/transport/http/sse-writer.d.ts +12 -0
- package/dist/types/core/aggregation/transport/http/sse-writer.d.ts.map +1 -0
- package/dist/types/core/aggregation/transport/index.d.ts +1 -0
- package/dist/types/core/aggregation/transport/index.d.ts.map +1 -1
- package/dist/types/core/aggregation/transport/nostr.d.ts +99 -1
- package/dist/types/core/aggregation/transport/nostr.d.ts.map +1 -1
- package/dist/types/core/aggregation/transport/transport.d.ts +26 -1
- package/dist/types/core/aggregation/transport/transport.d.ts.map +1 -1
- package/dist/types/core/beacon/beacon.d.ts +149 -22
- package/dist/types/core/beacon/beacon.d.ts.map +1 -1
- package/dist/types/core/beacon/cas-beacon.d.ts +3 -3
- package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -1
- package/dist/types/core/beacon/singleton-beacon.d.ts +3 -3
- package/dist/types/core/beacon/singleton-beacon.d.ts.map +1 -1
- package/dist/types/core/beacon/smt-beacon.d.ts +3 -3
- package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -1
- package/dist/types/core/beacon/utils.d.ts +2 -2
- package/dist/types/core/beacon/utils.d.ts.map +1 -1
- package/dist/types/core/updater.d.ts +27 -12
- package/dist/types/core/updater.d.ts.map +1 -1
- package/dist/types/did-btcr2.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +5 -7
- package/src/core/aggregation/beacon-strategy.ts +123 -0
- package/src/core/aggregation/cohort.ts +34 -8
- package/src/core/aggregation/logger.ts +33 -0
- package/src/core/aggregation/messages/base.ts +20 -5
- package/src/core/aggregation/messages/bodies.ts +223 -0
- package/src/core/aggregation/messages/factories.ts +1 -0
- package/src/core/aggregation/messages/index.ts +1 -0
- package/src/core/aggregation/participant.ts +40 -46
- package/src/core/aggregation/runner/events.ts +27 -3
- package/src/core/aggregation/runner/participant-runner.ts +41 -7
- package/src/core/aggregation/runner/service-runner.ts +227 -19
- package/src/core/aggregation/service.ts +189 -20
- package/src/core/aggregation/signing-session.ts +65 -7
- package/src/core/aggregation/transport/didcomm.ts +17 -0
- package/src/core/aggregation/transport/factory.ts +48 -12
- package/src/core/aggregation/transport/http/client.ts +409 -0
- package/src/core/aggregation/transport/http/envelope.ts +204 -0
- package/src/core/aggregation/transport/http/errors.ts +11 -0
- package/src/core/aggregation/transport/http/inbox-buffer.ts +53 -0
- package/src/core/aggregation/transport/http/index.ts +11 -0
- package/src/core/aggregation/transport/http/nonce-cache.ts +43 -0
- package/src/core/aggregation/transport/http/protocol.ts +57 -0
- package/src/core/aggregation/transport/http/rate-limiter.ts +75 -0
- package/src/core/aggregation/transport/http/request-auth.ts +164 -0
- package/src/core/aggregation/transport/http/server.ts +615 -0
- package/src/core/aggregation/transport/http/sse-stream.ts +121 -0
- package/src/core/aggregation/transport/http/sse-writer.ts +23 -0
- package/src/core/aggregation/transport/index.ts +1 -0
- package/src/core/aggregation/transport/nostr.ts +266 -23
- package/src/core/aggregation/transport/transport.ts +34 -1
- package/src/core/beacon/beacon.ts +411 -79
- package/src/core/beacon/cas-beacon.ts +4 -4
- package/src/core/beacon/singleton-beacon.ts +4 -4
- package/src/core/beacon/smt-beacon.ts +4 -4
- package/src/core/beacon/utils.ts +16 -11
- package/src/core/updater.ts +113 -67
- package/src/did-btcr2.ts +0 -5
- package/src/index.ts +2 -0
- package/src/utils/did-document.ts +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updater.d.ts","sourceRoot":"","sources":["../../../src/core/updater.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"updater.d.ts","sourceRoot":"","sources":["../../../src/core/updater.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;A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AAI,EAAE,aAAa,GAAG,IAAI;CAkEnC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"did-btcr2.d.ts","sourceRoot":"","sources":["../../src/did-btcr2.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,QAAQ,EACR,cAAc,EAAC,MAAM,mBAAmB,CAAC;AAS3C,OAAO,KAAK,EACV,SAAS,EAAC,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"did-btcr2.d.ts","sourceRoot":"","sources":["../../src/did-btcr2.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,QAAQ,EACR,cAAc,EAAC,MAAM,mBAAmB,CAAC;AAS3C,OAAO,KAAK,EACV,SAAS,EAAC,MAAM,YAAY,CAAC;AAQ/B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEvF,MAAM,WAAW,gBAAgB;IAC/B,qDAAqD;IACrD,MAAM,EAAE,MAAM,CAAC;IACf,+BAA+B;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sBAAsB;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,QAAS,YAAW,SAAS;IACxC;;OAEG;IACH,MAAM,CAAC,UAAU,EAAE,MAAM,CAAW;IAEpC;;;;;;;;;;;;;;;OAeG;IACH,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,QAAQ,GAAG,aAAa,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,MAAM;IAezF;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,MAAM,CAAC,OAAO,CACZ,GAAG,EAAE,MAAM,EACX,iBAAiB,GAAE,iBAAsB,GACxC,QAAQ;IAsBX;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,MAAM,CAAC,MAAM,CAAC,EACZ,cAAc,EACd,OAAO,EACP,eAAe,EACf,oBAAoB,EACpB,QAAQ,GACT,EAAE;QACD,cAAc,EAAE,gBAAgB,CAAC;QACjC,OAAO,EAAE,cAAc,EAAE,CAAC;QAC1B,eAAe,EAAE,MAAM,CAAC;QACxB,oBAAoB,EAAE,MAAM,CAAC;QAC7B,QAAQ,EAAE,MAAM,CAAC;KAClB,GAAG,OAAO;IA2DX;;;;;;;;;OASG;IACH,MAAM,CAAC,gBAAgB,CAAC,WAAW,EAAE,gBAAgB,EAAG,QAAQ,CAAC,EAAE,MAAM,GAAG,qBAAqB;CA0BlG"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ export * from './core/aggregation/cohort.js';
|
|
|
4
4
|
export * from './core/aggregation/signing-session.js';
|
|
5
5
|
export * from './core/aggregation/phases.js';
|
|
6
6
|
export * from './core/aggregation/errors.js';
|
|
7
|
+
export * from './core/aggregation/beacon-strategy.js';
|
|
8
|
+
export * from './core/aggregation/logger.js';
|
|
7
9
|
export * from './core/aggregation/messages/index.js';
|
|
8
10
|
export * from './core/aggregation/transport/index.js';
|
|
9
11
|
export * from './core/aggregation/runner/index.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mCAAmC,CAAC;AAClD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uCAAuC,CAAC;AACtD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sCAAsC,CAAC;AACrD,cAAc,uCAAuC,CAAC;AACtD,cAAc,oCAAoC,CAAC;AAGnD,cAAc,yBAAyB,CAAC;AACxC,cAAc,6B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mBAAmB,CAAC;AAGlC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iCAAiC,CAAC;AAChD,cAAc,yBAAyB,CAAC;AAGxC,cAAc,gBAAgB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@did-btcr2/method",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Reference implementation for the did:btcr2 DID method written in TypeScript and JavaScript. did:btcr2 is a censorship resistant DID Method using the Bitcoin blockchain as a Verifiable Data Registry to announce changes to the DID document. This is the core method implementation for the did-btcr2-js monorepo.",
|
|
6
6
|
"main": "./dist/cjs/index.js",
|
|
@@ -64,7 +64,6 @@
|
|
|
64
64
|
"bitcoin"
|
|
65
65
|
],
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@bitcoinerlab/secp256k1": "^1.2.0",
|
|
68
67
|
"@helia/strings": "^4.1.0",
|
|
69
68
|
"@noble/curves": "^1.9.7",
|
|
70
69
|
"@noble/hashes": "^1.8.0",
|
|
@@ -76,17 +75,16 @@
|
|
|
76
75
|
"@web5/common": "^1.1.0",
|
|
77
76
|
"@web5/crypto": "^1.0.6",
|
|
78
77
|
"@web5/dids": "^1.2.0",
|
|
79
|
-
"bitcoinjs-lib": "7.0.0-rc.0",
|
|
80
78
|
"canonicalize": "^2.1.0",
|
|
81
79
|
"dotenv": "^16.6.1",
|
|
82
80
|
"helia": "^5.5.1",
|
|
83
81
|
"multiformats": "^13.4.2",
|
|
84
82
|
"nostr-tools": "^2.23.3",
|
|
85
|
-
"@did-btcr2/bitcoin": "^0.
|
|
86
|
-
"@did-btcr2/
|
|
83
|
+
"@did-btcr2/bitcoin": "^0.6.0",
|
|
84
|
+
"@did-btcr2/common": "^9.1.0",
|
|
85
|
+
"@did-btcr2/cryptosuite": "^8.0.0",
|
|
87
86
|
"@did-btcr2/smt": "^0.2.4",
|
|
88
|
-
"@did-btcr2/keypair": "^0.
|
|
89
|
-
"@did-btcr2/common": "^9.0.0"
|
|
87
|
+
"@did-btcr2/keypair": "^0.13.0"
|
|
90
88
|
},
|
|
91
89
|
"devDependencies": {
|
|
92
90
|
"@eslint/js": "^9.39.4",
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { canonicalize } from '@did-btcr2/common';
|
|
2
|
+
import type { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
|
|
3
|
+
import type { SerializedSMTProof } from '@did-btcr2/smt';
|
|
4
|
+
import { blockHash, didToIndex, hashToHex, hexToHash, verifySerializedProof } from '@did-btcr2/smt';
|
|
5
|
+
import type { AggregationCohort } from './cohort.js';
|
|
6
|
+
import type { BaseBody } from './messages/base.js';
|
|
7
|
+
|
|
8
|
+
/** Validation result returned to the participant for a distribute-data message. */
|
|
9
|
+
export interface BeaconValidationResult {
|
|
10
|
+
matches: boolean;
|
|
11
|
+
casAnnouncement?: Record<string, string>;
|
|
12
|
+
smtProof?: SerializedSMTProof;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Per-participant body attached to DISTRIBUTE_AGGREGATED_DATA by the service. */
|
|
16
|
+
export interface BeaconDistributePayload {
|
|
17
|
+
casAnnouncement?: Record<string, string>;
|
|
18
|
+
smtProof?: Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Pluggable strategy for beacon-type-specific aggregation, distribution, and
|
|
23
|
+
* participant-side validation. Lets new beacon types be added without
|
|
24
|
+
* modifying the service or participant state machines: register a new strategy
|
|
25
|
+
* via {@link registerBeaconStrategy}.
|
|
26
|
+
*/
|
|
27
|
+
export interface AggregateBeaconStrategy {
|
|
28
|
+
/** String constant used as `beaconType` on CohortConfig / BaseMessage bodies. */
|
|
29
|
+
readonly type: string;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Service: build the aggregated data on the cohort after all updates are
|
|
33
|
+
* collected. Implementation should mutate the cohort (set signalBytes,
|
|
34
|
+
* casAnnouncement, smtProofs, etc.).
|
|
35
|
+
*/
|
|
36
|
+
buildAggregatedData(cohort: AggregationCohort): void;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Service: produce the body fields to attach to DISTRIBUTE_AGGREGATED_DATA
|
|
40
|
+
* for a specific participant. Called once per cohort member.
|
|
41
|
+
*/
|
|
42
|
+
getDistributePayload(cohort: AggregationCohort, participantDid: string): BeaconDistributePayload;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Participant: verify the aggregated data they received reflects their own
|
|
46
|
+
* submitted update. Pure function — returns matches + sidecar fields for
|
|
47
|
+
* the caller to store.
|
|
48
|
+
*/
|
|
49
|
+
validateParticipantView(params: {
|
|
50
|
+
participantDid: string;
|
|
51
|
+
submittedUpdate: SignedBTCR2Update;
|
|
52
|
+
expectedHash: string;
|
|
53
|
+
body: BaseBody;
|
|
54
|
+
}): BeaconValidationResult;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const CAS_STRATEGY: AggregateBeaconStrategy = {
|
|
58
|
+
type : 'CASBeacon',
|
|
59
|
+
|
|
60
|
+
buildAggregatedData(cohort) {
|
|
61
|
+
cohort.buildCASAnnouncement();
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
getDistributePayload(cohort) {
|
|
65
|
+
return { casAnnouncement: cohort.casAnnouncement };
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
validateParticipantView({ participantDid, expectedHash, body }) {
|
|
69
|
+
const casAnnouncement = body.casAnnouncement;
|
|
70
|
+
if(!casAnnouncement) return { matches: false };
|
|
71
|
+
return {
|
|
72
|
+
matches : casAnnouncement[participantDid] === expectedHash,
|
|
73
|
+
casAnnouncement,
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const SMT_STRATEGY: AggregateBeaconStrategy = {
|
|
79
|
+
type : 'SMTBeacon',
|
|
80
|
+
|
|
81
|
+
buildAggregatedData(cohort) {
|
|
82
|
+
cohort.buildSMTTree();
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
getDistributePayload(cohort, participantDid) {
|
|
86
|
+
const proof = cohort.smtProofs?.get(participantDid);
|
|
87
|
+
return { smtProof: proof as unknown as Record<string, unknown> | undefined };
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
validateParticipantView({ participantDid, submittedUpdate, body }) {
|
|
91
|
+
const smtProof = body.smtProof as unknown as SerializedSMTProof | undefined;
|
|
92
|
+
if(!smtProof?.updateId || !smtProof?.nonce) return { matches: false };
|
|
93
|
+
// Verify updateId matches the canonicalized update hash
|
|
94
|
+
const canonicalBytes = new TextEncoder().encode(canonicalize(submittedUpdate as unknown as Record<string, unknown>));
|
|
95
|
+
const expectedUpdateId = hashToHex(blockHash(canonicalBytes));
|
|
96
|
+
if(smtProof.updateId !== expectedUpdateId) {
|
|
97
|
+
return { matches: false, smtProof };
|
|
98
|
+
}
|
|
99
|
+
// Verify Merkle inclusion
|
|
100
|
+
const index = didToIndex(participantDid);
|
|
101
|
+
const candidateHash = blockHash(blockHash(hexToHash(smtProof.nonce)), hexToHash(smtProof.updateId));
|
|
102
|
+
return {
|
|
103
|
+
matches : verifySerializedProof(smtProof, index, candidateHash),
|
|
104
|
+
smtProof,
|
|
105
|
+
};
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/** Registered strategies keyed by `beaconType` string. */
|
|
110
|
+
const STRATEGIES: Map<string, AggregateBeaconStrategy> = new Map([
|
|
111
|
+
[CAS_STRATEGY.type, CAS_STRATEGY],
|
|
112
|
+
[SMT_STRATEGY.type, SMT_STRATEGY],
|
|
113
|
+
]);
|
|
114
|
+
|
|
115
|
+
/** Register a custom beacon strategy. Overwrites any existing entry with the same type. */
|
|
116
|
+
export function registerBeaconStrategy(strategy: AggregateBeaconStrategy): void {
|
|
117
|
+
STRATEGIES.set(strategy.type, strategy);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Look up a registered beacon strategy by type, or undefined if not registered. */
|
|
121
|
+
export function getBeaconStrategy(type: string): AggregateBeaconStrategy | undefined {
|
|
122
|
+
return STRATEGIES.get(type);
|
|
123
|
+
}
|
|
@@ -2,9 +2,10 @@ import { canonicalHash, canonicalize, hash } from '@did-btcr2/common';
|
|
|
2
2
|
import type { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
|
|
3
3
|
import type { SerializedSMTProof, TreeEntry } from '@did-btcr2/smt';
|
|
4
4
|
import { BTCR2MerkleTree } from '@did-btcr2/smt';
|
|
5
|
+
import { schnorr } from '@noble/curves/secp256k1.js';
|
|
5
6
|
import { hexToBytes, randomBytes } from '@noble/hashes/utils';
|
|
7
|
+
import { p2tr } from '@scure/btc-signer';
|
|
6
8
|
import { keyAggExport, keyAggregate, sortKeys } from '@scure/btc-signer/musig2';
|
|
7
|
-
import { crypto as btcCrypto, payments } from 'bitcoinjs-lib';
|
|
8
9
|
import type { CASAnnouncement } from '../types.js';
|
|
9
10
|
import { AggregationCohortError } from './errors.js';
|
|
10
11
|
|
|
@@ -48,11 +49,23 @@ export class AggregationCohort {
|
|
|
48
49
|
/** List of participant DIDs that have been accepted into the cohort. */
|
|
49
50
|
participants: Array<string> = [];
|
|
50
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Mapping from participant DID → their compressed secp256k1 public key.
|
|
54
|
+
* Distinct from {@link cohortKeys} (which is sorted per BIP-327) — this lets
|
|
55
|
+
* callers look up a participant's key without knowing their position in the
|
|
56
|
+
* sorted array. Populated by the service at `acceptParticipant` time.
|
|
57
|
+
*/
|
|
58
|
+
participantKeys: Map<string, Uint8Array> = new Map();
|
|
59
|
+
|
|
51
60
|
/** Sorted list of cohort participants' compressed public keys. */
|
|
52
61
|
#cohortKeys: Array<Uint8Array> = [];
|
|
53
62
|
|
|
54
|
-
/**
|
|
55
|
-
|
|
63
|
+
/**
|
|
64
|
+
* BIP-341 TapTweak — `taggedHash("TapTweak", internalPubkey)` for a key-path-only
|
|
65
|
+
* Taproot output. Despite prior naming, this is NOT a Merkle root: key-path-only
|
|
66
|
+
* spends have no script tree.
|
|
67
|
+
*/
|
|
68
|
+
tapTweak: Uint8Array = new Uint8Array();
|
|
56
69
|
|
|
57
70
|
/** The n-of-n MuSig2 Taproot beacon address. */
|
|
58
71
|
beaconAddress: string = '';
|
|
@@ -94,7 +107,7 @@ export class AggregationCohort {
|
|
|
94
107
|
|
|
95
108
|
/**
|
|
96
109
|
* Computes the n-of-n MuSig2 Taproot beacon address from cohort keys.
|
|
97
|
-
* Sets `
|
|
110
|
+
* Sets `tapTweak` to the BIP-341 key-path-only tweak.
|
|
98
111
|
*/
|
|
99
112
|
public computeBeaconAddress(): string {
|
|
100
113
|
if(this.#cohortKeys.length === 0) {
|
|
@@ -105,11 +118,11 @@ export class AggregationCohort {
|
|
|
105
118
|
}
|
|
106
119
|
const keyAggContext = keyAggregate(this.#cohortKeys);
|
|
107
120
|
const aggPubkey = keyAggExport(keyAggContext);
|
|
108
|
-
const payment =
|
|
121
|
+
const payment = p2tr(aggPubkey);
|
|
109
122
|
|
|
110
|
-
// BIP-341: key-path-only P2TR has no script tree
|
|
111
|
-
//
|
|
112
|
-
this.
|
|
123
|
+
// BIP-341: key-path-only P2TR has no script tree. Compute the tweak:
|
|
124
|
+
// taggedHash("TapTweak", internalPubkey).
|
|
125
|
+
this.tapTweak = schnorr.utils.taggedHash('TapTweak', aggPubkey);
|
|
113
126
|
|
|
114
127
|
if(!payment.address) {
|
|
115
128
|
throw new AggregationCohortError(
|
|
@@ -147,6 +160,19 @@ export class AggregationCohort {
|
|
|
147
160
|
}
|
|
148
161
|
}
|
|
149
162
|
|
|
163
|
+
/**
|
|
164
|
+
* Returns the position of a participant's public key in the sorted
|
|
165
|
+
* {@link cohortKeys} array, or -1 if the participant is not in the cohort.
|
|
166
|
+
* Required by MuSig2 partial-sig verification which indexes by signer position.
|
|
167
|
+
*/
|
|
168
|
+
public indexOfParticipant(did: string): number {
|
|
169
|
+
const pk = this.participantKeys.get(did);
|
|
170
|
+
if(!pk) return -1;
|
|
171
|
+
return this.#cohortKeys.findIndex(k =>
|
|
172
|
+
k.length === pk.length && k.every((b, i) => b === pk[i])
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
150
176
|
public addUpdate(participantDid: string, signedUpdate: SignedBTCR2Update): void {
|
|
151
177
|
if(!this.participants.includes(participantDid)) {
|
|
152
178
|
throw new AggregationCohortError(
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal injectable logger for the aggregation subsystem.
|
|
3
|
+
*
|
|
4
|
+
* Each runner and transport adapter accepts a `Logger` option; the default is
|
|
5
|
+
* {@link CONSOLE_LOGGER}, which forwards to `console.*`. Pass
|
|
6
|
+
* {@link SILENT_LOGGER} to suppress output (useful for tests) or a custom
|
|
7
|
+
* implementation to route logs to pino, winston, Sentry, etc.
|
|
8
|
+
*
|
|
9
|
+
* The interface is intentionally small — we don't want production code taking
|
|
10
|
+
* a hard dependency on any specific logger library.
|
|
11
|
+
*/
|
|
12
|
+
export interface Logger {
|
|
13
|
+
debug(message: string, ...args: unknown[]): void;
|
|
14
|
+
info(message: string, ...args: unknown[]): void;
|
|
15
|
+
warn(message: string, ...args: unknown[]): void;
|
|
16
|
+
error(message: string, ...args: unknown[]): void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Console-backed logger. Default for runners and transports. */
|
|
20
|
+
export const CONSOLE_LOGGER: Logger = {
|
|
21
|
+
debug : (msg, ...args) => console.debug(msg, ...args),
|
|
22
|
+
info : (msg, ...args) => console.info(msg, ...args),
|
|
23
|
+
warn : (msg, ...args) => console.warn(msg, ...args),
|
|
24
|
+
error : (msg, ...args) => console.error(msg, ...args),
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** No-op logger. Useful for tests and production environments with own logging pipeline. */
|
|
28
|
+
export const SILENT_LOGGER: Logger = {
|
|
29
|
+
debug : () => {},
|
|
30
|
+
info : () => {},
|
|
31
|
+
warn : () => {},
|
|
32
|
+
error : () => {},
|
|
33
|
+
};
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Current on-the-wire protocol version.
|
|
3
|
+
*
|
|
4
|
+
* Receivers reject messages with an unknown (mismatched) version. Bumping this
|
|
5
|
+
* requires coordinated updates across all participants and any intermediate
|
|
6
|
+
* relays that inspect message content.
|
|
7
|
+
*/
|
|
8
|
+
export const AGGREGATION_WIRE_VERSION = 1;
|
|
9
|
+
|
|
1
10
|
export type BaseBody = {
|
|
2
11
|
cohortId: string;
|
|
3
12
|
cohortSize?: number;
|
|
@@ -10,6 +19,8 @@ export type BaseBody = {
|
|
|
10
19
|
nonceContribution?: Uint8Array;
|
|
11
20
|
partialSignature?: Uint8Array;
|
|
12
21
|
pendingTx?: string;
|
|
22
|
+
/** Hex-encoded scriptPubKey of the UTXO being spent. Required for BIP-341 sighash. */
|
|
23
|
+
prevOutScriptHex?: string;
|
|
13
24
|
prevOutValue?: string;
|
|
14
25
|
communicationPk?: Uint8Array;
|
|
15
26
|
beaconType?: string;
|
|
@@ -23,6 +34,7 @@ export type BaseBody = {
|
|
|
23
34
|
|
|
24
35
|
export type Base = {
|
|
25
36
|
type: string;
|
|
37
|
+
version?: number;
|
|
26
38
|
to?: string;
|
|
27
39
|
from: string;
|
|
28
40
|
body?: BaseBody;
|
|
@@ -30,12 +42,14 @@ export type Base = {
|
|
|
30
42
|
|
|
31
43
|
export class BaseMessage {
|
|
32
44
|
public type: string;
|
|
45
|
+
public version: number;
|
|
33
46
|
public to?: string;
|
|
34
47
|
public from: string;
|
|
35
48
|
public body?: BaseBody;
|
|
36
49
|
|
|
37
|
-
constructor({ type, to, from, body }: Base) {
|
|
50
|
+
constructor({ type, version, to, from, body }: Base) {
|
|
38
51
|
this.type = type;
|
|
52
|
+
this.version = version ?? AGGREGATION_WIRE_VERSION;
|
|
39
53
|
this.to = to;
|
|
40
54
|
this.from = from;
|
|
41
55
|
this.body = body;
|
|
@@ -47,10 +61,11 @@ export class BaseMessage {
|
|
|
47
61
|
*/
|
|
48
62
|
public toJSON(): Base {
|
|
49
63
|
return {
|
|
50
|
-
type
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
64
|
+
type : this.type,
|
|
65
|
+
version : this.version,
|
|
66
|
+
to : this.to,
|
|
67
|
+
from : this.from,
|
|
68
|
+
body : this.body
|
|
54
69
|
};
|
|
55
70
|
}
|
|
56
71
|
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-message-type body interfaces and a discriminated {@link AggregationMessage}
|
|
3
|
+
* union.
|
|
4
|
+
*
|
|
5
|
+
* {@link BaseBody} remains the superset-of-all-fields body type used by the
|
|
6
|
+
* raw {@link BaseMessage} class (see `base.ts`). The narrow interfaces here
|
|
7
|
+
* describe what each specific message type is *required* to carry and are
|
|
8
|
+
* exposed alongside type guards for consumers who want compile-time narrowing.
|
|
9
|
+
*
|
|
10
|
+
* Guards validate both `type` and the presence of required body fields so they
|
|
11
|
+
* are safe to use on messages that have round-tripped through JSON / a relay.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { SerializedSMTProof } from '@did-btcr2/smt';
|
|
15
|
+
import type { BaseMessage } from './base.js';
|
|
16
|
+
import {
|
|
17
|
+
AGGREGATED_NONCE,
|
|
18
|
+
AUTHORIZATION_REQUEST,
|
|
19
|
+
COHORT_ADVERT,
|
|
20
|
+
COHORT_OPT_IN,
|
|
21
|
+
COHORT_OPT_IN_ACCEPT,
|
|
22
|
+
COHORT_READY,
|
|
23
|
+
DISTRIBUTE_AGGREGATED_DATA,
|
|
24
|
+
NONCE_CONTRIBUTION,
|
|
25
|
+
SIGNATURE_AUTHORIZATION,
|
|
26
|
+
SUBMIT_UPDATE,
|
|
27
|
+
VALIDATION_ACK,
|
|
28
|
+
} from './constants.js';
|
|
29
|
+
|
|
30
|
+
// ── Cohort formation (Step 1) ─────────────────────────────────────────────
|
|
31
|
+
|
|
32
|
+
export interface CohortAdvertBody {
|
|
33
|
+
cohortId: string;
|
|
34
|
+
cohortSize: number;
|
|
35
|
+
beaconType: string;
|
|
36
|
+
network: string;
|
|
37
|
+
communicationPk: Uint8Array;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface CohortOptInBody {
|
|
41
|
+
cohortId: string;
|
|
42
|
+
participantPk: Uint8Array;
|
|
43
|
+
communicationPk: Uint8Array;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface CohortOptInAcceptBody {
|
|
47
|
+
cohortId: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface CohortReadyBody {
|
|
51
|
+
cohortId: string;
|
|
52
|
+
beaconAddress: string;
|
|
53
|
+
cohortKeys: Array<Uint8Array>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ── Update / aggregation (Steps 2-3) ──────────────────────────────────────
|
|
57
|
+
|
|
58
|
+
export interface SubmitUpdateBody {
|
|
59
|
+
cohortId: string;
|
|
60
|
+
signedUpdate: Record<string, unknown>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface DistributeAggregatedDataBody {
|
|
64
|
+
cohortId: string;
|
|
65
|
+
beaconType: string;
|
|
66
|
+
signalBytesHex: string;
|
|
67
|
+
casAnnouncement?: Record<string, string>;
|
|
68
|
+
smtProof?: Record<string, unknown> | SerializedSMTProof;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface ValidationAckBody {
|
|
72
|
+
cohortId: string;
|
|
73
|
+
approved: boolean;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// ── Signing (Step 4) ──────────────────────────────────────────────────────
|
|
77
|
+
|
|
78
|
+
export interface AuthorizationRequestBody {
|
|
79
|
+
cohortId: string;
|
|
80
|
+
sessionId: string;
|
|
81
|
+
pendingTx: string;
|
|
82
|
+
prevOutScriptHex: string;
|
|
83
|
+
prevOutValue: string;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface NonceContributionBody {
|
|
87
|
+
cohortId: string;
|
|
88
|
+
sessionId: string;
|
|
89
|
+
nonceContribution: Uint8Array;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface AggregatedNonceBody {
|
|
93
|
+
cohortId: string;
|
|
94
|
+
sessionId: string;
|
|
95
|
+
aggregatedNonce: Uint8Array;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface SignatureAuthorizationBody {
|
|
99
|
+
cohortId: string;
|
|
100
|
+
sessionId: string;
|
|
101
|
+
partialSignature: Uint8Array;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// ── Narrow message types (BaseMessage & { type, body }) ──────────────────
|
|
105
|
+
|
|
106
|
+
export type CohortAdvertMessage = BaseMessage & { type: typeof COHORT_ADVERT; body: CohortAdvertBody };
|
|
107
|
+
export type CohortOptInMessage = BaseMessage & { type: typeof COHORT_OPT_IN; body: CohortOptInBody };
|
|
108
|
+
export type CohortOptInAcceptMessage = BaseMessage & { type: typeof COHORT_OPT_IN_ACCEPT; body: CohortOptInAcceptBody };
|
|
109
|
+
export type CohortReadyMessage = BaseMessage & { type: typeof COHORT_READY; body: CohortReadyBody };
|
|
110
|
+
export type SubmitUpdateMessage = BaseMessage & { type: typeof SUBMIT_UPDATE; body: SubmitUpdateBody };
|
|
111
|
+
export type DistributeAggregatedDataMessage = BaseMessage & { type: typeof DISTRIBUTE_AGGREGATED_DATA; body: DistributeAggregatedDataBody };
|
|
112
|
+
export type ValidationAckMessage = BaseMessage & { type: typeof VALIDATION_ACK; body: ValidationAckBody };
|
|
113
|
+
export type AuthorizationRequestMessage = BaseMessage & { type: typeof AUTHORIZATION_REQUEST; body: AuthorizationRequestBody };
|
|
114
|
+
export type NonceContributionMessage = BaseMessage & { type: typeof NONCE_CONTRIBUTION; body: NonceContributionBody };
|
|
115
|
+
export type AggregatedNonceMessage = BaseMessage & { type: typeof AGGREGATED_NONCE; body: AggregatedNonceBody };
|
|
116
|
+
export type SignatureAuthorizationMessage = BaseMessage & { type: typeof SIGNATURE_AUTHORIZATION; body: SignatureAuthorizationBody };
|
|
117
|
+
|
|
118
|
+
/** Discriminated union of every well-formed aggregation message. */
|
|
119
|
+
export type AggregationMessage =
|
|
120
|
+
| CohortAdvertMessage
|
|
121
|
+
| CohortOptInMessage
|
|
122
|
+
| CohortOptInAcceptMessage
|
|
123
|
+
| CohortReadyMessage
|
|
124
|
+
| SubmitUpdateMessage
|
|
125
|
+
| DistributeAggregatedDataMessage
|
|
126
|
+
| ValidationAckMessage
|
|
127
|
+
| AuthorizationRequestMessage
|
|
128
|
+
| NonceContributionMessage
|
|
129
|
+
| AggregatedNonceMessage
|
|
130
|
+
| SignatureAuthorizationMessage;
|
|
131
|
+
|
|
132
|
+
// ── Type guards ───────────────────────────────────────────────────────────
|
|
133
|
+
// Each guard validates `type` plus required body fields so it's safe to use
|
|
134
|
+
// on messages that have round-tripped through JSON / a relay.
|
|
135
|
+
|
|
136
|
+
const hasStr = (b: unknown, k: string): boolean =>
|
|
137
|
+
!!b && typeof (b as Record<string, unknown>)[k] === 'string';
|
|
138
|
+
const hasNum = (b: unknown, k: string): boolean =>
|
|
139
|
+
!!b && typeof (b as Record<string, unknown>)[k] === 'number';
|
|
140
|
+
const hasBool = (b: unknown, k: string): boolean =>
|
|
141
|
+
!!b && typeof (b as Record<string, unknown>)[k] === 'boolean';
|
|
142
|
+
const hasBytes = (b: unknown, k: string): boolean =>
|
|
143
|
+
!!b && (b as Record<string, unknown>)[k] instanceof Uint8Array;
|
|
144
|
+
const hasBytesArray = (b: unknown, k: string): boolean => {
|
|
145
|
+
const v = b ? (b as Record<string, unknown>)[k] : undefined;
|
|
146
|
+
return Array.isArray(v) && v.every(x => x instanceof Uint8Array);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export function isCohortAdvertMessage(m: BaseMessage): m is CohortAdvertMessage {
|
|
150
|
+
return m.type === COHORT_ADVERT
|
|
151
|
+
&& hasStr(m.body, 'cohortId')
|
|
152
|
+
&& hasNum(m.body, 'cohortSize')
|
|
153
|
+
&& hasStr(m.body, 'beaconType')
|
|
154
|
+
&& hasStr(m.body, 'network')
|
|
155
|
+
&& hasBytes(m.body, 'communicationPk');
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function isCohortOptInMessage(m: BaseMessage): m is CohortOptInMessage {
|
|
159
|
+
return m.type === COHORT_OPT_IN
|
|
160
|
+
&& hasStr(m.body, 'cohortId')
|
|
161
|
+
&& hasBytes(m.body, 'participantPk')
|
|
162
|
+
&& hasBytes(m.body, 'communicationPk');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function isCohortOptInAcceptMessage(m: BaseMessage): m is CohortOptInAcceptMessage {
|
|
166
|
+
return m.type === COHORT_OPT_IN_ACCEPT && hasStr(m.body, 'cohortId');
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export function isCohortReadyMessage(m: BaseMessage): m is CohortReadyMessage {
|
|
170
|
+
return m.type === COHORT_READY
|
|
171
|
+
&& hasStr(m.body, 'cohortId')
|
|
172
|
+
&& hasStr(m.body, 'beaconAddress')
|
|
173
|
+
&& hasBytesArray(m.body, 'cohortKeys');
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function isSubmitUpdateMessage(m: BaseMessage): m is SubmitUpdateMessage {
|
|
177
|
+
return m.type === SUBMIT_UPDATE
|
|
178
|
+
&& hasStr(m.body, 'cohortId')
|
|
179
|
+
&& !!m.body && typeof (m.body as Record<string, unknown>).signedUpdate === 'object';
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function isDistributeAggregatedDataMessage(m: BaseMessage): m is DistributeAggregatedDataMessage {
|
|
183
|
+
return m.type === DISTRIBUTE_AGGREGATED_DATA
|
|
184
|
+
&& hasStr(m.body, 'cohortId')
|
|
185
|
+
&& hasStr(m.body, 'beaconType')
|
|
186
|
+
&& hasStr(m.body, 'signalBytesHex');
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function isValidationAckMessage(m: BaseMessage): m is ValidationAckMessage {
|
|
190
|
+
return m.type === VALIDATION_ACK
|
|
191
|
+
&& hasStr(m.body, 'cohortId')
|
|
192
|
+
&& hasBool(m.body, 'approved');
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export function isAuthorizationRequestMessage(m: BaseMessage): m is AuthorizationRequestMessage {
|
|
196
|
+
return m.type === AUTHORIZATION_REQUEST
|
|
197
|
+
&& hasStr(m.body, 'cohortId')
|
|
198
|
+
&& hasStr(m.body, 'sessionId')
|
|
199
|
+
&& hasStr(m.body, 'pendingTx')
|
|
200
|
+
&& hasStr(m.body, 'prevOutScriptHex')
|
|
201
|
+
&& hasStr(m.body, 'prevOutValue');
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export function isNonceContributionMessage(m: BaseMessage): m is NonceContributionMessage {
|
|
205
|
+
return m.type === NONCE_CONTRIBUTION
|
|
206
|
+
&& hasStr(m.body, 'cohortId')
|
|
207
|
+
&& hasStr(m.body, 'sessionId')
|
|
208
|
+
&& hasBytes(m.body, 'nonceContribution');
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export function isAggregatedNonceMessage(m: BaseMessage): m is AggregatedNonceMessage {
|
|
212
|
+
return m.type === AGGREGATED_NONCE
|
|
213
|
+
&& hasStr(m.body, 'cohortId')
|
|
214
|
+
&& hasStr(m.body, 'sessionId')
|
|
215
|
+
&& hasBytes(m.body, 'aggregatedNonce');
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export function isSignatureAuthorizationMessage(m: BaseMessage): m is SignatureAuthorizationMessage {
|
|
219
|
+
return m.type === SIGNATURE_AUTHORIZATION
|
|
220
|
+
&& hasStr(m.body, 'cohortId')
|
|
221
|
+
&& hasStr(m.body, 'sessionId')
|
|
222
|
+
&& hasBytes(m.body, 'partialSignature');
|
|
223
|
+
}
|