@originals/sdk 1.8.0 → 1.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/utils/hash.js +1 -0
- package/package.json +6 -5
- package/src/adapters/FeeOracleMock.ts +9 -0
- package/src/adapters/index.ts +5 -0
- package/src/adapters/providers/OrdHttpProvider.ts +126 -0
- package/src/adapters/providers/OrdMockProvider.ts +101 -0
- package/src/adapters/types.ts +66 -0
- package/src/bitcoin/BitcoinManager.ts +329 -0
- package/src/bitcoin/BroadcastClient.ts +54 -0
- package/src/bitcoin/OrdinalsClient.ts +120 -0
- package/src/bitcoin/PSBTBuilder.ts +106 -0
- package/src/bitcoin/fee-calculation.ts +38 -0
- package/src/bitcoin/providers/OrdNodeProvider.ts +92 -0
- package/src/bitcoin/providers/OrdinalsProvider.ts +56 -0
- package/src/bitcoin/providers/types.ts +59 -0
- package/src/bitcoin/transactions/commit.ts +465 -0
- package/src/bitcoin/transactions/index.ts +13 -0
- package/src/bitcoin/transfer.ts +43 -0
- package/src/bitcoin/utxo-selection.ts +322 -0
- package/src/bitcoin/utxo.ts +113 -0
- package/src/cel/ExternalReferenceManager.ts +87 -0
- package/src/cel/OriginalsCel.ts +460 -0
- package/src/cel/algorithms/createEventLog.ts +68 -0
- package/src/cel/algorithms/deactivateEventLog.ts +109 -0
- package/src/cel/algorithms/index.ts +11 -0
- package/src/cel/algorithms/updateEventLog.ts +99 -0
- package/src/cel/algorithms/verifyEventLog.ts +306 -0
- package/src/cel/algorithms/witnessEvent.ts +87 -0
- package/src/cel/cli/create.ts +330 -0
- package/src/cel/cli/index.ts +383 -0
- package/src/cel/cli/inspect.ts +549 -0
- package/src/cel/cli/migrate.ts +473 -0
- package/src/cel/cli/verify.ts +249 -0
- package/src/cel/hash.ts +71 -0
- package/src/cel/index.ts +16 -0
- package/src/cel/layers/BtcoCelManager.ts +408 -0
- package/src/cel/layers/PeerCelManager.ts +371 -0
- package/src/cel/layers/WebVHCelManager.ts +361 -0
- package/src/cel/layers/index.ts +27 -0
- package/src/cel/serialization/cbor.ts +189 -0
- package/src/cel/serialization/index.ts +10 -0
- package/src/cel/serialization/json.ts +209 -0
- package/src/cel/types.ts +160 -0
- package/src/cel/witnesses/BitcoinWitness.ts +184 -0
- package/src/cel/witnesses/HttpWitness.ts +241 -0
- package/src/cel/witnesses/WitnessService.ts +51 -0
- package/src/cel/witnesses/index.ts +11 -0
- package/src/contexts/credentials-v1.json +237 -0
- package/src/contexts/credentials-v2-examples.json +5 -0
- package/src/contexts/credentials-v2.json +340 -0
- package/src/contexts/credentials.json +237 -0
- package/src/contexts/data-integrity-v2.json +81 -0
- package/src/contexts/dids.json +58 -0
- package/src/contexts/ed255192020.json +93 -0
- package/src/contexts/ordinals-plus.json +23 -0
- package/src/contexts/originals.json +22 -0
- package/src/core/OriginalsSDK.ts +420 -0
- package/src/crypto/Multikey.ts +194 -0
- package/src/crypto/Signer.ts +262 -0
- package/src/crypto/noble-init.ts +138 -0
- package/src/did/BtcoDidResolver.ts +231 -0
- package/src/did/DIDManager.ts +705 -0
- package/src/did/Ed25519Verifier.ts +68 -0
- package/src/did/KeyManager.ts +239 -0
- package/src/did/WebVHManager.ts +499 -0
- package/src/did/createBtcoDidDocument.ts +60 -0
- package/src/did/providers/OrdinalsClientProviderAdapter.ts +68 -0
- package/src/events/EventEmitter.ts +222 -0
- package/src/events/index.ts +19 -0
- package/src/events/types.ts +331 -0
- package/src/examples/basic-usage.ts +78 -0
- package/src/examples/create-module-original.ts +435 -0
- package/src/examples/full-lifecycle-flow.ts +514 -0
- package/src/examples/run.ts +60 -0
- package/src/index.ts +204 -0
- package/src/kinds/KindRegistry.ts +320 -0
- package/src/kinds/index.ts +74 -0
- package/src/kinds/types.ts +470 -0
- package/src/kinds/validators/AgentValidator.ts +257 -0
- package/src/kinds/validators/AppValidator.ts +211 -0
- package/src/kinds/validators/DatasetValidator.ts +242 -0
- package/src/kinds/validators/DocumentValidator.ts +311 -0
- package/src/kinds/validators/MediaValidator.ts +269 -0
- package/src/kinds/validators/ModuleValidator.ts +225 -0
- package/src/kinds/validators/base.ts +276 -0
- package/src/kinds/validators/index.ts +12 -0
- package/src/lifecycle/BatchOperations.ts +381 -0
- package/src/lifecycle/LifecycleManager.ts +2156 -0
- package/src/lifecycle/OriginalsAsset.ts +524 -0
- package/src/lifecycle/ProvenanceQuery.ts +280 -0
- package/src/lifecycle/ResourceVersioning.ts +163 -0
- package/src/migration/MigrationManager.ts +587 -0
- package/src/migration/audit/AuditLogger.ts +176 -0
- package/src/migration/checkpoint/CheckpointManager.ts +112 -0
- package/src/migration/checkpoint/CheckpointStorage.ts +101 -0
- package/src/migration/index.ts +33 -0
- package/src/migration/operations/BaseMigration.ts +126 -0
- package/src/migration/operations/PeerToBtcoMigration.ts +105 -0
- package/src/migration/operations/PeerToWebvhMigration.ts +62 -0
- package/src/migration/operations/WebvhToBtcoMigration.ts +105 -0
- package/src/migration/rollback/RollbackManager.ts +170 -0
- package/src/migration/state/StateMachine.ts +92 -0
- package/src/migration/state/StateTracker.ts +156 -0
- package/src/migration/types.ts +356 -0
- package/src/migration/validation/BitcoinValidator.ts +107 -0
- package/src/migration/validation/CredentialValidator.ts +62 -0
- package/src/migration/validation/DIDCompatibilityValidator.ts +151 -0
- package/src/migration/validation/LifecycleValidator.ts +64 -0
- package/src/migration/validation/StorageValidator.ts +79 -0
- package/src/migration/validation/ValidationPipeline.ts +213 -0
- package/src/resources/ResourceManager.ts +655 -0
- package/src/resources/index.ts +21 -0
- package/src/resources/types.ts +202 -0
- package/src/storage/LocalStorageAdapter.ts +64 -0
- package/src/storage/MemoryStorageAdapter.ts +29 -0
- package/src/storage/StorageAdapter.ts +25 -0
- package/src/storage/index.ts +3 -0
- package/src/types/bitcoin.ts +98 -0
- package/src/types/common.ts +92 -0
- package/src/types/credentials.ts +89 -0
- package/src/types/did.ts +31 -0
- package/src/types/external-shims.d.ts +53 -0
- package/src/types/index.ts +7 -0
- package/src/types/network.ts +178 -0
- package/src/utils/EventLogger.ts +298 -0
- package/src/utils/Logger.ts +324 -0
- package/src/utils/MetricsCollector.ts +358 -0
- package/src/utils/bitcoin-address.ts +132 -0
- package/src/utils/cbor.ts +31 -0
- package/src/utils/encoding.ts +135 -0
- package/src/utils/hash.ts +12 -0
- package/src/utils/retry.ts +46 -0
- package/src/utils/satoshi-validation.ts +196 -0
- package/src/utils/serialization.ts +102 -0
- package/src/utils/telemetry.ts +44 -0
- package/src/utils/validation.ts +123 -0
- package/src/vc/CredentialManager.ts +955 -0
- package/src/vc/Issuer.ts +105 -0
- package/src/vc/Verifier.ts +54 -0
- package/src/vc/cryptosuites/bbs.ts +253 -0
- package/src/vc/cryptosuites/bbsSimple.ts +21 -0
- package/src/vc/cryptosuites/eddsa.ts +99 -0
- package/src/vc/documentLoader.ts +81 -0
- package/src/vc/proofs/data-integrity.ts +33 -0
- package/src/vc/utils/jsonld.ts +18 -0
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,420 @@
|
|
|
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
|
+
|