@originals/sdk 1.8.2 → 1.8.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 (144) hide show
  1. package/package.json +5 -6
  2. package/src/adapters/FeeOracleMock.ts +0 -9
  3. package/src/adapters/index.ts +0 -5
  4. package/src/adapters/providers/OrdHttpProvider.ts +0 -126
  5. package/src/adapters/providers/OrdMockProvider.ts +0 -101
  6. package/src/adapters/types.ts +0 -66
  7. package/src/bitcoin/BitcoinManager.ts +0 -329
  8. package/src/bitcoin/BroadcastClient.ts +0 -54
  9. package/src/bitcoin/OrdinalsClient.ts +0 -120
  10. package/src/bitcoin/PSBTBuilder.ts +0 -106
  11. package/src/bitcoin/fee-calculation.ts +0 -38
  12. package/src/bitcoin/providers/OrdNodeProvider.ts +0 -92
  13. package/src/bitcoin/providers/OrdinalsProvider.ts +0 -56
  14. package/src/bitcoin/providers/types.ts +0 -59
  15. package/src/bitcoin/transactions/commit.ts +0 -465
  16. package/src/bitcoin/transactions/index.ts +0 -13
  17. package/src/bitcoin/transfer.ts +0 -43
  18. package/src/bitcoin/utxo-selection.ts +0 -322
  19. package/src/bitcoin/utxo.ts +0 -113
  20. package/src/cel/ExternalReferenceManager.ts +0 -87
  21. package/src/cel/OriginalsCel.ts +0 -460
  22. package/src/cel/algorithms/createEventLog.ts +0 -68
  23. package/src/cel/algorithms/deactivateEventLog.ts +0 -109
  24. package/src/cel/algorithms/index.ts +0 -11
  25. package/src/cel/algorithms/updateEventLog.ts +0 -99
  26. package/src/cel/algorithms/verifyEventLog.ts +0 -306
  27. package/src/cel/algorithms/witnessEvent.ts +0 -87
  28. package/src/cel/cli/create.ts +0 -330
  29. package/src/cel/cli/index.ts +0 -383
  30. package/src/cel/cli/inspect.ts +0 -549
  31. package/src/cel/cli/migrate.ts +0 -473
  32. package/src/cel/cli/verify.ts +0 -249
  33. package/src/cel/hash.ts +0 -71
  34. package/src/cel/index.ts +0 -16
  35. package/src/cel/layers/BtcoCelManager.ts +0 -408
  36. package/src/cel/layers/PeerCelManager.ts +0 -371
  37. package/src/cel/layers/WebVHCelManager.ts +0 -361
  38. package/src/cel/layers/index.ts +0 -27
  39. package/src/cel/serialization/cbor.ts +0 -189
  40. package/src/cel/serialization/index.ts +0 -10
  41. package/src/cel/serialization/json.ts +0 -209
  42. package/src/cel/types.ts +0 -160
  43. package/src/cel/witnesses/BitcoinWitness.ts +0 -184
  44. package/src/cel/witnesses/HttpWitness.ts +0 -241
  45. package/src/cel/witnesses/WitnessService.ts +0 -51
  46. package/src/cel/witnesses/index.ts +0 -11
  47. package/src/contexts/credentials-v1.json +0 -237
  48. package/src/contexts/credentials-v2-examples.json +0 -5
  49. package/src/contexts/credentials-v2.json +0 -340
  50. package/src/contexts/credentials.json +0 -237
  51. package/src/contexts/data-integrity-v2.json +0 -81
  52. package/src/contexts/dids.json +0 -58
  53. package/src/contexts/ed255192020.json +0 -93
  54. package/src/contexts/ordinals-plus.json +0 -23
  55. package/src/contexts/originals.json +0 -22
  56. package/src/core/OriginalsSDK.ts +0 -420
  57. package/src/crypto/Multikey.ts +0 -194
  58. package/src/crypto/Signer.ts +0 -262
  59. package/src/crypto/noble-init.ts +0 -138
  60. package/src/did/BtcoDidResolver.ts +0 -231
  61. package/src/did/DIDManager.ts +0 -705
  62. package/src/did/Ed25519Verifier.ts +0 -68
  63. package/src/did/KeyManager.ts +0 -239
  64. package/src/did/WebVHManager.ts +0 -499
  65. package/src/did/createBtcoDidDocument.ts +0 -60
  66. package/src/did/providers/OrdinalsClientProviderAdapter.ts +0 -68
  67. package/src/events/EventEmitter.ts +0 -222
  68. package/src/events/index.ts +0 -19
  69. package/src/events/types.ts +0 -331
  70. package/src/examples/basic-usage.ts +0 -78
  71. package/src/examples/create-module-original.ts +0 -435
  72. package/src/examples/full-lifecycle-flow.ts +0 -514
  73. package/src/examples/run.ts +0 -60
  74. package/src/index.ts +0 -204
  75. package/src/kinds/KindRegistry.ts +0 -320
  76. package/src/kinds/index.ts +0 -74
  77. package/src/kinds/types.ts +0 -470
  78. package/src/kinds/validators/AgentValidator.ts +0 -257
  79. package/src/kinds/validators/AppValidator.ts +0 -211
  80. package/src/kinds/validators/DatasetValidator.ts +0 -242
  81. package/src/kinds/validators/DocumentValidator.ts +0 -311
  82. package/src/kinds/validators/MediaValidator.ts +0 -269
  83. package/src/kinds/validators/ModuleValidator.ts +0 -225
  84. package/src/kinds/validators/base.ts +0 -276
  85. package/src/kinds/validators/index.ts +0 -12
  86. package/src/lifecycle/BatchOperations.ts +0 -381
  87. package/src/lifecycle/LifecycleManager.ts +0 -2156
  88. package/src/lifecycle/OriginalsAsset.ts +0 -524
  89. package/src/lifecycle/ProvenanceQuery.ts +0 -280
  90. package/src/lifecycle/ResourceVersioning.ts +0 -163
  91. package/src/migration/MigrationManager.ts +0 -587
  92. package/src/migration/audit/AuditLogger.ts +0 -176
  93. package/src/migration/checkpoint/CheckpointManager.ts +0 -112
  94. package/src/migration/checkpoint/CheckpointStorage.ts +0 -101
  95. package/src/migration/index.ts +0 -33
  96. package/src/migration/operations/BaseMigration.ts +0 -126
  97. package/src/migration/operations/PeerToBtcoMigration.ts +0 -105
  98. package/src/migration/operations/PeerToWebvhMigration.ts +0 -62
  99. package/src/migration/operations/WebvhToBtcoMigration.ts +0 -105
  100. package/src/migration/rollback/RollbackManager.ts +0 -170
  101. package/src/migration/state/StateMachine.ts +0 -92
  102. package/src/migration/state/StateTracker.ts +0 -156
  103. package/src/migration/types.ts +0 -356
  104. package/src/migration/validation/BitcoinValidator.ts +0 -107
  105. package/src/migration/validation/CredentialValidator.ts +0 -62
  106. package/src/migration/validation/DIDCompatibilityValidator.ts +0 -151
  107. package/src/migration/validation/LifecycleValidator.ts +0 -64
  108. package/src/migration/validation/StorageValidator.ts +0 -79
  109. package/src/migration/validation/ValidationPipeline.ts +0 -213
  110. package/src/resources/ResourceManager.ts +0 -655
  111. package/src/resources/index.ts +0 -21
  112. package/src/resources/types.ts +0 -202
  113. package/src/storage/LocalStorageAdapter.ts +0 -64
  114. package/src/storage/MemoryStorageAdapter.ts +0 -29
  115. package/src/storage/StorageAdapter.ts +0 -25
  116. package/src/storage/index.ts +0 -3
  117. package/src/types/bitcoin.ts +0 -98
  118. package/src/types/common.ts +0 -92
  119. package/src/types/credentials.ts +0 -89
  120. package/src/types/did.ts +0 -31
  121. package/src/types/external-shims.d.ts +0 -53
  122. package/src/types/index.ts +0 -7
  123. package/src/types/network.ts +0 -178
  124. package/src/utils/EventLogger.ts +0 -298
  125. package/src/utils/Logger.ts +0 -324
  126. package/src/utils/MetricsCollector.ts +0 -358
  127. package/src/utils/bitcoin-address.ts +0 -132
  128. package/src/utils/cbor.ts +0 -31
  129. package/src/utils/encoding.ts +0 -135
  130. package/src/utils/hash.ts +0 -12
  131. package/src/utils/retry.ts +0 -46
  132. package/src/utils/satoshi-validation.ts +0 -196
  133. package/src/utils/serialization.ts +0 -102
  134. package/src/utils/telemetry.ts +0 -44
  135. package/src/utils/validation.ts +0 -123
  136. package/src/vc/CredentialManager.ts +0 -955
  137. package/src/vc/Issuer.ts +0 -105
  138. package/src/vc/Verifier.ts +0 -54
  139. package/src/vc/cryptosuites/bbs.ts +0 -253
  140. package/src/vc/cryptosuites/bbsSimple.ts +0 -21
  141. package/src/vc/cryptosuites/eddsa.ts +0 -99
  142. package/src/vc/documentLoader.ts +0 -81
  143. package/src/vc/proofs/data-integrity.ts +0 -33
  144. package/src/vc/utils/jsonld.ts +0 -18
@@ -1,58 +0,0 @@
1
- {
2
- "@context": {
3
- "@protected": true,
4
- "id": "@id",
5
- "type": "@type",
6
-
7
- "alsoKnownAs": {
8
- "@id": "https://www.w3.org/ns/activitystreams#alsoKnownAs",
9
- "@type": "@id"
10
- },
11
- "assertionMethod": {
12
- "@id": "https://w3id.org/security#assertionMethod",
13
- "@type": "@id",
14
- "@container": "@set"
15
- },
16
- "authentication": {
17
- "@id": "https://w3id.org/security#authenticationMethod",
18
- "@type": "@id",
19
- "@container": "@set"
20
- },
21
- "capabilityDelegation": {
22
- "@id": "https://w3id.org/security#capabilityDelegationMethod",
23
- "@type": "@id",
24
- "@container": "@set"
25
- },
26
- "capabilityInvocation": {
27
- "@id": "https://w3id.org/security#capabilityInvocationMethod",
28
- "@type": "@id",
29
- "@container": "@set"
30
- },
31
- "controller": {
32
- "@id": "https://w3id.org/security#controller",
33
- "@type": "@id"
34
- },
35
- "keyAgreement": {
36
- "@id": "https://w3id.org/security#keyAgreementMethod",
37
- "@type": "@id",
38
- "@container": "@set"
39
- },
40
- "service": {
41
- "@id": "https://www.w3.org/ns/did#service",
42
- "@type": "@id",
43
- "@context": {
44
- "@protected": true,
45
- "id": "@id",
46
- "type": "@type",
47
- "serviceEndpoint": {
48
- "@id": "https://www.w3.org/ns/did#serviceEndpoint",
49
- "@type": "@id"
50
- }
51
- }
52
- },
53
- "verificationMethod": {
54
- "@id": "https://w3id.org/security#verificationMethod",
55
- "@type": "@id"
56
- }
57
- }
58
- }
@@ -1,93 +0,0 @@
1
- {
2
- "@context": {
3
- "id": "@id",
4
- "type": "@type",
5
- "@protected": true,
6
- "proof": {
7
- "@id": "https://w3id.org/security#proof",
8
- "@type": "@id",
9
- "@container": "@graph"
10
- },
11
- "Ed25519VerificationKey2020": {
12
- "@id": "https://w3id.org/security#Ed25519VerificationKey2020",
13
- "@context": {
14
- "@protected": true,
15
- "id": "@id",
16
- "type": "@type",
17
- "controller": {
18
- "@id": "https://w3id.org/security#controller",
19
- "@type": "@id"
20
- },
21
- "revoked": {
22
- "@id": "https://w3id.org/security#revoked",
23
- "@type": "http://www.w3.org/2001/XMLSchema#dateTime"
24
- },
25
- "publicKeyMultibase": {
26
- "@id": "https://w3id.org/security#publicKeyMultibase",
27
- "@type": "https://w3id.org/security#multibase"
28
- }
29
- }
30
- },
31
- "Ed25519Signature2020": {
32
- "@id": "https://w3id.org/security#Ed25519Signature2020",
33
- "@context": {
34
- "@protected": true,
35
- "id": "@id",
36
- "type": "@type",
37
- "challenge": "https://w3id.org/security#challenge",
38
- "created": {
39
- "@id": "http://purl.org/dc/terms/created",
40
- "@type": "http://www.w3.org/2001/XMLSchema#dateTime"
41
- },
42
- "domain": "https://w3id.org/security#domain",
43
- "expires": {
44
- "@id": "https://w3id.org/security#expiration",
45
- "@type": "http://www.w3.org/2001/XMLSchema#dateTime"
46
- },
47
- "nonce": "https://w3id.org/security#nonce",
48
- "proofPurpose": {
49
- "@id": "https://w3id.org/security#proofPurpose",
50
- "@type": "@vocab",
51
- "@context": {
52
- "@protected": true,
53
- "id": "@id",
54
- "type": "@type",
55
- "assertionMethod": {
56
- "@id": "https://w3id.org/security#assertionMethod",
57
- "@type": "@id",
58
- "@container": "@set"
59
- },
60
- "authentication": {
61
- "@id": "https://w3id.org/security#authenticationMethod",
62
- "@type": "@id",
63
- "@container": "@set"
64
- },
65
- "capabilityInvocation": {
66
- "@id": "https://w3id.org/security#capabilityInvocationMethod",
67
- "@type": "@id",
68
- "@container": "@set"
69
- },
70
- "capabilityDelegation": {
71
- "@id": "https://w3id.org/security#capabilityDelegationMethod",
72
- "@type": "@id",
73
- "@container": "@set"
74
- },
75
- "keyAgreement": {
76
- "@id": "https://w3id.org/security#keyAgreementMethod",
77
- "@type": "@id",
78
- "@container": "@set"
79
- }
80
- }
81
- },
82
- "proofValue": {
83
- "@id": "https://w3id.org/security#proofValue",
84
- "@type": "https://w3id.org/security#multibase"
85
- },
86
- "verificationMethod": {
87
- "@id": "https://w3id.org/security#verificationMethod",
88
- "@type": "@id"
89
- }
90
- }
91
- }
92
- }
93
- }
@@ -1,23 +0,0 @@
1
- {
2
- "@context": {
3
- "@version": 1.1,
4
- "id": "@id",
5
- "type": "@type",
6
- "VerifiableCollectible": "https://ordinals.plus/vocab/v1#VerifiableCollectible",
7
- "VerifiableCollectibleCredential": "https://ordinals.plus/vocab/v1#VerifiableCollectibleCredential",
8
- "VerifiableCollectibleTrait": "https://ordinals.plus/vocab/v1#VerifiableCollectibleTrait",
9
- "VerifiableCollectibleTraitCredential": "https://ordinals.plus/vocab/v1#VerifiableCollectibleTraitCredential",
10
- "CuratedCollection": "https://ordinals.plus/vocab/v1#CuratedCollection",
11
- "CuratedCollectionCredential": "https://ordinals.plus/vocab/v1#CuratedCollectionCredential",
12
- "attributes": {
13
- "@id": "https://ordinals.plus/vocab/v1#attributes",
14
- "@container": "@set"
15
- },
16
- "items": {
17
- "@id": "https://ordinals.plus/vocab/v1#items",
18
- "@container": "@set"
19
- },
20
- "traitType": "https://ordinals.plus/vocab/v1#traitType",
21
- "value": "https://ordinals.plus/vocab/v1#traitValue"
22
- }
23
- }
@@ -1,22 +0,0 @@
1
- {
2
- "@context": {
3
- "@version": 1.1,
4
- "type": "@type",
5
- "id": "@id",
6
- "Originals": "https://originals.build",
7
- "OriginalsBundle": "Originals:OriginalsBundle",
8
- "ResourceCreated": "Originals:ResourceCreated",
9
- "ResourceUpdated": "Originals:ResourceUpdated",
10
- "ResourceMigrated": "Originals:ResourceMigrated",
11
- "attributes": {
12
- "@id": "Originals:attributes",
13
- "@container": "@set"
14
- },
15
- "resources": "Originals:resources",
16
- "verifiableCredentials": "Originals:verifiableCredentials",
17
- "content": "Originals:content",
18
- "trait_type": "Originals:trait_type",
19
- "display_type": "Originals:display_type",
20
- "value": "Originals:value"
21
- }
22
- }
@@ -1,420 +0,0 @@
1
- import { DIDManager } from '../did/DIDManager';
2
- import { CredentialManager } from '../vc/CredentialManager';
3
- import { LifecycleManager } from '../lifecycle/LifecycleManager';
4
- import { BitcoinManager } from '../bitcoin/BitcoinManager';
5
- import { OriginalsConfig, KeyStore, ExternalSigner, ExternalVerifier } from '../types';
6
- import { DIDDocument, VerificationMethod, ServiceEndpoint } from '../types/did';
7
- import { DEFAULT_WEBVH_NETWORK } from '../types/network';
8
- import { emitTelemetry, StructuredError } from '../utils/telemetry';
9
- import { Logger } from '../utils/Logger';
10
- import { MetricsCollector } from '../utils/MetricsCollector';
11
- import { EventLogger } from '../utils/EventLogger';
12
- import { createDID } from 'didwebvh-ts';
13
-
14
- // Type for DID log (from didwebvh-ts)
15
- interface DIDLogEntry {
16
- versionId: string;
17
- versionTime: string;
18
- parameters: Record<string, unknown>;
19
- state: Record<string, unknown>;
20
- proof?: Record<string, unknown>[];
21
- }
22
-
23
- type DIDLog = DIDLogEntry[];
24
-
25
- // Type for DID resolution metadata (from didwebvh-ts)
26
- interface DIDResolutionMeta {
27
- versionId: string;
28
- created: string;
29
- updated: string;
30
- previousLogEntryHash?: string;
31
- updateKeys: string[];
32
- scid: string;
33
- prerotation: boolean;
34
- portable: boolean;
35
- nextKeyHashes: string[];
36
- deactivated: boolean;
37
- witness?: unknown;
38
- watchers?: string[] | null;
39
- error?: string;
40
- problemDetails?: unknown;
41
- latestVersionId?: string;
42
- }
43
-
44
- // Base result type for Original creation/update
45
- export interface OriginalResult {
46
- did: string;
47
- doc: DIDDocument;
48
- log: DIDLog;
49
- meta: DIDResolutionMeta;
50
- }
51
-
52
- // DID-based Original creation options
53
- export interface CreateDIDOriginalOptions {
54
- type: 'did';
55
- domain: string;
56
- signer: ExternalSigner;
57
- verifier?: ExternalVerifier;
58
- updateKeys: string[];
59
- verificationMethods: VerificationMethod[];
60
- paths?: string[];
61
- controller?: string;
62
- context?: string | string[] | object | object[];
63
- alsoKnownAs?: string[];
64
- portable?: boolean;
65
- nextKeyHashes?: string[];
66
- authentication?: string[];
67
- assertionMethod?: string[];
68
- keyAgreement?: string[];
69
- services?: ServiceEndpoint[];
70
- }
71
-
72
- // DID-based Original update options
73
- export interface UpdateDIDOriginalOptions {
74
- type: 'did';
75
- log: DIDLog;
76
- signer: ExternalSigner;
77
- verifier?: ExternalVerifier;
78
- updateKeys?: string[];
79
- verificationMethods?: VerificationMethod[];
80
- services?: ServiceEndpoint[];
81
- controller?: string;
82
- context?: string | string[] | object | object[];
83
- alsoKnownAs?: string[];
84
- portable?: boolean;
85
- nextKeyHashes?: string[];
86
- authentication?: string[];
87
- assertionMethod?: string[];
88
- keyAgreement?: string[];
89
- domain?: string;
90
- }
91
-
92
- // Union type for all Original creation options
93
- export type CreateOriginalOptions = CreateDIDOriginalOptions;
94
-
95
- // Union type for all Original update options
96
- export type UpdateOriginalOptions = UpdateDIDOriginalOptions;
97
-
98
- export interface OriginalsSDKOptions extends Partial<OriginalsConfig> {
99
- keyStore?: KeyStore;
100
- }
101
-
102
- export class OriginalsSDK {
103
- public readonly did: DIDManager;
104
- public readonly credentials: CredentialManager;
105
- public readonly lifecycle: LifecycleManager;
106
- public readonly bitcoin: BitcoinManager;
107
- public readonly logger: Logger;
108
- public readonly metrics: MetricsCollector;
109
- private eventLogger: EventLogger;
110
- private config: OriginalsConfig;
111
-
112
- constructor(config: OriginalsConfig, keyStore?: KeyStore) {
113
- // Input validation
114
- if (!config || typeof config !== 'object') {
115
- throw new Error('Configuration object is required');
116
- }
117
- if (!config.network || !['mainnet', 'regtest', 'signet'].includes(config.network)) {
118
- throw new Error('Invalid network: must be mainnet, regtest, or signet');
119
- }
120
- if (!config.defaultKeyType || !['ES256K', 'Ed25519', 'ES256'].includes(config.defaultKeyType)) {
121
- throw new Error('Invalid defaultKeyType: must be ES256K, Ed25519, or ES256');
122
- }
123
-
124
- this.config = config;
125
-
126
- // Initialize logger and metrics
127
- this.logger = new Logger('SDK', config);
128
- this.metrics = new MetricsCollector();
129
- this.eventLogger = new EventLogger(this.logger.child('Events'), this.metrics);
130
-
131
- // Log SDK initialization
132
- this.logger.info('Initializing Originals SDK', {
133
- network: config.network,
134
- keyType: config.defaultKeyType
135
- });
136
-
137
- emitTelemetry(config.telemetry, { name: 'sdk.init', attributes: { network: config.network } });
138
-
139
- // Initialize managers
140
- this.did = new DIDManager(config);
141
- this.credentials = new CredentialManager(config, this.did);
142
- this.lifecycle = new LifecycleManager(config, this.did, this.credentials, undefined, keyStore);
143
- this.bitcoin = new BitcoinManager(config);
144
-
145
- // Set up event logging integration
146
- this.setupEventLogging();
147
-
148
- this.logger.info('SDK initialized successfully');
149
- }
150
-
151
- /**
152
- * Set up event logging integration
153
- */
154
- private setupEventLogging(): void {
155
- // Configure event logging from config
156
- if (this.config.logging?.eventLogging) {
157
- this.eventLogger.configureEventLogging(this.config.logging.eventLogging);
158
- }
159
-
160
- // Subscribe to lifecycle events
161
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
162
- this.eventLogger.subscribeToEvents((this.lifecycle as any).eventEmitter);
163
- }
164
-
165
-
166
- /**
167
- * Validates that the SDK is properly configured for Bitcoin operations.
168
- * Throws a StructuredError if ordinalsProvider is not configured.
169
- *
170
- * @throws {StructuredError} When ordinalsProvider is not configured
171
- */
172
- validateBitcoinConfig(): void {
173
- if (!this.config.ordinalsProvider) {
174
- throw new StructuredError(
175
- 'ORD_PROVIDER_REQUIRED',
176
- 'Bitcoin operations require an ordinalsProvider to be configured. ' +
177
- 'Please provide an ordinalsProvider when creating the SDK. ' +
178
- 'See README.md for configuration examples.'
179
- );
180
- }
181
- }
182
-
183
- static create(options?: OriginalsSDKOptions): OriginalsSDK {
184
- const { keyStore, ...configOptions } = options || {};
185
- const defaultConfig: OriginalsConfig = {
186
- network: 'mainnet',
187
- defaultKeyType: 'ES256K',
188
- enableLogging: false,
189
- webvhNetwork: DEFAULT_WEBVH_NETWORK, // Default to 'pichu' (production)
190
- };
191
- return new OriginalsSDK({ ...defaultConfig, ...configOptions }, keyStore);
192
- }
193
-
194
- /**
195
- * Prepare data for signing using didwebvh-ts's canonical approach
196
- * This is a public static helper method that wraps didwebvh-ts's prepareDataForSigning
197
- * to ensure didwebvh-ts is only imported within the SDK
198
- */
199
- static async prepareDIDDataForSigning(
200
- document: Record<string, unknown>,
201
- proof: Record<string, unknown>
202
- ): Promise<Uint8Array> {
203
- // Dynamically import didwebvh-ts to avoid module resolution issues
204
- const mod = await import('didwebvh-ts') as unknown as {
205
- prepareDataForSigning: (
206
- document: Record<string, unknown>,
207
- proof: Record<string, unknown>
208
- ) => Promise<Uint8Array>;
209
- };
210
-
211
- const { prepareDataForSigning } = mod;
212
-
213
- // Runtime validation
214
- if (typeof prepareDataForSigning !== 'function') {
215
- throw new Error('Failed to load didwebvh-ts: prepareDataForSigning is not a function');
216
- }
217
-
218
- return prepareDataForSigning(document, proof);
219
- }
220
-
221
- /**
222
- * Verify a DID signature using Ed25519
223
- * This is a public static helper method that provides browser-compatible Ed25519 verification
224
- * Works with Uint8Array inputs (no Buffer required)
225
- *
226
- * @param signature - The signature bytes (Uint8Array)
227
- * @param message - The message bytes that were signed (Uint8Array)
228
- * @param publicKey - The public key bytes (Uint8Array, should be 32 bytes for Ed25519)
229
- * @returns True if the signature is valid
230
- */
231
- static async verifyDIDSignature(
232
- signature: Uint8Array,
233
- message: Uint8Array,
234
- publicKey: Uint8Array
235
- ): Promise<boolean> {
236
- // Dynamically import @noble/ed25519 to avoid module resolution issues
237
- const ed25519Mod = await import('@noble/ed25519');
238
-
239
- // Ed25519 public keys must be exactly 32 bytes
240
- // Some keys may have a version byte prefix, so remove it if present
241
- let ed25519PublicKey = publicKey;
242
- if (publicKey.length === 33) {
243
- ed25519PublicKey = publicKey.slice(1);
244
- } else if (publicKey.length !== 32) {
245
- throw new Error(`Invalid Ed25519 public key length: ${publicKey.length} (expected 32 bytes)`);
246
- }
247
-
248
- // Verify using @noble/ed25519 with Uint8Array (browser-compatible)
249
- // ed25519.verifyAsync accepts Uint8Array directly
250
- try {
251
- return await ed25519Mod.verifyAsync(signature, message, ed25519PublicKey);
252
- } catch (error) {
253
- // Verification failed or error occurred
254
- return false;
255
- }
256
- }
257
-
258
- /**
259
- * Create a new Original
260
- * This is a convenience proxy that routes to the appropriate specialized creation method.
261
- * Currently proxies to createDIDOriginal(), but can be extended for other Original types.
262
- *
263
- * @param options - Creation options (discriminated union by type)
264
- * @returns Created DID, document, log, and metadata
265
- */
266
- static async createOriginal(options: CreateOriginalOptions): Promise<OriginalResult> {
267
- // Route based on type discriminator
268
- switch (options.type) {
269
- case 'did':
270
- return OriginalsSDK.createDIDOriginal(options);
271
- default:
272
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
273
- throw new Error(`Unsupported Original type: ${options.type}`);
274
- }
275
- }
276
-
277
- /**
278
- * Create a new DID-based Original (DID document/log)
279
- * This wraps didwebvh-ts's createDID function to ensure didwebvh-ts is only imported within the SDK.
280
- *
281
- * A DID-based Original represents a decentralized identity that can be used as the foundation
282
- * for other Originals (e.g., asset Originals, credential Originals, etc.).
283
- *
284
- * @param options - Creation options matching didwebvh-ts createDID interface
285
- * @returns Created DID, document, log, and metadata
286
- */
287
- static async createDIDOriginal(options: CreateDIDOriginalOptions): Promise<OriginalResult> {
288
- // Dynamically import didwebvh-ts to avoid module resolution issues
289
- // const mod = await import('didwebvh-ts') as unknown as {
290
- // createDID: (options: Record<string, unknown>) => Promise<{
291
- // did: string;
292
- // doc: Record<string, unknown>;
293
- // log: DIDLog;
294
- // meta: DIDResolutionMeta;
295
- // }>;
296
- // };
297
-
298
- // const { createDID } = mod;
299
-
300
- // Runtime validation
301
- if (typeof createDID !== 'function') {
302
- throw new Error('Failed to load didwebvh-ts: createDID is not a function');
303
- }
304
-
305
- // Create the DID using didwebvh-ts
306
- const result = await createDID({
307
- domain: options.domain,
308
- signer: options.signer,
309
- verifier: options.verifier,
310
- paths: options.paths,
311
- updateKeys: options.updateKeys,
312
- verificationMethods: options.verificationMethods,
313
- context: options.context || [
314
- 'https://www.w3.org/ns/did/v1',
315
- 'https://w3id.org/security/multikey/v1'
316
- ],
317
- });
318
-
319
- return {
320
- did: result.did,
321
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
322
- doc: result.doc,
323
- log: result.log as unknown as DIDLog,
324
- meta: result.meta
325
- };
326
- }
327
-
328
- /**
329
- * Update an existing Original
330
- * This is a convenience proxy that routes to the appropriate specialized update method.
331
- * Currently proxies to updateDIDOriginal(), but can be extended for other Original types.
332
- *
333
- * @param options - Update options (discriminated union by type)
334
- * @returns Updated DID, document, log, and metadata
335
- */
336
- static async updateOriginal(options: UpdateOriginalOptions): Promise<OriginalResult> {
337
- // Route based on type discriminator
338
- switch (options.type) {
339
- case 'did':
340
- return OriginalsSDK.updateDIDOriginal(options);
341
- default: {
342
- // TypeScript exhaustiveness check
343
- const _exhaustive: never = options as never;
344
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
345
- throw new Error(`Unsupported Original type: ${(_exhaustive as any).type}`);
346
- }
347
- }
348
- }
349
-
350
- /**
351
- * Update an existing DID-based Original (DID document/log)
352
- * This wraps didwebvh-ts's updateDID function to ensure didwebvh-ts is only imported within the SDK.
353
- *
354
- * @param options - Update options matching didwebvh-ts updateDID interface
355
- * @returns Updated DID, document, log, and metadata
356
- */
357
- static async updateDIDOriginal(options: UpdateDIDOriginalOptions): Promise<OriginalResult> {
358
- // Dynamically import didwebvh-ts to avoid module resolution issues
359
- const mod = await import('didwebvh-ts') as unknown as {
360
- updateDID: (options: Record<string, unknown>) => Promise<{
361
- did: string;
362
- doc: Record<string, unknown>;
363
- log: DIDLog;
364
- meta: DIDResolutionMeta;
365
- }>;
366
- };
367
-
368
- const { updateDID } = mod;
369
-
370
- // Runtime validation
371
- if (typeof updateDID !== 'function') {
372
- throw new Error('Failed to load didwebvh-ts: updateDID is not a function');
373
- }
374
-
375
- // Prepare options for updateDID
376
- const updateOptions: Record<string, unknown> = {
377
- log: options.log,
378
- signer: options.signer,
379
- verifier: options.verifier || options.signer, // Use signer as verifier if not provided
380
- };
381
-
382
- // Add optional parameters
383
- if (options.updateKeys !== undefined) updateOptions.updateKeys = options.updateKeys;
384
- if (options.verificationMethods !== undefined) updateOptions.verificationMethods = options.verificationMethods;
385
- if (options.services !== undefined) updateOptions.services = options.services;
386
- if (options.controller !== undefined) updateOptions.controller = options.controller;
387
- if (options.context !== undefined) updateOptions.context = options.context;
388
- if (options.alsoKnownAs !== undefined) updateOptions.alsoKnownAs = options.alsoKnownAs;
389
- if (options.portable !== undefined) updateOptions.portable = options.portable;
390
- if (options.nextKeyHashes !== undefined) updateOptions.nextKeyHashes = options.nextKeyHashes;
391
- if (options.authentication !== undefined) updateOptions.authentication = options.authentication;
392
- if (options.assertionMethod !== undefined) updateOptions.assertionMethod = options.assertionMethod;
393
- if (options.keyAgreement !== undefined) updateOptions.keyAgreement = options.keyAgreement;
394
- if (options.domain !== undefined) updateOptions.domain = options.domain;
395
-
396
- // Update the DID using didwebvh-ts
397
- const result = await updateDID(updateOptions);
398
-
399
- // Extract DID from the log if not returned directly
400
- let did: string;
401
- if (result.did) {
402
- did = result.did;
403
- } else if (result.log && result.log.length > 0) {
404
- // Extract DID from the document in the log
405
- const latestDoc = result.log[result.log.length - 1]?.state as unknown as DIDDocument | undefined;
406
- did = latestDoc?.id || '';
407
- } else {
408
- throw new Error('Cannot determine DID from update result');
409
- }
410
-
411
- return {
412
- did,
413
- doc: result.doc as unknown as DIDDocument,
414
- log: result.log,
415
- meta: result.meta
416
- };
417
- }
418
- }
419
-
420
-