@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
@@ -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,416 +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
- this.eventLogger.subscribeToEvents((this.lifecycle as any).eventEmitter);
162
- }
163
-
164
-
165
- /**
166
- * Validates that the SDK is properly configured for Bitcoin operations.
167
- * Throws a StructuredError if ordinalsProvider is not configured.
168
- *
169
- * @throws {StructuredError} When ordinalsProvider is not configured
170
- */
171
- validateBitcoinConfig(): void {
172
- if (!this.config.ordinalsProvider) {
173
- throw new StructuredError(
174
- 'ORD_PROVIDER_REQUIRED',
175
- 'Bitcoin operations require an ordinalsProvider to be configured. ' +
176
- 'Please provide an ordinalsProvider when creating the SDK. ' +
177
- 'See README.md for configuration examples.'
178
- );
179
- }
180
- }
181
-
182
- static create(options?: OriginalsSDKOptions): OriginalsSDK {
183
- const { keyStore, ...configOptions } = options || {};
184
- const defaultConfig: OriginalsConfig = {
185
- network: 'mainnet',
186
- defaultKeyType: 'ES256K',
187
- enableLogging: false,
188
- webvhNetwork: DEFAULT_WEBVH_NETWORK, // Default to 'pichu' (production)
189
- };
190
- return new OriginalsSDK({ ...defaultConfig, ...configOptions }, keyStore);
191
- }
192
-
193
- /**
194
- * Prepare data for signing using didwebvh-ts's canonical approach
195
- * This is a public static helper method that wraps didwebvh-ts's prepareDataForSigning
196
- * to ensure didwebvh-ts is only imported within the SDK
197
- */
198
- static async prepareDIDDataForSigning(
199
- document: Record<string, unknown>,
200
- proof: Record<string, unknown>
201
- ): Promise<Uint8Array> {
202
- // Dynamically import didwebvh-ts to avoid module resolution issues
203
- const mod = await import('didwebvh-ts') as unknown as {
204
- prepareDataForSigning: (
205
- document: Record<string, unknown>,
206
- proof: Record<string, unknown>
207
- ) => Promise<Uint8Array>;
208
- };
209
-
210
- const { prepareDataForSigning } = mod;
211
-
212
- // Runtime validation
213
- if (typeof prepareDataForSigning !== 'function') {
214
- throw new Error('Failed to load didwebvh-ts: prepareDataForSigning is not a function');
215
- }
216
-
217
- return prepareDataForSigning(document, proof);
218
- }
219
-
220
- /**
221
- * Verify a DID signature using Ed25519
222
- * This is a public static helper method that provides browser-compatible Ed25519 verification
223
- * Works with Uint8Array inputs (no Buffer required)
224
- *
225
- * @param signature - The signature bytes (Uint8Array)
226
- * @param message - The message bytes that were signed (Uint8Array)
227
- * @param publicKey - The public key bytes (Uint8Array, should be 32 bytes for Ed25519)
228
- * @returns True if the signature is valid
229
- */
230
- static async verifyDIDSignature(
231
- signature: Uint8Array,
232
- message: Uint8Array,
233
- publicKey: Uint8Array
234
- ): Promise<boolean> {
235
- // Dynamically import @noble/ed25519 to avoid module resolution issues
236
- const ed25519Mod = await import('@noble/ed25519');
237
-
238
- // Ed25519 public keys must be exactly 32 bytes
239
- // Some keys may have a version byte prefix, so remove it if present
240
- let ed25519PublicKey = publicKey;
241
- if (publicKey.length === 33) {
242
- ed25519PublicKey = publicKey.slice(1);
243
- } else if (publicKey.length !== 32) {
244
- throw new Error(`Invalid Ed25519 public key length: ${publicKey.length} (expected 32 bytes)`);
245
- }
246
-
247
- // Verify using @noble/ed25519 with Uint8Array (browser-compatible)
248
- // ed25519.verifyAsync accepts Uint8Array directly
249
- try {
250
- return await ed25519Mod.verifyAsync(signature, message, ed25519PublicKey);
251
- } catch (error) {
252
- // Verification failed or error occurred
253
- return false;
254
- }
255
- }
256
-
257
- /**
258
- * Create a new Original
259
- * This is a convenience proxy that routes to the appropriate specialized creation method.
260
- * Currently proxies to createDIDOriginal(), but can be extended for other Original types.
261
- *
262
- * @param options - Creation options (discriminated union by type)
263
- * @returns Created DID, document, log, and metadata
264
- */
265
- static async createOriginal(options: CreateOriginalOptions): Promise<OriginalResult> {
266
- // Route based on type discriminator
267
- switch (options.type) {
268
- case 'did':
269
- return OriginalsSDK.createDIDOriginal(options);
270
- default:
271
- // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
272
- throw new Error(`Unsupported Original type: ${options.type}`);
273
- }
274
- }
275
-
276
- /**
277
- * Create a new DID-based Original (DID document/log)
278
- * This wraps didwebvh-ts's createDID function to ensure didwebvh-ts is only imported within the SDK.
279
- *
280
- * A DID-based Original represents a decentralized identity that can be used as the foundation
281
- * for other Originals (e.g., asset Originals, credential Originals, etc.).
282
- *
283
- * @param options - Creation options matching didwebvh-ts createDID interface
284
- * @returns Created DID, document, log, and metadata
285
- */
286
- static async createDIDOriginal(options: CreateDIDOriginalOptions): Promise<OriginalResult> {
287
- // Dynamically import didwebvh-ts to avoid module resolution issues
288
- // const mod = await import('didwebvh-ts') as unknown as {
289
- // createDID: (options: Record<string, unknown>) => Promise<{
290
- // did: string;
291
- // doc: Record<string, unknown>;
292
- // log: DIDLog;
293
- // meta: DIDResolutionMeta;
294
- // }>;
295
- // };
296
-
297
- // const { createDID } = mod;
298
-
299
- // Runtime validation
300
- if (typeof createDID !== 'function') {
301
- throw new Error('Failed to load didwebvh-ts: createDID is not a function');
302
- }
303
-
304
- // Create the DID using didwebvh-ts
305
- const result = await createDID({
306
- domain: options.domain,
307
- signer: options.signer,
308
- verifier: options.verifier,
309
- paths: options.paths,
310
- updateKeys: options.updateKeys,
311
- verificationMethods: options.verificationMethods,
312
- context: options.context || [
313
- 'https://www.w3.org/ns/did/v1',
314
- 'https://w3id.org/security/multikey/v1'
315
- ],
316
- });
317
-
318
- return {
319
- did: result.did,
320
- doc: result.doc,
321
- log: result.log as unknown as DIDLog,
322
- meta: result.meta
323
- };
324
- }
325
-
326
- /**
327
- * Update an existing Original
328
- * This is a convenience proxy that routes to the appropriate specialized update method.
329
- * Currently proxies to updateDIDOriginal(), but can be extended for other Original types.
330
- *
331
- * @param options - Update options (discriminated union by type)
332
- * @returns Updated DID, document, log, and metadata
333
- */
334
- static async updateOriginal(options: UpdateOriginalOptions): Promise<OriginalResult> {
335
- // Route based on type discriminator
336
- switch (options.type) {
337
- case 'did':
338
- return OriginalsSDK.updateDIDOriginal(options);
339
- default:
340
- // TypeScript exhaustiveness check
341
- const _exhaustive: never = options as never;
342
- throw new Error(`Unsupported Original type: ${(_exhaustive as any).type}`);
343
- }
344
- }
345
-
346
- /**
347
- * Update an existing DID-based Original (DID document/log)
348
- * This wraps didwebvh-ts's updateDID function to ensure didwebvh-ts is only imported within the SDK.
349
- *
350
- * @param options - Update options matching didwebvh-ts updateDID interface
351
- * @returns Updated DID, document, log, and metadata
352
- */
353
- static async updateDIDOriginal(options: UpdateDIDOriginalOptions): Promise<OriginalResult> {
354
- // Dynamically import didwebvh-ts to avoid module resolution issues
355
- const mod = await import('didwebvh-ts') as unknown as {
356
- updateDID: (options: Record<string, unknown>) => Promise<{
357
- did: string;
358
- doc: Record<string, unknown>;
359
- log: DIDLog;
360
- meta: DIDResolutionMeta;
361
- }>;
362
- };
363
-
364
- const { updateDID } = mod;
365
-
366
- // Runtime validation
367
- if (typeof updateDID !== 'function') {
368
- throw new Error('Failed to load didwebvh-ts: updateDID is not a function');
369
- }
370
-
371
- // Prepare options for updateDID
372
- const updateOptions: Record<string, unknown> = {
373
- log: options.log,
374
- signer: options.signer,
375
- verifier: options.verifier || options.signer, // Use signer as verifier if not provided
376
- };
377
-
378
- // Add optional parameters
379
- if (options.updateKeys !== undefined) updateOptions.updateKeys = options.updateKeys;
380
- if (options.verificationMethods !== undefined) updateOptions.verificationMethods = options.verificationMethods;
381
- if (options.services !== undefined) updateOptions.services = options.services;
382
- if (options.controller !== undefined) updateOptions.controller = options.controller;
383
- if (options.context !== undefined) updateOptions.context = options.context;
384
- if (options.alsoKnownAs !== undefined) updateOptions.alsoKnownAs = options.alsoKnownAs;
385
- if (options.portable !== undefined) updateOptions.portable = options.portable;
386
- if (options.nextKeyHashes !== undefined) updateOptions.nextKeyHashes = options.nextKeyHashes;
387
- if (options.authentication !== undefined) updateOptions.authentication = options.authentication;
388
- if (options.assertionMethod !== undefined) updateOptions.assertionMethod = options.assertionMethod;
389
- if (options.keyAgreement !== undefined) updateOptions.keyAgreement = options.keyAgreement;
390
- if (options.domain !== undefined) updateOptions.domain = options.domain;
391
-
392
- // Update the DID using didwebvh-ts
393
- const result = await updateDID(updateOptions);
394
-
395
- // Extract DID from the log if not returned directly
396
- let did: string;
397
- if (result.did) {
398
- did = result.did;
399
- } else if (result.log && result.log.length > 0) {
400
- // Extract DID from the document in the log
401
- const latestDoc = result.log[result.log.length - 1]?.state as unknown as DIDDocument | undefined;
402
- did = latestDoc?.id || '';
403
- } else {
404
- throw new Error('Cannot determine DID from update result');
405
- }
406
-
407
- return {
408
- did,
409
- doc: result.doc as unknown as DIDDocument,
410
- log: result.log,
411
- meta: result.meta
412
- };
413
- }
414
- }
415
-
416
-