@originals/sdk 1.2.0 → 1.4.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/package.json +1 -1
- package/src/did/DIDManager.ts +1 -1
- package/src/did/WebVHManager.ts +11 -2
- package/src/examples/create-module-original.ts +435 -0
- package/src/examples/full-lifecycle-flow.ts +514 -0
- package/src/examples/run.ts +59 -4
- package/src/index.ts +69 -3
- package/src/kinds/KindRegistry.ts +290 -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/LifecycleManager.ts +909 -1
- package/src/resources/ResourceManager.ts +655 -0
- package/src/resources/index.ts +21 -0
- package/src/resources/types.ts +202 -0
- package/src/types/common.ts +1 -1
- package/src/vc/CredentialManager.ts +647 -2
- package/tests/integration/createTypedOriginal.test.ts +379 -0
- package/tests/performance/BatchOperations.perf.test.ts +2 -2
- package/tests/unit/kinds/KindRegistry.test.ts +329 -0
- package/tests/unit/kinds/types.test.ts +409 -0
- package/tests/unit/kinds/validators.test.ts +651 -0
- package/tests/unit/lifecycle/LifecycleManager.cleanapi.test.ts +441 -0
- package/tests/unit/resources/ResourceManager.test.ts +740 -0
- package/tests/unit/vc/CredentialManager.helpers.test.ts +527 -0
- package/.turbo/turbo-build.log +0 -1
- package/dist/adapters/FeeOracleMock.d.ts +0 -6
- package/dist/adapters/FeeOracleMock.js +0 -8
- package/dist/adapters/index.d.ts +0 -4
- package/dist/adapters/index.js +0 -4
- package/dist/adapters/providers/OrdHttpProvider.d.ts +0 -56
- package/dist/adapters/providers/OrdHttpProvider.js +0 -110
- package/dist/adapters/providers/OrdMockProvider.d.ts +0 -70
- package/dist/adapters/providers/OrdMockProvider.js +0 -75
- package/dist/adapters/types.d.ts +0 -71
- package/dist/adapters/types.js +0 -1
- package/dist/bitcoin/BitcoinManager.d.ts +0 -15
- package/dist/bitcoin/BitcoinManager.js +0 -262
- package/dist/bitcoin/BroadcastClient.d.ts +0 -30
- package/dist/bitcoin/BroadcastClient.js +0 -35
- package/dist/bitcoin/OrdinalsClient.d.ts +0 -21
- package/dist/bitcoin/OrdinalsClient.js +0 -105
- package/dist/bitcoin/PSBTBuilder.d.ts +0 -24
- package/dist/bitcoin/PSBTBuilder.js +0 -80
- package/dist/bitcoin/fee-calculation.d.ts +0 -14
- package/dist/bitcoin/fee-calculation.js +0 -31
- package/dist/bitcoin/providers/OrdNodeProvider.d.ts +0 -38
- package/dist/bitcoin/providers/OrdNodeProvider.js +0 -67
- package/dist/bitcoin/providers/OrdinalsProvider.d.ts +0 -33
- package/dist/bitcoin/providers/OrdinalsProvider.js +0 -50
- package/dist/bitcoin/providers/types.d.ts +0 -63
- package/dist/bitcoin/providers/types.js +0 -1
- package/dist/bitcoin/transactions/commit.d.ts +0 -89
- package/dist/bitcoin/transactions/commit.js +0 -311
- package/dist/bitcoin/transactions/index.d.ts +0 -7
- package/dist/bitcoin/transactions/index.js +0 -8
- package/dist/bitcoin/transfer.d.ts +0 -9
- package/dist/bitcoin/transfer.js +0 -26
- package/dist/bitcoin/utxo-selection.d.ts +0 -78
- package/dist/bitcoin/utxo-selection.js +0 -237
- package/dist/bitcoin/utxo.d.ts +0 -26
- package/dist/bitcoin/utxo.js +0 -78
- package/dist/contexts/credentials-v1.json +0 -195
- package/dist/contexts/credentials-v2-examples.json +0 -5
- package/dist/contexts/credentials-v2.json +0 -301
- package/dist/contexts/credentials.json +0 -195
- package/dist/contexts/data-integrity-v2.json +0 -81
- package/dist/contexts/dids.json +0 -57
- package/dist/contexts/ed255192020.json +0 -93
- package/dist/contexts/ordinals-plus.json +0 -23
- package/dist/contexts/originals.json +0 -22
- package/dist/core/OriginalsSDK.d.ts +0 -158
- package/dist/core/OriginalsSDK.js +0 -274
- package/dist/crypto/Multikey.d.ts +0 -30
- package/dist/crypto/Multikey.js +0 -149
- package/dist/crypto/Signer.d.ts +0 -21
- package/dist/crypto/Signer.js +0 -196
- package/dist/crypto/noble-init.d.ts +0 -18
- package/dist/crypto/noble-init.js +0 -106
- package/dist/did/BtcoDidResolver.d.ts +0 -57
- package/dist/did/BtcoDidResolver.js +0 -166
- package/dist/did/DIDManager.d.ts +0 -101
- package/dist/did/DIDManager.js +0 -493
- package/dist/did/Ed25519Verifier.d.ts +0 -30
- package/dist/did/Ed25519Verifier.js +0 -59
- package/dist/did/KeyManager.d.ts +0 -17
- package/dist/did/KeyManager.js +0 -207
- package/dist/did/WebVHManager.d.ts +0 -100
- package/dist/did/WebVHManager.js +0 -304
- package/dist/did/createBtcoDidDocument.d.ts +0 -10
- package/dist/did/createBtcoDidDocument.js +0 -42
- package/dist/did/providers/OrdinalsClientProviderAdapter.d.ts +0 -23
- package/dist/did/providers/OrdinalsClientProviderAdapter.js +0 -51
- package/dist/events/EventEmitter.d.ts +0 -115
- package/dist/events/EventEmitter.js +0 -198
- package/dist/events/index.d.ts +0 -7
- package/dist/events/index.js +0 -6
- package/dist/events/types.d.ts +0 -286
- package/dist/events/types.js +0 -9
- package/dist/examples/basic-usage.d.ts +0 -3
- package/dist/examples/basic-usage.js +0 -62
- package/dist/examples/run.d.ts +0 -1
- package/dist/examples/run.js +0 -4
- package/dist/index.d.ts +0 -39
- package/dist/index.js +0 -47
- package/dist/lifecycle/BatchOperations.d.ts +0 -147
- package/dist/lifecycle/BatchOperations.js +0 -251
- package/dist/lifecycle/LifecycleManager.d.ts +0 -116
- package/dist/lifecycle/LifecycleManager.js +0 -971
- package/dist/lifecycle/OriginalsAsset.d.ts +0 -164
- package/dist/lifecycle/OriginalsAsset.js +0 -380
- package/dist/lifecycle/ProvenanceQuery.d.ts +0 -126
- package/dist/lifecycle/ProvenanceQuery.js +0 -220
- package/dist/lifecycle/ResourceVersioning.d.ts +0 -73
- package/dist/lifecycle/ResourceVersioning.js +0 -127
- package/dist/migration/MigrationManager.d.ts +0 -86
- package/dist/migration/MigrationManager.js +0 -412
- package/dist/migration/audit/AuditLogger.d.ts +0 -51
- package/dist/migration/audit/AuditLogger.js +0 -156
- package/dist/migration/checkpoint/CheckpointManager.d.ts +0 -31
- package/dist/migration/checkpoint/CheckpointManager.js +0 -96
- package/dist/migration/checkpoint/CheckpointStorage.d.ts +0 -26
- package/dist/migration/checkpoint/CheckpointStorage.js +0 -89
- package/dist/migration/index.d.ts +0 -22
- package/dist/migration/index.js +0 -27
- package/dist/migration/operations/BaseMigration.d.ts +0 -48
- package/dist/migration/operations/BaseMigration.js +0 -83
- package/dist/migration/operations/PeerToBtcoMigration.d.ts +0 -25
- package/dist/migration/operations/PeerToBtcoMigration.js +0 -67
- package/dist/migration/operations/PeerToWebvhMigration.d.ts +0 -19
- package/dist/migration/operations/PeerToWebvhMigration.js +0 -46
- package/dist/migration/operations/WebvhToBtcoMigration.d.ts +0 -25
- package/dist/migration/operations/WebvhToBtcoMigration.js +0 -67
- package/dist/migration/rollback/RollbackManager.d.ts +0 -29
- package/dist/migration/rollback/RollbackManager.js +0 -146
- package/dist/migration/state/StateMachine.d.ts +0 -25
- package/dist/migration/state/StateMachine.js +0 -76
- package/dist/migration/state/StateTracker.d.ts +0 -36
- package/dist/migration/state/StateTracker.js +0 -123
- package/dist/migration/types.d.ts +0 -306
- package/dist/migration/types.js +0 -33
- package/dist/migration/validation/BitcoinValidator.d.ts +0 -13
- package/dist/migration/validation/BitcoinValidator.js +0 -83
- package/dist/migration/validation/CredentialValidator.d.ts +0 -13
- package/dist/migration/validation/CredentialValidator.js +0 -46
- package/dist/migration/validation/DIDCompatibilityValidator.d.ts +0 -16
- package/dist/migration/validation/DIDCompatibilityValidator.js +0 -127
- package/dist/migration/validation/LifecycleValidator.d.ts +0 -10
- package/dist/migration/validation/LifecycleValidator.js +0 -52
- package/dist/migration/validation/StorageValidator.d.ts +0 -10
- package/dist/migration/validation/StorageValidator.js +0 -65
- package/dist/migration/validation/ValidationPipeline.d.ts +0 -29
- package/dist/migration/validation/ValidationPipeline.js +0 -180
- package/dist/storage/LocalStorageAdapter.d.ts +0 -11
- package/dist/storage/LocalStorageAdapter.js +0 -53
- package/dist/storage/MemoryStorageAdapter.d.ts +0 -6
- package/dist/storage/MemoryStorageAdapter.js +0 -21
- package/dist/storage/StorageAdapter.d.ts +0 -16
- package/dist/storage/StorageAdapter.js +0 -1
- package/dist/storage/index.d.ts +0 -2
- package/dist/storage/index.js +0 -2
- package/dist/types/bitcoin.d.ts +0 -84
- package/dist/types/bitcoin.js +0 -1
- package/dist/types/common.d.ts +0 -82
- package/dist/types/common.js +0 -1
- package/dist/types/credentials.d.ts +0 -75
- package/dist/types/credentials.js +0 -1
- package/dist/types/did.d.ts +0 -26
- package/dist/types/did.js +0 -1
- package/dist/types/index.d.ts +0 -5
- package/dist/types/index.js +0 -5
- package/dist/types/network.d.ts +0 -78
- package/dist/types/network.js +0 -145
- package/dist/utils/EventLogger.d.ts +0 -71
- package/dist/utils/EventLogger.js +0 -232
- package/dist/utils/Logger.d.ts +0 -106
- package/dist/utils/Logger.js +0 -257
- package/dist/utils/MetricsCollector.d.ts +0 -110
- package/dist/utils/MetricsCollector.js +0 -264
- package/dist/utils/bitcoin-address.d.ts +0 -38
- package/dist/utils/bitcoin-address.js +0 -113
- package/dist/utils/cbor.d.ts +0 -2
- package/dist/utils/cbor.js +0 -9
- package/dist/utils/encoding.d.ts +0 -37
- package/dist/utils/encoding.js +0 -120
- package/dist/utils/hash.d.ts +0 -1
- package/dist/utils/hash.js +0 -5
- package/dist/utils/retry.d.ts +0 -10
- package/dist/utils/retry.js +0 -35
- package/dist/utils/satoshi-validation.d.ts +0 -60
- package/dist/utils/satoshi-validation.js +0 -156
- package/dist/utils/serialization.d.ts +0 -14
- package/dist/utils/serialization.js +0 -76
- package/dist/utils/telemetry.d.ts +0 -17
- package/dist/utils/telemetry.js +0 -24
- package/dist/utils/validation.d.ts +0 -5
- package/dist/utils/validation.js +0 -98
- package/dist/vc/CredentialManager.d.ts +0 -22
- package/dist/vc/CredentialManager.js +0 -227
- package/dist/vc/Issuer.d.ts +0 -27
- package/dist/vc/Issuer.js +0 -70
- package/dist/vc/Verifier.d.ts +0 -16
- package/dist/vc/Verifier.js +0 -50
- package/dist/vc/cryptosuites/bbs.d.ts +0 -44
- package/dist/vc/cryptosuites/bbs.js +0 -213
- package/dist/vc/cryptosuites/bbsSimple.d.ts +0 -9
- package/dist/vc/cryptosuites/bbsSimple.js +0 -12
- package/dist/vc/cryptosuites/eddsa.d.ts +0 -30
- package/dist/vc/cryptosuites/eddsa.js +0 -81
- package/dist/vc/documentLoader.d.ts +0 -16
- package/dist/vc/documentLoader.js +0 -59
- package/dist/vc/proofs/data-integrity.d.ts +0 -21
- package/dist/vc/proofs/data-integrity.js +0 -15
- package/dist/vc/utils/jsonld.d.ts +0 -2
- package/dist/vc/utils/jsonld.js +0 -15
- package/test/logs/did_webvh_QmNTn9Kkp8dQ75WrF9xqJ2kuDp9QhKc3aPiERRMj8XoTBN_example_com.jsonl +0 -1
- package/test/logs/did_webvh_QmNu4MNr8Lr5txx5gYNhuhZDchXsZEu3hJXKYuphpWTPDp_example_com_users_etc_passwd.jsonl +0 -1
- package/test/logs/did_webvh_QmR9MrGZACzjKETA8SBRNCKG11HxU85c4bVR2qN5eDCfsD_example_com.jsonl +0 -1
- package/test/logs/did_webvh_QmUc5suaqRM2P4nrXxZwqYMfqzhdMqjuL7oJaJbEpCQVCd_example_com_users_etc_passwd.jsonl +0 -1
- package/test/logs/did_webvh_QmUkiB2RCV2VZ1RTXsCebWN25Eiy9TLvpzDWAJNjhgvB4X_example_com_etc_passwd.jsonl +0 -1
- package/test/logs/did_webvh_QmUoRTe8UMwpAQXZSAW7pjAgZK1tq2X3C6Kfxq3UXGcaGy_example_com_secret.jsonl +0 -1
- package/test/logs/did_webvh_QmWWot3chx1t6KwTmcE5i2FeDZ5JMkQw3qXycsKDVmJ9Be_example_com_users_alice.jsonl +0 -1
- package/test/logs/did_webvh_QmWvVgALL5kjZdpgR7KZay7J8UiiUr834kkRmWeFAxjAuC_example_com_users_etc_passwd.jsonl +0 -1
- package/test/logs/did_webvh_QmWwaRQHUZAFcKihFC6xR6tRTTrQhHPTku6azf1egWbpy1_example_com_users_alice.jsonl +0 -1
- package/test/logs/did_webvh_QmXJLtkz23r7AozbtXsZMKWnVU6rd38CkVtjdWuATU3Yp6_example_com_users_alice123_profile.jsonl +0 -1
- package/test/logs/did_webvh_QmYsce448po14oDE1wXbyaP6wY9HQgHSKLwdezn1k577SF_example_com_my_org_user_name_test_123.jsonl +0 -1
- package/test/logs/did_webvh_QmZBeNzzqajxdfwcDUPZ4P8C5YSXyRztrAwmPiKuKUxmAK_example_com.jsonl +0 -1
- package/test/logs/did_webvh_QmZhJsqxizwVbRtqCUkmE6XQunSxtxMt3gbTYadVBNAaEq_example_com.jsonl +0 -1
- package/test/logs/did_webvh_QmZk7NHU2D57RzzbMq4tWW9gBa9AqtVTWfiRM6RFdwGVj2_example_com.jsonl +0 -1
- package/test/logs/did_webvh_QmZshSXp9w8ovH62zGGBS1b5pGGPsuYiu1VQ935sga2hWF_example_com_level1_level2.jsonl +0 -1
- package/test/logs/did_webvh_QmbWAmw7HQL7vKJyCsctZihXf1rmT4sGvggKCPKWcUWjw1_example_com.jsonl +0 -1
- package/test/logs/did_webvh_QmbdLUMbYs3juR39TLB6hhrFWLcNg45ybUzeBJCS1MhCh1_example_com_C_Windows_System32.jsonl +0 -1
- package/test/logs/did_webvh_QmcaQ1Ma4gkSbae85aCm8Mv4rvdT2Sb2RR3JzYwrm5XBq8_example_com_etc_passwd.jsonl +0 -1
- package/test/logs/did_webvh_QmcbA7WQhsBqZSoDpKJHjV8Q5o53h8vmgJhQfo6rqTY5ho_example_com.jsonl +0 -1
- package/test/logs/did_webvh_Qmdy8uWr2gkUJrXsThynAug3DASTWwb3onEj89LKmMGZYB_example_com.jsonl +0 -1
- package/tests/e2e/README.md +0 -97
- package/tests/e2e/example.spec.ts +0 -78
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Noble Crypto Library Initialization
|
|
3
|
-
*
|
|
4
|
-
* @noble/ed25519 v2.x and @noble/secp256k1 require manual configuration of hash functions.
|
|
5
|
-
* This is by design - they don't bundle hash implementations to allow flexibility.
|
|
6
|
-
*
|
|
7
|
-
* This module centralizes the initialization to ensure:
|
|
8
|
-
* 1. Libraries are configured before any crypto operations
|
|
9
|
-
* 2. Configuration is consistent across the SDK
|
|
10
|
-
* 3. Readonly property issues (Bun) are handled gracefully
|
|
11
|
-
*
|
|
12
|
-
* This should be imported at the SDK entry point (index.ts) to ensure it runs first.
|
|
13
|
-
*/
|
|
14
|
-
/**
|
|
15
|
-
* Initialize all noble crypto libraries
|
|
16
|
-
* This should be called once at SDK startup
|
|
17
|
-
*/
|
|
18
|
-
export declare function initNobleCrypto(): void;
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Noble Crypto Library Initialization
|
|
3
|
-
*
|
|
4
|
-
* @noble/ed25519 v2.x and @noble/secp256k1 require manual configuration of hash functions.
|
|
5
|
-
* This is by design - they don't bundle hash implementations to allow flexibility.
|
|
6
|
-
*
|
|
7
|
-
* This module centralizes the initialization to ensure:
|
|
8
|
-
* 1. Libraries are configured before any crypto operations
|
|
9
|
-
* 2. Configuration is consistent across the SDK
|
|
10
|
-
* 3. Readonly property issues (Bun) are handled gracefully
|
|
11
|
-
*
|
|
12
|
-
* This should be imported at the SDK entry point (index.ts) to ensure it runs first.
|
|
13
|
-
*/
|
|
14
|
-
import * as secp256k1 from '@noble/secp256k1';
|
|
15
|
-
import * as ed25519 from '@noble/ed25519';
|
|
16
|
-
import { sha256, sha512 } from '@noble/hashes/sha2.js';
|
|
17
|
-
import { hmac } from '@noble/hashes/hmac.js';
|
|
18
|
-
import { concatBytes } from '@noble/hashes/utils.js';
|
|
19
|
-
// Implementation functions
|
|
20
|
-
const sha512Impl = (...msgs) => sha512(concatBytes(...msgs));
|
|
21
|
-
const hmacSha256Impl = (key, ...msgs) => hmac(sha256, key, concatBytes(...msgs));
|
|
22
|
-
/**
|
|
23
|
-
* Safely set a property on an object, handling readonly properties
|
|
24
|
-
*/
|
|
25
|
-
function safeSetProperty(obj, prop, value, options) {
|
|
26
|
-
try {
|
|
27
|
-
obj[prop] = value;
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
catch {
|
|
31
|
-
// Property might be readonly, try defineProperty
|
|
32
|
-
try {
|
|
33
|
-
Object.defineProperty(obj, prop, {
|
|
34
|
-
value,
|
|
35
|
-
writable: options?.writable ?? true,
|
|
36
|
-
configurable: options?.configurable ?? true,
|
|
37
|
-
});
|
|
38
|
-
return true;
|
|
39
|
-
}
|
|
40
|
-
catch {
|
|
41
|
-
// If both fail, property might already be set or truly readonly
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Initialize @noble/secp256k1 with hmacSha256Sync utility
|
|
48
|
-
*/
|
|
49
|
-
function initSecp256k1() {
|
|
50
|
-
const sAny = secp256k1;
|
|
51
|
-
if (!sAny?.utils) {
|
|
52
|
-
// Try to create utils object if it doesn't exist
|
|
53
|
-
try {
|
|
54
|
-
sAny.utils = {};
|
|
55
|
-
}
|
|
56
|
-
catch {
|
|
57
|
-
// If we can't create it, try defineProperty
|
|
58
|
-
Object.defineProperty(sAny, 'utils', {
|
|
59
|
-
value: {},
|
|
60
|
-
writable: true,
|
|
61
|
-
configurable: true,
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
// Set hmacSha256Sync if not already set
|
|
66
|
-
if (typeof sAny.utils.hmacSha256Sync !== 'function') {
|
|
67
|
-
safeSetProperty(sAny.utils, 'hmacSha256Sync', hmacSha256Impl);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Initialize @noble/ed25519 with sha512Sync utility
|
|
72
|
-
* Handles both etc.sha512Sync (v2.x) and utils.sha512Sync (backward compat)
|
|
73
|
-
*/
|
|
74
|
-
function initEd25519() {
|
|
75
|
-
const eAny = ed25519;
|
|
76
|
-
// Set etc.sha512Sync for @noble/ed25519 v2.x (required)
|
|
77
|
-
if (eAny?.etc && typeof eAny.etc.sha512Sync !== 'function') {
|
|
78
|
-
safeSetProperty(eAny.etc, 'sha512Sync', sha512Impl);
|
|
79
|
-
}
|
|
80
|
-
// Set utils.sha512Sync for backward compatibility
|
|
81
|
-
if (!eAny?.utils) {
|
|
82
|
-
try {
|
|
83
|
-
eAny.utils = {};
|
|
84
|
-
}
|
|
85
|
-
catch {
|
|
86
|
-
Object.defineProperty(eAny, 'utils', {
|
|
87
|
-
value: {},
|
|
88
|
-
writable: true,
|
|
89
|
-
configurable: true,
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (typeof eAny.utils.sha512Sync !== 'function') {
|
|
94
|
-
safeSetProperty(eAny.utils, 'sha512Sync', sha512Impl);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Initialize all noble crypto libraries
|
|
99
|
-
* This should be called once at SDK startup
|
|
100
|
-
*/
|
|
101
|
-
export function initNobleCrypto() {
|
|
102
|
-
initSecp256k1();
|
|
103
|
-
initEd25519();
|
|
104
|
-
}
|
|
105
|
-
// Auto-initialize when this module is imported
|
|
106
|
-
initNobleCrypto();
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import type { DIDDocument } from '../types/did';
|
|
2
|
-
export interface BtcoInscriptionData {
|
|
3
|
-
inscriptionId: string;
|
|
4
|
-
content: string;
|
|
5
|
-
metadata: any;
|
|
6
|
-
contentUrl?: string;
|
|
7
|
-
contentType?: string;
|
|
8
|
-
isValidDid?: boolean;
|
|
9
|
-
didDocument?: DIDDocument | null;
|
|
10
|
-
error?: string;
|
|
11
|
-
}
|
|
12
|
-
export interface BtcoDidResolutionResult {
|
|
13
|
-
didDocument: DIDDocument | null;
|
|
14
|
-
inscriptions?: BtcoInscriptionData[];
|
|
15
|
-
resolutionMetadata: {
|
|
16
|
-
contentType?: string;
|
|
17
|
-
error?: string;
|
|
18
|
-
message?: string;
|
|
19
|
-
inscriptionId?: string;
|
|
20
|
-
satNumber?: string;
|
|
21
|
-
network?: string;
|
|
22
|
-
totalInscriptions?: number;
|
|
23
|
-
};
|
|
24
|
-
didDocumentMetadata: {
|
|
25
|
-
created?: string;
|
|
26
|
-
updated?: string;
|
|
27
|
-
deactivated?: boolean;
|
|
28
|
-
inscriptionId?: string;
|
|
29
|
-
network?: string;
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
export interface ResourceProviderLike {
|
|
33
|
-
getSatInfo(satNumber: string): Promise<{
|
|
34
|
-
inscription_ids: string[];
|
|
35
|
-
}>;
|
|
36
|
-
resolveInscription(inscriptionId: string): Promise<{
|
|
37
|
-
id: string;
|
|
38
|
-
sat: number;
|
|
39
|
-
content_type: string;
|
|
40
|
-
content_url: string;
|
|
41
|
-
}>;
|
|
42
|
-
getMetadata(inscriptionId: string): Promise<any>;
|
|
43
|
-
}
|
|
44
|
-
export interface BtcoDidResolutionOptions {
|
|
45
|
-
provider?: ResourceProviderLike;
|
|
46
|
-
fetchFn?: (url: string) => Promise<Response>;
|
|
47
|
-
timeout?: number;
|
|
48
|
-
}
|
|
49
|
-
export declare class BtcoDidResolver {
|
|
50
|
-
private readonly options;
|
|
51
|
-
constructor(options?: BtcoDidResolutionOptions);
|
|
52
|
-
private parseBtcoDid;
|
|
53
|
-
private getDidPrefix;
|
|
54
|
-
resolve(did: string, options?: BtcoDidResolutionOptions): Promise<BtcoDidResolutionResult>;
|
|
55
|
-
private isValidDidDocument;
|
|
56
|
-
private createErrorResult;
|
|
57
|
-
}
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
export class BtcoDidResolver {
|
|
2
|
-
constructor(options = {}) {
|
|
3
|
-
this.options = options;
|
|
4
|
-
}
|
|
5
|
-
parseBtcoDid(did) {
|
|
6
|
-
const regex = /^did:btco(?::(reg|sig))?:([0-9]+)(?:\/(.+))?$/;
|
|
7
|
-
const match = did.match(regex);
|
|
8
|
-
if (!match)
|
|
9
|
-
return null;
|
|
10
|
-
const [, networkSuffix, satNumber, path] = match;
|
|
11
|
-
const network = networkSuffix || 'mainnet';
|
|
12
|
-
return { satNumber, path, network };
|
|
13
|
-
}
|
|
14
|
-
getDidPrefix(network) {
|
|
15
|
-
switch (network) {
|
|
16
|
-
case 'reg':
|
|
17
|
-
case 'regtest':
|
|
18
|
-
return 'did:btco:reg';
|
|
19
|
-
case 'sig':
|
|
20
|
-
case 'signet':
|
|
21
|
-
return 'did:btco:sig';
|
|
22
|
-
default:
|
|
23
|
-
return 'did:btco';
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
async resolve(did, options = {}) {
|
|
27
|
-
const parsed = this.parseBtcoDid(did);
|
|
28
|
-
if (!parsed) {
|
|
29
|
-
return this.createErrorResult('invalidDid', `Invalid BTCO DID format: ${did}`);
|
|
30
|
-
}
|
|
31
|
-
const { satNumber, network } = parsed;
|
|
32
|
-
const provider = options.provider || this.options.provider;
|
|
33
|
-
if (!provider) {
|
|
34
|
-
return this.createErrorResult('noProvider', 'No provider supplied');
|
|
35
|
-
}
|
|
36
|
-
let inscriptionIds = [];
|
|
37
|
-
try {
|
|
38
|
-
const satInfo = await provider.getSatInfo(satNumber);
|
|
39
|
-
inscriptionIds = satInfo?.inscription_ids || [];
|
|
40
|
-
}
|
|
41
|
-
catch (e) {
|
|
42
|
-
return this.createErrorResult('notFound', `Failed to retrieve inscriptions for satoshi ${satNumber}: ${e?.message || String(e)}`);
|
|
43
|
-
}
|
|
44
|
-
if (inscriptionIds.length === 0) {
|
|
45
|
-
return this.createErrorResult('notFound', `No inscriptions found on satoshi ${satNumber}`);
|
|
46
|
-
}
|
|
47
|
-
const expectedDid = `${this.getDidPrefix(network)}:${satNumber}`;
|
|
48
|
-
const didPattern = new RegExp(`^(?:BTCO DID: )?(${expectedDid.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')})`, 'i');
|
|
49
|
-
const inscriptionDataList = [];
|
|
50
|
-
for (const inscriptionId of inscriptionIds) {
|
|
51
|
-
const inscriptionData = {
|
|
52
|
-
inscriptionId,
|
|
53
|
-
content: '',
|
|
54
|
-
metadata: null
|
|
55
|
-
};
|
|
56
|
-
try {
|
|
57
|
-
const inscription = await provider.resolveInscription(inscriptionId);
|
|
58
|
-
if (!inscription) {
|
|
59
|
-
inscriptionData.error = `Inscription ${inscriptionId} not found`;
|
|
60
|
-
inscriptionDataList.push(inscriptionData);
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
inscriptionData.contentUrl = inscription.content_url;
|
|
64
|
-
inscriptionData.contentType = inscription.content_type;
|
|
65
|
-
try {
|
|
66
|
-
// Use configurable fetch function or default to global fetch
|
|
67
|
-
const fetchFn = options.fetchFn || this.options.fetchFn || fetch;
|
|
68
|
-
const timeout = options.timeout || this.options.timeout || 10000; // 10 second default
|
|
69
|
-
// Create abort controller for timeout
|
|
70
|
-
const controller = new AbortController();
|
|
71
|
-
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
72
|
-
try {
|
|
73
|
-
const response = await fetchFn(inscription.content_url);
|
|
74
|
-
clearTimeout(timeoutId);
|
|
75
|
-
if (!response.ok) {
|
|
76
|
-
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
77
|
-
}
|
|
78
|
-
inscriptionData.content = await response.text();
|
|
79
|
-
}
|
|
80
|
-
finally {
|
|
81
|
-
clearTimeout(timeoutId);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
catch (err) {
|
|
85
|
-
inscriptionData.error = `Failed to fetch content: ${err?.message || String(err)}`;
|
|
86
|
-
inscriptionDataList.push(inscriptionData);
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
try {
|
|
90
|
-
inscriptionData.metadata = await provider.getMetadata(inscriptionId);
|
|
91
|
-
}
|
|
92
|
-
catch (err) {
|
|
93
|
-
inscriptionData.metadata = null;
|
|
94
|
-
}
|
|
95
|
-
inscriptionData.isValidDid = didPattern.test(inscriptionData.content);
|
|
96
|
-
if (inscriptionData.isValidDid && inscriptionData.metadata) {
|
|
97
|
-
const didDocument = inscriptionData.metadata;
|
|
98
|
-
if (this.isValidDidDocument(didDocument) && didDocument.id === expectedDid) {
|
|
99
|
-
inscriptionData.didDocument = didDocument;
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
inscriptionData.error = 'Invalid DID document structure or mismatched ID';
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
if (inscriptionData.content.includes('🔥')) {
|
|
106
|
-
inscriptionData.didDocument = null;
|
|
107
|
-
if (!inscriptionData.error) {
|
|
108
|
-
inscriptionData.error = 'DID has been deactivated';
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
catch (err) {
|
|
113
|
-
inscriptionData.error = `Failed to process inscription: ${err?.message || String(err)}`;
|
|
114
|
-
}
|
|
115
|
-
inscriptionDataList.push(inscriptionData);
|
|
116
|
-
}
|
|
117
|
-
let latestValidDidDocument = null;
|
|
118
|
-
let latestInscriptionId;
|
|
119
|
-
for (let i = inscriptionDataList.length - 1; i >= 0; i--) {
|
|
120
|
-
const data = inscriptionDataList[i];
|
|
121
|
-
if (data.didDocument && !data.error) {
|
|
122
|
-
latestValidDidDocument = data.didDocument;
|
|
123
|
-
latestInscriptionId = data.inscriptionId;
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return {
|
|
128
|
-
didDocument: latestValidDidDocument,
|
|
129
|
-
inscriptions: inscriptionDataList,
|
|
130
|
-
resolutionMetadata: {
|
|
131
|
-
inscriptionId: latestInscriptionId,
|
|
132
|
-
satNumber,
|
|
133
|
-
network,
|
|
134
|
-
totalInscriptions: inscriptionDataList.length
|
|
135
|
-
},
|
|
136
|
-
didDocumentMetadata: {
|
|
137
|
-
inscriptionId: latestInscriptionId,
|
|
138
|
-
network
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
isValidDidDocument(doc) {
|
|
143
|
-
if (!doc || typeof doc !== 'object')
|
|
144
|
-
return false;
|
|
145
|
-
if (!doc.id || typeof doc.id !== 'string')
|
|
146
|
-
return false;
|
|
147
|
-
if (!doc['@context'])
|
|
148
|
-
return false;
|
|
149
|
-
const contexts = Array.isArray(doc['@context']) ? doc['@context'] : [doc['@context']];
|
|
150
|
-
if (!contexts.includes('https://www.w3.org/ns/did/v1') && !contexts.includes('https://w3id.org/did/v1')) {
|
|
151
|
-
return false;
|
|
152
|
-
}
|
|
153
|
-
if (doc.verificationMethod && !Array.isArray(doc.verificationMethod))
|
|
154
|
-
return false;
|
|
155
|
-
if (doc.authentication && !Array.isArray(doc.authentication))
|
|
156
|
-
return false;
|
|
157
|
-
return true;
|
|
158
|
-
}
|
|
159
|
-
createErrorResult(error, message) {
|
|
160
|
-
return {
|
|
161
|
-
didDocument: null,
|
|
162
|
-
resolutionMetadata: { error, message },
|
|
163
|
-
didDocumentMetadata: {}
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
}
|
package/dist/did/DIDManager.d.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { DIDDocument, OriginalsConfig, AssetResource, KeyPair, ExternalSigner, ExternalVerifier } from '../types';
|
|
2
|
-
import { createBtcoDidDocument } from './createBtcoDidDocument';
|
|
3
|
-
export declare class DIDManager {
|
|
4
|
-
private config;
|
|
5
|
-
constructor(config: OriginalsConfig);
|
|
6
|
-
createDIDPeer(resources: AssetResource[], returnKeyPair?: false): Promise<DIDDocument>;
|
|
7
|
-
createDIDPeer(resources: AssetResource[], returnKeyPair: true): Promise<{
|
|
8
|
-
didDocument: DIDDocument;
|
|
9
|
-
keyPair: {
|
|
10
|
-
privateKey: string;
|
|
11
|
-
publicKey: string;
|
|
12
|
-
};
|
|
13
|
-
}>;
|
|
14
|
-
migrateToDIDWebVH(didDoc: DIDDocument, domain?: string): Promise<DIDDocument>;
|
|
15
|
-
migrateToDIDBTCO(didDoc: DIDDocument, satoshi: string): Promise<DIDDocument>;
|
|
16
|
-
resolveDID(did: string): Promise<DIDDocument | null>;
|
|
17
|
-
validateDIDDocument(didDoc: DIDDocument): boolean;
|
|
18
|
-
private getLayerFromDID;
|
|
19
|
-
createBtcoDidDocument(satNumber: number | string, network: 'mainnet' | 'regtest' | 'signet', options: Parameters<typeof createBtcoDidDocument>[2]): DIDDocument;
|
|
20
|
-
/**
|
|
21
|
-
* Creates a new did:webvh DID with proper cryptographic signing
|
|
22
|
-
* @param options - Creation options including domain and optional key pair or external signer
|
|
23
|
-
* @returns The created DID, document, log, and key pair (if generated)
|
|
24
|
-
*/
|
|
25
|
-
createDIDWebVH(options: CreateWebVHOptions): Promise<CreateWebVHResult>;
|
|
26
|
-
/**
|
|
27
|
-
* Updates a DID:WebVH document
|
|
28
|
-
* @param options - Update options
|
|
29
|
-
* @returns Updated DID document and log
|
|
30
|
-
*/
|
|
31
|
-
updateDIDWebVH(options: {
|
|
32
|
-
did: string;
|
|
33
|
-
currentLog: DIDLog;
|
|
34
|
-
updates: Partial<DIDDocument>;
|
|
35
|
-
signer: ExternalSigner | {
|
|
36
|
-
privateKey: string;
|
|
37
|
-
publicKey: string;
|
|
38
|
-
};
|
|
39
|
-
verifier?: ExternalVerifier;
|
|
40
|
-
outputDir?: string;
|
|
41
|
-
}): Promise<{
|
|
42
|
-
didDocument: DIDDocument;
|
|
43
|
-
log: DIDLog;
|
|
44
|
-
logPath?: string;
|
|
45
|
-
}>;
|
|
46
|
-
/**
|
|
47
|
-
* Saves the DID log to the appropriate did.jsonl path
|
|
48
|
-
* @param did - The DID identifier
|
|
49
|
-
* @param log - The DID log to save
|
|
50
|
-
* @param baseDir - Base directory for saving (e.g., public/.well-known)
|
|
51
|
-
* @returns The full path where the log was saved
|
|
52
|
-
*/
|
|
53
|
-
saveDIDLog(did: string, log: DIDLog, baseDir: string): Promise<string>;
|
|
54
|
-
/**
|
|
55
|
-
* Loads a DID log from a did.jsonl file
|
|
56
|
-
* @param logPath - Path to the did.jsonl file
|
|
57
|
-
* @returns The loaded DID log
|
|
58
|
-
*/
|
|
59
|
-
loadDIDLog(logPath: string): Promise<DIDLog>;
|
|
60
|
-
/**
|
|
61
|
-
* Validates a path segment to prevent directory traversal attacks
|
|
62
|
-
* @param segment - Path segment to validate
|
|
63
|
-
* @returns true if valid, false otherwise
|
|
64
|
-
*/
|
|
65
|
-
private isValidPathSegment;
|
|
66
|
-
}
|
|
67
|
-
interface WebVHVerificationMethod {
|
|
68
|
-
id?: string;
|
|
69
|
-
type: string;
|
|
70
|
-
controller?: string;
|
|
71
|
-
publicKeyMultibase: string;
|
|
72
|
-
secretKeyMultibase?: string;
|
|
73
|
-
purpose?: 'authentication' | 'assertionMethod' | 'keyAgreement' | 'capabilityInvocation' | 'capabilityDelegation';
|
|
74
|
-
}
|
|
75
|
-
interface DIDLogEntry {
|
|
76
|
-
versionId: string;
|
|
77
|
-
versionTime: string;
|
|
78
|
-
parameters: Record<string, unknown>;
|
|
79
|
-
state: Record<string, unknown>;
|
|
80
|
-
proof?: Record<string, unknown>[];
|
|
81
|
-
}
|
|
82
|
-
type DIDLog = DIDLogEntry[];
|
|
83
|
-
export interface CreateWebVHOptions {
|
|
84
|
-
domain?: string;
|
|
85
|
-
keyPair?: KeyPair;
|
|
86
|
-
paths?: string[];
|
|
87
|
-
portable?: boolean;
|
|
88
|
-
outputDir?: string;
|
|
89
|
-
externalSigner?: ExternalSigner;
|
|
90
|
-
externalVerifier?: ExternalVerifier;
|
|
91
|
-
verificationMethods?: WebVHVerificationMethod[];
|
|
92
|
-
updateKeys?: string[];
|
|
93
|
-
}
|
|
94
|
-
export interface CreateWebVHResult {
|
|
95
|
-
did: string;
|
|
96
|
-
didDocument: DIDDocument;
|
|
97
|
-
log: DIDLog;
|
|
98
|
-
keyPair: KeyPair;
|
|
99
|
-
logPath?: string;
|
|
100
|
-
}
|
|
101
|
-
export {};
|