@originals/sdk 1.4.2 → 1.4.3

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.
Files changed (212) hide show
  1. package/package.json +4 -1
  2. package/.eslintrc.json +0 -33
  3. package/src/adapters/FeeOracleMock.ts +0 -9
  4. package/src/adapters/index.ts +0 -5
  5. package/src/adapters/providers/OrdHttpProvider.ts +0 -126
  6. package/src/adapters/providers/OrdMockProvider.ts +0 -101
  7. package/src/adapters/types.ts +0 -66
  8. package/src/bitcoin/BitcoinManager.ts +0 -330
  9. package/src/bitcoin/BroadcastClient.ts +0 -54
  10. package/src/bitcoin/OrdinalsClient.ts +0 -119
  11. package/src/bitcoin/PSBTBuilder.ts +0 -106
  12. package/src/bitcoin/fee-calculation.ts +0 -38
  13. package/src/bitcoin/providers/OrdNodeProvider.ts +0 -92
  14. package/src/bitcoin/providers/OrdinalsProvider.ts +0 -56
  15. package/src/bitcoin/providers/types.ts +0 -59
  16. package/src/bitcoin/transactions/commit.ts +0 -465
  17. package/src/bitcoin/transactions/index.ts +0 -13
  18. package/src/bitcoin/transfer.ts +0 -43
  19. package/src/bitcoin/utxo-selection.ts +0 -322
  20. package/src/bitcoin/utxo.ts +0 -113
  21. package/src/contexts/credentials-v1.json +0 -237
  22. package/src/contexts/credentials-v2-examples.json +0 -5
  23. package/src/contexts/credentials-v2.json +0 -340
  24. package/src/contexts/credentials.json +0 -237
  25. package/src/contexts/data-integrity-v2.json +0 -81
  26. package/src/contexts/dids.json +0 -58
  27. package/src/contexts/ed255192020.json +0 -93
  28. package/src/contexts/ordinals-plus.json +0 -23
  29. package/src/contexts/originals.json +0 -22
  30. package/src/core/OriginalsSDK.ts +0 -416
  31. package/src/crypto/Multikey.ts +0 -194
  32. package/src/crypto/Signer.ts +0 -254
  33. package/src/crypto/noble-init.ts +0 -121
  34. package/src/did/BtcoDidResolver.ts +0 -227
  35. package/src/did/DIDManager.ts +0 -694
  36. package/src/did/Ed25519Verifier.ts +0 -68
  37. package/src/did/KeyManager.ts +0 -236
  38. package/src/did/WebVHManager.ts +0 -498
  39. package/src/did/createBtcoDidDocument.ts +0 -59
  40. package/src/did/providers/OrdinalsClientProviderAdapter.ts +0 -68
  41. package/src/events/EventEmitter.ts +0 -222
  42. package/src/events/index.ts +0 -19
  43. package/src/events/types.ts +0 -331
  44. package/src/examples/basic-usage.ts +0 -78
  45. package/src/examples/create-module-original.ts +0 -435
  46. package/src/examples/full-lifecycle-flow.ts +0 -514
  47. package/src/examples/run.ts +0 -60
  48. package/src/index.ts +0 -150
  49. package/src/kinds/KindRegistry.ts +0 -290
  50. package/src/kinds/index.ts +0 -74
  51. package/src/kinds/types.ts +0 -470
  52. package/src/kinds/validators/AgentValidator.ts +0 -257
  53. package/src/kinds/validators/AppValidator.ts +0 -211
  54. package/src/kinds/validators/DatasetValidator.ts +0 -242
  55. package/src/kinds/validators/DocumentValidator.ts +0 -311
  56. package/src/kinds/validators/MediaValidator.ts +0 -269
  57. package/src/kinds/validators/ModuleValidator.ts +0 -225
  58. package/src/kinds/validators/base.ts +0 -276
  59. package/src/kinds/validators/index.ts +0 -12
  60. package/src/lifecycle/BatchOperations.ts +0 -373
  61. package/src/lifecycle/LifecycleManager.ts +0 -2126
  62. package/src/lifecycle/OriginalsAsset.ts +0 -524
  63. package/src/lifecycle/ProvenanceQuery.ts +0 -280
  64. package/src/lifecycle/ResourceVersioning.ts +0 -163
  65. package/src/migration/MigrationManager.ts +0 -527
  66. package/src/migration/audit/AuditLogger.ts +0 -176
  67. package/src/migration/checkpoint/CheckpointManager.ts +0 -112
  68. package/src/migration/checkpoint/CheckpointStorage.ts +0 -101
  69. package/src/migration/index.ts +0 -33
  70. package/src/migration/operations/BaseMigration.ts +0 -126
  71. package/src/migration/operations/PeerToBtcoMigration.ts +0 -105
  72. package/src/migration/operations/PeerToWebvhMigration.ts +0 -62
  73. package/src/migration/operations/WebvhToBtcoMigration.ts +0 -105
  74. package/src/migration/rollback/RollbackManager.ts +0 -170
  75. package/src/migration/state/StateMachine.ts +0 -92
  76. package/src/migration/state/StateTracker.ts +0 -156
  77. package/src/migration/types.ts +0 -344
  78. package/src/migration/validation/BitcoinValidator.ts +0 -107
  79. package/src/migration/validation/CredentialValidator.ts +0 -62
  80. package/src/migration/validation/DIDCompatibilityValidator.ts +0 -151
  81. package/src/migration/validation/LifecycleValidator.ts +0 -64
  82. package/src/migration/validation/StorageValidator.ts +0 -79
  83. package/src/migration/validation/ValidationPipeline.ts +0 -213
  84. package/src/resources/ResourceManager.ts +0 -655
  85. package/src/resources/index.ts +0 -21
  86. package/src/resources/types.ts +0 -202
  87. package/src/storage/LocalStorageAdapter.ts +0 -61
  88. package/src/storage/MemoryStorageAdapter.ts +0 -29
  89. package/src/storage/StorageAdapter.ts +0 -25
  90. package/src/storage/index.ts +0 -3
  91. package/src/types/bitcoin.ts +0 -98
  92. package/src/types/common.ts +0 -92
  93. package/src/types/credentials.ts +0 -88
  94. package/src/types/did.ts +0 -31
  95. package/src/types/external-shims.d.ts +0 -53
  96. package/src/types/index.ts +0 -7
  97. package/src/types/network.ts +0 -175
  98. package/src/utils/EventLogger.ts +0 -298
  99. package/src/utils/Logger.ts +0 -322
  100. package/src/utils/MetricsCollector.ts +0 -358
  101. package/src/utils/bitcoin-address.ts +0 -130
  102. package/src/utils/cbor.ts +0 -12
  103. package/src/utils/encoding.ts +0 -127
  104. package/src/utils/hash.ts +0 -6
  105. package/src/utils/retry.ts +0 -46
  106. package/src/utils/satoshi-validation.ts +0 -196
  107. package/src/utils/serialization.ts +0 -96
  108. package/src/utils/telemetry.ts +0 -40
  109. package/src/utils/validation.ts +0 -119
  110. package/src/vc/CredentialManager.ts +0 -918
  111. package/src/vc/Issuer.ts +0 -100
  112. package/src/vc/Verifier.ts +0 -47
  113. package/src/vc/cryptosuites/bbs.ts +0 -253
  114. package/src/vc/cryptosuites/bbsSimple.ts +0 -21
  115. package/src/vc/cryptosuites/eddsa.ts +0 -99
  116. package/src/vc/documentLoader.ts +0 -67
  117. package/src/vc/proofs/data-integrity.ts +0 -33
  118. package/src/vc/utils/jsonld.ts +0 -18
  119. package/tests/__mocks__/bbs-signatures.js +0 -17
  120. package/tests/__mocks__/mf-base58.js +0 -24
  121. package/tests/fixtures/did-documents.ts +0 -247
  122. package/tests/index.test.ts +0 -21
  123. package/tests/integration/BatchOperations.test.ts +0 -531
  124. package/tests/integration/CompleteLifecycle.e2e.test.ts +0 -735
  125. package/tests/integration/CredentialManager.test.ts +0 -42
  126. package/tests/integration/DIDManager.test.ts +0 -41
  127. package/tests/integration/DidPeerToWebVhFlow.test.ts +0 -351
  128. package/tests/integration/Events.test.ts +0 -435
  129. package/tests/integration/Lifecycle.transfer.btco.integration.test.ts +0 -25
  130. package/tests/integration/LifecycleManager.test.ts +0 -21
  131. package/tests/integration/MultikeyFlow.test.ts +0 -52
  132. package/tests/integration/TelemetryIntegration.test.ts +0 -395
  133. package/tests/integration/WebVhPublish.test.ts +0 -48
  134. package/tests/integration/createTypedOriginal.test.ts +0 -379
  135. package/tests/integration/migration/peer-to-webvh.test.ts +0 -172
  136. package/tests/manual/test-commit-creation.ts +0 -323
  137. package/tests/mocks/MockKeyStore.ts +0 -38
  138. package/tests/mocks/adapters/MemoryStorageAdapter.ts +0 -24
  139. package/tests/mocks/adapters/MockFeeOracle.ts +0 -11
  140. package/tests/mocks/adapters/MockOrdinalsProvider.ts +0 -76
  141. package/tests/mocks/adapters/OrdMockProvider.test.ts +0 -176
  142. package/tests/mocks/adapters/index.ts +0 -6
  143. package/tests/performance/BatchOperations.perf.test.ts +0 -403
  144. package/tests/performance/logging.perf.test.ts +0 -336
  145. package/tests/sdk.test.ts +0 -43
  146. package/tests/security/bitcoin-penetration-tests.test.ts +0 -622
  147. package/tests/setup.bun.ts +0 -69
  148. package/tests/setup.jest.ts +0 -23
  149. package/tests/stress/batch-operations-stress.test.ts +0 -571
  150. package/tests/unit/adapters/FeeOracleMock.test.ts +0 -40
  151. package/tests/unit/bitcoin/BitcoinManager.test.ts +0 -293
  152. package/tests/unit/bitcoin/BroadcastClient.test.ts +0 -52
  153. package/tests/unit/bitcoin/OrdNodeProvider.test.ts +0 -53
  154. package/tests/unit/bitcoin/OrdinalsClient.test.ts +0 -381
  155. package/tests/unit/bitcoin/OrdinalsClientProvider.test.ts +0 -102
  156. package/tests/unit/bitcoin/PSBTBuilder.test.ts +0 -84
  157. package/tests/unit/bitcoin/fee-calculation.test.ts +0 -261
  158. package/tests/unit/bitcoin/transactions/commit.test.ts +0 -649
  159. package/tests/unit/bitcoin/transfer.test.ts +0 -31
  160. package/tests/unit/bitcoin/utxo-selection-new.test.ts +0 -502
  161. package/tests/unit/bitcoin/utxo.more.test.ts +0 -39
  162. package/tests/unit/bitcoin/utxo.selection.test.ts +0 -38
  163. package/tests/unit/core/OriginalsSDK.test.ts +0 -152
  164. package/tests/unit/crypto/Multikey.test.ts +0 -206
  165. package/tests/unit/crypto/Signer.test.ts +0 -408
  166. package/tests/unit/did/BtcoDidResolver.test.ts +0 -611
  167. package/tests/unit/did/DIDManager.more.test.ts +0 -43
  168. package/tests/unit/did/DIDManager.test.ts +0 -185
  169. package/tests/unit/did/Ed25519Verifier.test.ts +0 -160
  170. package/tests/unit/did/KeyManager.test.ts +0 -452
  171. package/tests/unit/did/OrdinalsClientProviderAdapter.test.ts +0 -45
  172. package/tests/unit/did/WebVHManager.test.ts +0 -435
  173. package/tests/unit/did/createBtcoDidDocument.test.ts +0 -67
  174. package/tests/unit/did/providers/OrdinalsClientProviderAdapter.test.ts +0 -159
  175. package/tests/unit/events/EventEmitter.test.ts +0 -407
  176. package/tests/unit/kinds/KindRegistry.test.ts +0 -329
  177. package/tests/unit/kinds/types.test.ts +0 -409
  178. package/tests/unit/kinds/validators.test.ts +0 -651
  179. package/tests/unit/lifecycle/BatchOperations.test.ts +0 -527
  180. package/tests/unit/lifecycle/LifecycleManager.cleanapi.test.ts +0 -441
  181. package/tests/unit/lifecycle/LifecycleManager.keymanagement.test.ts +0 -312
  182. package/tests/unit/lifecycle/LifecycleManager.prov.test.ts +0 -18
  183. package/tests/unit/lifecycle/LifecycleManager.test.ts +0 -213
  184. package/tests/unit/lifecycle/LifecycleManager.transfer.unit.test.ts +0 -30
  185. package/tests/unit/lifecycle/OriginalsAsset.test.ts +0 -176
  186. package/tests/unit/lifecycle/ProvenanceQuery.test.ts +0 -577
  187. package/tests/unit/lifecycle/ResourceVersioning.test.ts +0 -651
  188. package/tests/unit/resources/ResourceManager.test.ts +0 -740
  189. package/tests/unit/storage/MemoryStorageAdapter.test.ts +0 -93
  190. package/tests/unit/types/network.test.ts +0 -255
  191. package/tests/unit/utils/EventIntegration.test.ts +0 -384
  192. package/tests/unit/utils/Logger.test.ts +0 -473
  193. package/tests/unit/utils/MetricsCollector.test.ts +0 -358
  194. package/tests/unit/utils/bitcoin-address.test.ts +0 -250
  195. package/tests/unit/utils/cbor.test.ts +0 -35
  196. package/tests/unit/utils/encoding.test.ts +0 -318
  197. package/tests/unit/utils/hash.test.ts +0 -12
  198. package/tests/unit/utils/retry.test.ts +0 -100
  199. package/tests/unit/utils/satoshi-validation.test.ts +0 -354
  200. package/tests/unit/utils/serialization.test.ts +0 -124
  201. package/tests/unit/utils/telemetry.test.ts +0 -52
  202. package/tests/unit/utils/validation.test.ts +0 -141
  203. package/tests/unit/vc/CredentialManager.helpers.test.ts +0 -527
  204. package/tests/unit/vc/CredentialManager.test.ts +0 -487
  205. package/tests/unit/vc/Issuer.test.ts +0 -107
  206. package/tests/unit/vc/Verifier.test.ts +0 -525
  207. package/tests/unit/vc/bbs.test.ts +0 -282
  208. package/tests/unit/vc/cryptosuites/eddsa.test.ts +0 -398
  209. package/tests/unit/vc/documentLoader.test.ts +0 -121
  210. package/tests/unit/vc/proofs/data-integrity.test.ts +0 -24
  211. package/tsconfig.json +0 -31
  212. package/tsconfig.test.json +0 -15
package/src/vc/Issuer.ts DELETED
@@ -1,100 +0,0 @@
1
- import { VerifiableCredential, VerifiablePresentation, Proof } from '../types';
2
- import { multikey, MultikeyType } from '../crypto/Multikey';
3
- import { DIDManager } from '../did/DIDManager';
4
- import { createDocumentLoader } from './documentLoader';
5
- import { DataIntegrityProofManager } from './proofs/data-integrity';
6
-
7
- export interface IssueOptions {
8
- proofPurpose: 'assertionMethod' | 'authentication';
9
- documentLoader?: (iri: string) => Promise<{ document: any; documentUrl: string; contextUrl: string | null }>;
10
- challenge?: string;
11
- domain?: string;
12
- }
13
-
14
- export type VerificationMethodLike = {
15
- id: string;
16
- controller: string;
17
- publicKeyMultibase: string;
18
- secretKeyMultibase?: string;
19
- type?: 'Multikey' | string;
20
- };
21
-
22
- export class Issuer {
23
- constructor(private didManager: DIDManager, private verificationMethod: VerificationMethodLike) {}
24
-
25
- private inferKeyType(publicKeyMultibase: string): MultikeyType {
26
- try {
27
- return multikey.decodePublicKey(publicKeyMultibase).type;
28
- } catch {
29
- return 'Ed25519';
30
- }
31
- }
32
-
33
- async issueCredential(
34
- unsigned: Omit<VerifiableCredential, '@context' | 'proof'>,
35
- options: IssueOptions
36
- ): Promise<VerifiableCredential> {
37
- const documentLoader = options.documentLoader || createDocumentLoader(this.didManager);
38
- await documentLoader(this.verificationMethod.id);
39
-
40
- const issuerId = typeof unsigned.issuer === 'string' ? unsigned.issuer : (unsigned.issuer as any)?.id;
41
- const credential: VerifiableCredential = {
42
- ...unsigned,
43
- '@context': ['https://www.w3.org/ns/credentials/v2'],
44
- issuer: issuerId || this.verificationMethod.controller,
45
- proof: undefined
46
- } as any;
47
-
48
- if (!this.verificationMethod.secretKeyMultibase) {
49
- throw new Error('Missing secretKeyMultibase for issuance');
50
- }
51
- const keyType = this.inferKeyType(this.verificationMethod.publicKeyMultibase);
52
- if (keyType !== 'Ed25519') {
53
- throw new Error('Only Ed25519 supported for eddsa-rdfc-2022');
54
- }
55
- const proof = await DataIntegrityProofManager.createProof(credential, {
56
- verificationMethod: this.verificationMethod.id,
57
- proofPurpose: options.proofPurpose,
58
- cryptosuite: 'eddsa-rdfc-2022',
59
- type: 'DataIntegrityProof',
60
- privateKey: this.verificationMethod.secretKeyMultibase,
61
- documentLoader
62
- });
63
- return { ...credential, proof } as any;
64
- }
65
-
66
- async issuePresentation(
67
- presentation: Omit<VerifiablePresentation, '@context' | 'proof'>,
68
- options: IssueOptions
69
- ): Promise<VerifiablePresentation> {
70
- const documentLoader = options.documentLoader || createDocumentLoader(this.didManager);
71
- await documentLoader(this.verificationMethod.id);
72
-
73
- if (!this.verificationMethod.secretKeyMultibase) {
74
- throw new Error('Missing secretKeyMultibase for issuance');
75
- }
76
- const keyType = this.inferKeyType(this.verificationMethod.publicKeyMultibase);
77
- if (keyType !== 'Ed25519') {
78
- throw new Error('Only Ed25519 supported for eddsa-rdfc-2022');
79
- }
80
- const proof = await DataIntegrityProofManager.createProof(
81
- { ...(presentation as any), '@context': ['https://www.w3.org/ns/credentials/v2'] },
82
- {
83
- verificationMethod: this.verificationMethod.id,
84
- proofPurpose: options.proofPurpose,
85
- cryptosuite: 'eddsa-rdfc-2022',
86
- type: 'DataIntegrityProof',
87
- privateKey: this.verificationMethod.secretKeyMultibase,
88
- challenge: options.challenge,
89
- domain: options.domain,
90
- documentLoader
91
- }
92
- );
93
- return {
94
- ...(presentation as any),
95
- '@context': ['https://www.w3.org/ns/credentials/v2'],
96
- proof
97
- } as VerifiablePresentation;
98
- }
99
- }
100
-
@@ -1,47 +0,0 @@
1
- import { VerifiableCredential, VerifiablePresentation } from '../types';
2
- import { DIDManager } from '../did/DIDManager';
3
- import { createDocumentLoader } from './documentLoader';
4
- import { DataIntegrityProofManager } from './proofs/data-integrity';
5
-
6
- export type VerificationResult = { verified: boolean; errors: string[] };
7
-
8
- export class Verifier {
9
- constructor(private didManager: DIDManager) {}
10
-
11
- async verifyCredential(vc: VerifiableCredential, options: { documentLoader?: (iri: string) => Promise<any> } = {}): Promise<VerificationResult> {
12
- try {
13
- if (!vc || !vc['@context'] || !vc.type) throw new Error('Invalid credential');
14
- if (!vc.proof) throw new Error('Credential has no proof');
15
- const loader = options.documentLoader || createDocumentLoader(this.didManager);
16
- const ctxs: string[] = Array.isArray(vc['@context']) ? (vc['@context'] as any) : [vc['@context'] as any];
17
- for (const c of ctxs) await loader(c);
18
- const proof = Array.isArray(vc.proof) ? (vc.proof as any)[0] : (vc.proof as any);
19
- const result = await DataIntegrityProofManager.verifyProof(vc, proof, { documentLoader: loader });
20
- return result.verified ? { verified: true, errors: [] } : { verified: false, errors: result.errors ?? ['Verification failed'] };
21
- } catch (e: any) {
22
- return { verified: false, errors: [e?.message ?? 'Unknown error in verifyCredential'] };
23
- }
24
- }
25
-
26
- async verifyPresentation(vp: VerifiablePresentation, options: { documentLoader?: (iri: string) => Promise<any> } = {}): Promise<VerificationResult> {
27
- try {
28
- if (!vp || !vp['@context'] || !vp.type) throw new Error('Invalid presentation');
29
- if (!vp.proof) throw new Error('Presentation has no proof');
30
- const loader = options.documentLoader || createDocumentLoader(this.didManager);
31
- const ctxs: string[] = Array.isArray(vp['@context']) ? (vp['@context'] as any) : [vp['@context'] as any];
32
- for (const c of ctxs) await loader(c);
33
- if (vp.verifiableCredential) {
34
- for (const c of vp.verifiableCredential) {
35
- const res = await this.verifyCredential(c as any, { documentLoader: loader });
36
- if (!res.verified) return res;
37
- }
38
- }
39
- const proof = Array.isArray(vp.proof) ? (vp.proof as any)[0] : (vp.proof as any);
40
- const result = await DataIntegrityProofManager.verifyProof(vp, proof, { documentLoader: loader });
41
- return result.verified ? { verified: true, errors: [] } : { verified: false, errors: result.errors ?? ['Verification failed'] };
42
- } catch (e: any) {
43
- return { verified: false, errors: [e?.message ?? 'Unknown error in verifyPresentation'] };
44
- }
45
- }
46
- }
47
-
@@ -1,253 +0,0 @@
1
- import * as cbor from 'cbor-js';
2
-
3
- /**
4
- * Minimal BBS utility methods ported from legacy for working with
5
- * Data Integrity BBS (bbs-2023) base and derived proof value encoding.
6
- *
7
- * Notes:
8
- * - This module focuses on serialization/parsing helpers used by callers
9
- * to pack/unpack proof values. It does not perform signing or verification.
10
- * - All methods operate on Uint8Array inputs and return multibase strings
11
- * (base64url with 'u' prefix) where applicable to match the spec.
12
- */
13
- export class BBSCryptosuiteUtils {
14
- private static encodeBase64urlNoPad(bytes: Uint8Array): string {
15
- const b64 = Buffer.from(bytes).toString('base64');
16
- const b64url = b64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/g, '');
17
- return 'u' + b64url;
18
- }
19
-
20
- private static decodeBase64urlNoPad(s: string): Uint8Array {
21
- if (!s.startsWith('u')) throw new Error('Not a multibase base64url (u- prefixed) string');
22
- const raw = s.slice(1);
23
- const b64 = raw.replace(/-/g, '+').replace(/_/g, '/');
24
- const pad = b64.length % 4 === 2 ? '==' : b64.length % 4 === 3 ? '=' : '';
25
- return new Uint8Array(Buffer.from(b64 + pad, 'base64'));
26
- }
27
- private static compareBytes(a: Uint8Array, b: number[]): boolean {
28
- if (a.length !== b.length) return false;
29
- for (let i = 0; i < b.length; i++) {
30
- if (a[i] !== b[i]) return false;
31
- }
32
- return true;
33
- }
34
-
35
- private static concatBytes(a: Uint8Array, b: Uint8Array): Uint8Array {
36
- const out = new Uint8Array(a.length + b.length);
37
- out.set(a, 0);
38
- out.set(b, a.length);
39
- return out;
40
- }
41
-
42
- // ===== Base proof (serialize/parse) =====
43
-
44
- static serializeBaseProofValue(
45
- bbsSignature: Uint8Array,
46
- bbsHeader: Uint8Array,
47
- publicKey: Uint8Array,
48
- hmacKey: Uint8Array,
49
- mandatoryPointers: string[],
50
- featureOption: 'baseline' | 'anonymous_holder_binding' | 'pseudonym_issuer_pid' | 'pseudonym_hidden_pid',
51
- pid?: Uint8Array,
52
- signerBlind?: Uint8Array
53
- ): string {
54
- let headerBytes: Uint8Array;
55
- let components: (Uint8Array | string[] | Uint8Array)[];
56
-
57
- switch (featureOption) {
58
- case 'baseline':
59
- headerBytes = new Uint8Array([0xd9, 0x5d, 0x02]);
60
- components = [bbsSignature, bbsHeader, publicKey, hmacKey, mandatoryPointers];
61
- break;
62
- case 'anonymous_holder_binding':
63
- headerBytes = new Uint8Array([0xd9, 0x5d, 0x04]);
64
- if (!signerBlind) throw new Error('signerBlind is required for anonymous_holder_binding');
65
- components = [bbsSignature, bbsHeader, publicKey, hmacKey, mandatoryPointers, signerBlind];
66
- break;
67
- case 'pseudonym_issuer_pid':
68
- headerBytes = new Uint8Array([0xd9, 0x5d, 0x06]);
69
- if (!pid) throw new Error('pid is required for pseudonym_issuer_pid');
70
- components = [bbsSignature, bbsHeader, publicKey, hmacKey, mandatoryPointers, pid];
71
- break;
72
- case 'pseudonym_hidden_pid':
73
- headerBytes = new Uint8Array([0xd9, 0x5d, 0x08]);
74
- if (!signerBlind) throw new Error('signerBlind is required for pseudonym_hidden_pid');
75
- components = [bbsSignature, bbsHeader, publicKey, hmacKey, mandatoryPointers, signerBlind];
76
- break;
77
- default:
78
- throw new Error(`Unsupported feature option: ${featureOption}`);
79
- }
80
-
81
- const encodedComponents = cbor.encode(components);
82
- const proofBytes = BBSCryptosuiteUtils.concatBytes(headerBytes, new Uint8Array(encodedComponents));
83
- return BBSCryptosuiteUtils.encodeBase64urlNoPad(proofBytes);
84
- }
85
-
86
- static parseBaseProofValue(proofValue: string): {
87
- bbsSignature: Uint8Array;
88
- bbsHeader: Uint8Array;
89
- publicKey: Uint8Array;
90
- hmacKey: Uint8Array;
91
- mandatoryPointers: string[];
92
- featureOption: 'baseline' | 'anonymous_holder_binding' | 'pseudonym_issuer_pid' | 'pseudonym_hidden_pid' | 'base_proof';
93
- pid?: Uint8Array;
94
- signerBlind?: Uint8Array;
95
- } {
96
- const decoded = BBSCryptosuiteUtils.decodeBase64urlNoPad(proofValue);
97
- const header = decoded.slice(0, 3);
98
- let featureOption: any;
99
- if (this.compareBytes(header, [0xd9, 0x5d, 0x02])) featureOption = 'baseline';
100
- else if (this.compareBytes(header, [0xd9, 0x5d, 0x04])) featureOption = 'anonymous_holder_binding';
101
- else if (this.compareBytes(header, [0xd9, 0x5d, 0x06])) featureOption = 'pseudonym_issuer_pid';
102
- else if (this.compareBytes(header, [0xd9, 0x5d, 0x08])) featureOption = 'pseudonym_hidden_pid';
103
- else if (this.compareBytes(header, [0xd9, 0x5d, 0x03])) featureOption = 'base_proof';
104
- else throw new Error('Invalid BBS base proof header');
105
-
106
- const components: any[] = cbor.decode(decoded.slice(3).buffer) as any[];
107
- const base = {
108
- bbsSignature: components[0] as Uint8Array,
109
- bbsHeader: components[1] as Uint8Array,
110
- publicKey: components[2] as Uint8Array,
111
- hmacKey: components[3] as Uint8Array,
112
- mandatoryPointers: components[4] as string[],
113
- featureOption
114
- } as any;
115
-
116
- if (featureOption === 'anonymous_holder_binding' || featureOption === 'pseudonym_hidden_pid') {
117
- base.signerBlind = components[5] as Uint8Array;
118
- }
119
- if (featureOption === 'pseudonym_issuer_pid') {
120
- base.pid = components[5] as Uint8Array;
121
- }
122
- return base;
123
- }
124
-
125
- // ===== Label map compression helpers =====
126
-
127
- private static compressLabelMap(labelMap: { [key: string]: string }): { [key: string]: string } {
128
- const map: { [key: string]: string } = {};
129
- for (const [k, v] of Object.entries(labelMap)) {
130
- const c14nMatch = k.match(/^c14n(\d+)$/);
131
- const bMatch = v.match(/^b(\d+)$/);
132
- if (!c14nMatch || !bMatch) {
133
- throw new Error(`Invalid label map entry: ${k} -> ${v}`);
134
- }
135
- const key = parseInt(c14nMatch[1], 10);
136
- const value = parseInt(bMatch[1], 10);
137
- map[key] = value.toString();
138
- }
139
- return map;
140
- }
141
-
142
- private static decompressLabelMap(compressed: { [key: string]: string }): { [key: string]: string } {
143
- const map: { [key: string]: string } = {};
144
- for (const [k, v] of Object.entries(compressed)) {
145
- map[`c14n${k}`] = `b${v}`;
146
- }
147
- return map;
148
- }
149
-
150
- // ===== Derived proof (serialize/parse) =====
151
-
152
- static serializeDerivedProofValue(
153
- bbsProof: Uint8Array,
154
- labelMap: { [key: string]: string },
155
- mandatoryIndexes: number[],
156
- selectiveIndexes: number[],
157
- presentationHeader: Uint8Array,
158
- featureOption: 'baseline' | 'anonymous_holder_binding' | 'pseudonym',
159
- pseudonym?: string,
160
- lengthBBSMessages?: number
161
- ): string {
162
- const compressedLabelMap = this.compressLabelMap(labelMap);
163
-
164
- let headerBytes: Uint8Array;
165
- let components: (Uint8Array | { [key: string]: string } | number[] | number | string)[];
166
-
167
- switch (featureOption) {
168
- case 'baseline':
169
- headerBytes = new Uint8Array([0xd9, 0x5d, 0x03]);
170
- components = [
171
- bbsProof,
172
- compressedLabelMap,
173
- mandatoryIndexes,
174
- selectiveIndexes,
175
- presentationHeader
176
- ];
177
- break;
178
- case 'anonymous_holder_binding':
179
- if (typeof lengthBBSMessages !== 'number') {
180
- throw new Error('lengthBBSMessages is required for anonymous_holder_binding');
181
- }
182
- headerBytes = new Uint8Array([0xd9, 0x5d, 0x05]);
183
- components = [
184
- bbsProof,
185
- compressedLabelMap,
186
- mandatoryIndexes,
187
- selectiveIndexes,
188
- presentationHeader,
189
- lengthBBSMessages
190
- ];
191
- break;
192
- case 'pseudonym':
193
- if (!pseudonym || typeof lengthBBSMessages !== 'number') {
194
- throw new Error('pseudonym and lengthBBSMessages are required for pseudonym features');
195
- }
196
- headerBytes = new Uint8Array([0xd9, 0x5d, 0x07]);
197
- components = [
198
- bbsProof,
199
- compressedLabelMap,
200
- mandatoryIndexes,
201
- selectiveIndexes,
202
- presentationHeader,
203
- pseudonym,
204
- lengthBBSMessages
205
- ];
206
- break;
207
- default:
208
- throw new Error(`Unsupported feature option: ${featureOption}`);
209
- }
210
-
211
- const encodedComponents = cbor.encode(components);
212
- const proofBytes = this.concatBytes(headerBytes, new Uint8Array(encodedComponents));
213
- return this.encodeBase64urlNoPad(proofBytes);
214
- }
215
-
216
- static parseDerivedProofValue(proofValue: string): {
217
- bbsProof: Uint8Array;
218
- labelMap: { [key: string]: string };
219
- mandatoryIndexes: number[];
220
- selectiveIndexes: number[];
221
- presentationHeader: Uint8Array;
222
- featureOption: 'baseline' | 'anonymous_holder_binding' | 'pseudonym';
223
- pseudonym?: string;
224
- lengthBBSMessages?: number;
225
- } {
226
- const decoded = this.decodeBase64urlNoPad(proofValue);
227
- const header = decoded.slice(0, 3);
228
- let featureOption: 'baseline' | 'anonymous_holder_binding' | 'pseudonym';
229
- if (this.compareBytes(header, [0xd9, 0x5d, 0x03])) featureOption = 'baseline';
230
- else if (this.compareBytes(header, [0xd9, 0x5d, 0x05])) featureOption = 'anonymous_holder_binding';
231
- else if (this.compareBytes(header, [0xd9, 0x5d, 0x07])) featureOption = 'pseudonym';
232
- else throw new Error('Invalid BBS derived proof header');
233
-
234
- const components: any[] = cbor.decode(decoded.slice(3).buffer) as any[];
235
- const decompressedLabelMap = this.decompressLabelMap(components[1]);
236
- const result: any = {
237
- bbsProof: components[0],
238
- labelMap: decompressedLabelMap,
239
- mandatoryIndexes: components[2],
240
- selectiveIndexes: components[3],
241
- presentationHeader: components[4],
242
- featureOption
243
- };
244
- if (featureOption === 'anonymous_holder_binding') {
245
- result.lengthBBSMessages = components[5];
246
- } else if (featureOption === 'pseudonym') {
247
- result.pseudonym = components[5];
248
- result.lengthBBSMessages = components[6];
249
- }
250
- return result;
251
- }
252
- }
253
-
@@ -1,21 +0,0 @@
1
- import { sha256 } from '@noble/hashes/sha2.js';
2
-
3
- export type BbsKeyPair = {
4
- publicKey: Uint8Array;
5
- privateKey: Uint8Array;
6
- };
7
-
8
- export class BbsSimple {
9
- static readonly CIPHERSUITE = 'BLS12-381-SHA-256';
10
-
11
- static async sign(messages: Uint8Array[], keypair: BbsKeyPair, header?: Uint8Array): Promise<Uint8Array> {
12
- const headerBytes = header ?? new Uint8Array(sha256(new Uint8Array(0)));
13
- throw new Error('BbsSimple.sign is not implemented');
14
- }
15
-
16
- static async verify(messages: Uint8Array[], signature: Uint8Array, publicKey: Uint8Array, header?: Uint8Array): Promise<boolean> {
17
- const headerBytes = header ?? new Uint8Array(sha256(new Uint8Array(0)));
18
- throw new Error('BbsSimple.verify is not implemented');
19
- }
20
- }
21
-
@@ -1,99 +0,0 @@
1
- import { base58 } from '@scure/base';
2
- import * as ed25519 from '@noble/ed25519';
3
- import { canonize, canonizeProof } from '../utils/jsonld';
4
- import { multikey } from '../../crypto/Multikey';
5
- import { sha256Bytes } from '../../utils/hash';
6
-
7
- export interface DataIntegrityProof {
8
- type: 'DataIntegrityProof';
9
- cryptosuite: string;
10
- created?: string;
11
- verificationMethod: string;
12
- proofPurpose: string;
13
- proofValue: string;
14
- id?: string;
15
- previousProof?: string | string[];
16
- }
17
-
18
- export interface VerificationResult {
19
- verified: boolean;
20
- errors?: string[];
21
- }
22
-
23
- export class EdDSACryptosuiteManager {
24
-
25
- static async createProof(document: any, options: any): Promise<DataIntegrityProof> {
26
- const proofConfig = await this.createProofConfiguration(options);
27
- const transformedData = await this.transform(document, options);
28
- const hashData = await this.hash(transformedData, proofConfig, options);
29
- let privateKey: Uint8Array;
30
- if (typeof options.privateKey === 'string') {
31
- const dec = multikey.decodePrivateKey(options.privateKey);
32
- if (dec.type !== 'Ed25519') throw new Error('Invalid key type for EdDSA');
33
- privateKey = dec.key;
34
- } else if (options.privateKey instanceof Uint8Array) {
35
- privateKey = options.privateKey;
36
- } else {
37
- throw new Error('Invalid private key format');
38
- }
39
- const proofValueBytes = await this.sign({ data: hashData, privateKey });
40
- delete (proofConfig as any)['@context'];
41
- return { ...proofConfig, proofValue: base58.encode(proofValueBytes) } as DataIntegrityProof;
42
- }
43
-
44
- static async verifyProof(document: any, proof: DataIntegrityProof, options: any): Promise<VerificationResult> {
45
- try {
46
- const documentToVerify = { ...document };
47
- delete (documentToVerify as any).proof;
48
- const transformedData = await this.transform(documentToVerify, options);
49
- const hashData = await this.hash(transformedData, { '@context': document['@context'], ...proof }, options);
50
- const vmDoc = await options.documentLoader(proof.verificationMethod);
51
- const pk = vmDoc.document.publicKeyMultibase as string;
52
- const dec = multikey.decodePublicKey(pk);
53
- if (dec.type !== 'Ed25519') throw new Error('Invalid key type for EdDSA');
54
- const signature = base58.decode(proof.proofValue);
55
- const verified = await this.verify({ data: hashData, signature, publicKey: dec.key });
56
- return verified ? { verified: true } : { verified: false, errors: ['Proof verification failed'] };
57
- } catch (e: any) {
58
- return { verified: false, errors: [e?.message ?? 'Unknown verification error'] };
59
- }
60
- }
61
-
62
- private static async createProofConfiguration(options: any): Promise<any> {
63
- return {
64
- '@context': 'https://w3id.org/security/data-integrity/v2',
65
- type: 'DataIntegrityProof',
66
- cryptosuite: 'eddsa-rdfc-2022',
67
- created: new Date().toISOString(),
68
- verificationMethod: options.verificationMethod,
69
- proofPurpose: options.proofPurpose || 'assertionMethod',
70
- ...(options.challenge && { challenge: options.challenge }),
71
- ...(options.domain && { domain: options.domain })
72
- };
73
- }
74
-
75
- private static async transform(document: any, options: any): Promise<string> {
76
- return await canonize(document, { documentLoader: options.documentLoader });
77
- }
78
-
79
- private static async hash(transformedData: string, proofConfig: any, options: any): Promise<Uint8Array> {
80
- const canonicalProofConfig = await canonizeProof(proofConfig, { documentLoader: options.documentLoader });
81
- const proofConfigHash = await sha256Bytes(canonicalProofConfig);
82
- const documentHash = await sha256Bytes(transformedData);
83
- return new Uint8Array([...proofConfigHash, ...documentHash]);
84
- }
85
-
86
- static async sign({ data, privateKey }: { data: Uint8Array; privateKey: Uint8Array }): Promise<Uint8Array> {
87
- if (privateKey.length !== 32) {
88
- if (privateKey.length === 64) privateKey = privateKey.slice(32);
89
- else throw new Error('Invalid private key length');
90
- }
91
- const signature = await ed25519.signAsync(Buffer.from(data).toString('hex'), Buffer.from(privateKey).toString('hex'));
92
- return signature;
93
- }
94
-
95
- static async verify({ data, signature, publicKey }: { data: Uint8Array; signature: Uint8Array; publicKey: Uint8Array }): Promise<boolean> {
96
- return await ed25519.verifyAsync(Buffer.from(signature).toString('hex'), Buffer.from(data).toString('hex'), Buffer.from(publicKey).toString('hex'));
97
- }
98
- }
99
-
@@ -1,67 +0,0 @@
1
- import { DIDManager } from '../did/DIDManager';
2
-
3
- type LoadedDocument = { document: any; documentUrl: string; contextUrl: string | null };
4
-
5
- const CONTEXTS: Record<string, any> = {
6
- // Provide 1.1-compatible stubs for jsonld canonize
7
- 'https://www.w3.org/ns/credentials/v2': { '@context': { '@version': 1.1 } },
8
- 'https://w3id.org/security/data-integrity/v2': { '@context': { '@version': 1.1 } }
9
- };
10
-
11
- export class DocumentLoader {
12
- constructor(private didManager: DIDManager) {}
13
-
14
- async load(iri: string): Promise<LoadedDocument> {
15
- if (iri.startsWith('did:')) {
16
- return this.resolveDID(iri);
17
- }
18
- const doc = CONTEXTS[iri];
19
- if (doc) {
20
- return { document: doc, documentUrl: iri, contextUrl: null };
21
- }
22
- throw new Error(`Document not found: ${iri}`);
23
- }
24
-
25
- private async resolveDID(didUrl: string): Promise<LoadedDocument> {
26
- const [did, fragment] = didUrl.split('#');
27
- const didDoc = await this.didManager.resolveDID(did);
28
- if (!didDoc) {
29
- throw new Error(`DID not resolved: ${did}`);
30
- }
31
- if (fragment) {
32
- // If a VM was registered explicitly, prefer it
33
- const cached = verificationMethodRegistry.get(didUrl);
34
- if (cached) {
35
- return {
36
- document: { '@context': (didDoc as any)['@context'], ...cached },
37
- documentUrl: didUrl,
38
- contextUrl: null
39
- };
40
- }
41
- const vms = (didDoc as any).verificationMethod as any[] | undefined;
42
- const vm = vms?.find((m) => m.id === didUrl);
43
- if (vm) {
44
- return {
45
- document: { '@context': (didDoc as any)['@context'], ...vm },
46
- documentUrl: didUrl,
47
- contextUrl: null
48
- };
49
- }
50
- return {
51
- document: { '@context': (didDoc as any)['@context'], id: didUrl },
52
- documentUrl: didUrl,
53
- contextUrl: null
54
- };
55
- }
56
- return { document: didDoc, documentUrl: didUrl, contextUrl: null };
57
- }
58
- }
59
-
60
- export const createDocumentLoader = (didManager: DIDManager) =>
61
- (iri: string) => new DocumentLoader(didManager).load(iri);
62
-
63
- export const verificationMethodRegistry: Map<string, any> = new Map();
64
- export function registerVerificationMethod(vm: any) {
65
- if (vm?.id) verificationMethodRegistry.set(vm.id, vm);
66
- }
67
-
@@ -1,33 +0,0 @@
1
- import { EdDSACryptosuiteManager, type DataIntegrityProof } from '../cryptosuites/eddsa';
2
-
3
- export interface VerificationResult { verified: boolean; errors?: string[] }
4
-
5
- export interface ProofOptions {
6
- verificationMethod: string;
7
- proofPurpose: string;
8
- privateKey?: Uint8Array | string;
9
- type: 'DataIntegrityProof';
10
- created?: string;
11
- cryptosuite: string;
12
- documentLoader?: (url: string) => Promise<any>;
13
- previousProof?: string | string[];
14
- challenge?: string;
15
- domain?: string;
16
- }
17
-
18
- export class DataIntegrityProofManager {
19
- static async createProof(document: any, options: ProofOptions): Promise<DataIntegrityProof> {
20
- if (options.cryptosuite !== 'eddsa-rdfc-2022') {
21
- throw new Error(`Unsupported cryptosuite: ${options.cryptosuite}`);
22
- }
23
- return await EdDSACryptosuiteManager.createProof(document, options);
24
- }
25
-
26
- static async verifyProof(document: any, proof: DataIntegrityProof, options: any): Promise<VerificationResult> {
27
- if (proof.cryptosuite !== 'eddsa-rdfc-2022') {
28
- return { verified: false, errors: [`Unsupported cryptosuite: ${proof.cryptosuite}`] };
29
- }
30
- return await EdDSACryptosuiteManager.verifyProof(document, proof, options);
31
- }
32
- }
33
-
@@ -1,18 +0,0 @@
1
- import jsonld from 'jsonld';
2
-
3
- export async function canonize(input: any, { documentLoader }: any): Promise<string> {
4
- return await jsonld.canonize(input, {
5
- algorithm: 'URDNA2015',
6
- format: 'application/n-quads',
7
- documentLoader,
8
- safe: false,
9
- useNative: false,
10
- rdfDirection: 'i18n-datatype'
11
- } as any);
12
- }
13
-
14
- export async function canonizeProof(proof: any, { documentLoader }: any): Promise<string> {
15
- const { jws, signatureValue, proofValue, ...rest } = proof;
16
- return await canonize(rest, { documentLoader });
17
- }
18
-
@@ -1,17 +0,0 @@
1
- // Minimal mock for @digitalbazaar/bbs-signatures used in tests
2
- const toHex = (u8) => Buffer.from(u8).toString('hex');
3
-
4
- exports.sign = async ({ secretKey, publicKey, header, messages }) => {
5
- // produce a deterministic pseudo-signature for tests
6
- const data = [secretKey, publicKey, header, ...messages].map(toHex).join('|');
7
- return new Uint8Array(Buffer.from('sig:' + data));
8
- };
9
-
10
- exports.verifySignature = async ({ publicKey, signature, header, messages }) => {
11
- const expected = await exports.sign({ secretKey: new Uint8Array(0), publicKey, header, messages });
12
- // accept any signature that starts with 'sig:' and contains publicKey/header/messages
13
- const sigStr = Buffer.from(signature).toString();
14
- const expStr = Buffer.from(expected).toString();
15
- return sigStr.includes(Buffer.from(publicKey).toString('hex')) && sigStr.includes(Buffer.from(header).toString('hex')) && sigStr.includes(expStr.split('|').slice(2).join('|'));
16
- };
17
-