@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.
Files changed (244) hide show
  1. package/package.json +1 -1
  2. package/src/did/DIDManager.ts +1 -1
  3. package/src/did/WebVHManager.ts +11 -2
  4. package/src/examples/create-module-original.ts +435 -0
  5. package/src/examples/full-lifecycle-flow.ts +514 -0
  6. package/src/examples/run.ts +59 -4
  7. package/src/index.ts +69 -3
  8. package/src/kinds/KindRegistry.ts +290 -0
  9. package/src/kinds/index.ts +74 -0
  10. package/src/kinds/types.ts +470 -0
  11. package/src/kinds/validators/AgentValidator.ts +257 -0
  12. package/src/kinds/validators/AppValidator.ts +211 -0
  13. package/src/kinds/validators/DatasetValidator.ts +242 -0
  14. package/src/kinds/validators/DocumentValidator.ts +311 -0
  15. package/src/kinds/validators/MediaValidator.ts +269 -0
  16. package/src/kinds/validators/ModuleValidator.ts +225 -0
  17. package/src/kinds/validators/base.ts +276 -0
  18. package/src/kinds/validators/index.ts +12 -0
  19. package/src/lifecycle/LifecycleManager.ts +909 -1
  20. package/src/resources/ResourceManager.ts +655 -0
  21. package/src/resources/index.ts +21 -0
  22. package/src/resources/types.ts +202 -0
  23. package/src/types/common.ts +1 -1
  24. package/src/vc/CredentialManager.ts +647 -2
  25. package/tests/integration/createTypedOriginal.test.ts +379 -0
  26. package/tests/performance/BatchOperations.perf.test.ts +2 -2
  27. package/tests/unit/kinds/KindRegistry.test.ts +329 -0
  28. package/tests/unit/kinds/types.test.ts +409 -0
  29. package/tests/unit/kinds/validators.test.ts +651 -0
  30. package/tests/unit/lifecycle/LifecycleManager.cleanapi.test.ts +441 -0
  31. package/tests/unit/resources/ResourceManager.test.ts +740 -0
  32. package/tests/unit/vc/CredentialManager.helpers.test.ts +527 -0
  33. package/.turbo/turbo-build.log +0 -1
  34. package/dist/adapters/FeeOracleMock.d.ts +0 -6
  35. package/dist/adapters/FeeOracleMock.js +0 -8
  36. package/dist/adapters/index.d.ts +0 -4
  37. package/dist/adapters/index.js +0 -4
  38. package/dist/adapters/providers/OrdHttpProvider.d.ts +0 -56
  39. package/dist/adapters/providers/OrdHttpProvider.js +0 -110
  40. package/dist/adapters/providers/OrdMockProvider.d.ts +0 -70
  41. package/dist/adapters/providers/OrdMockProvider.js +0 -75
  42. package/dist/adapters/types.d.ts +0 -71
  43. package/dist/adapters/types.js +0 -1
  44. package/dist/bitcoin/BitcoinManager.d.ts +0 -15
  45. package/dist/bitcoin/BitcoinManager.js +0 -262
  46. package/dist/bitcoin/BroadcastClient.d.ts +0 -30
  47. package/dist/bitcoin/BroadcastClient.js +0 -35
  48. package/dist/bitcoin/OrdinalsClient.d.ts +0 -21
  49. package/dist/bitcoin/OrdinalsClient.js +0 -105
  50. package/dist/bitcoin/PSBTBuilder.d.ts +0 -24
  51. package/dist/bitcoin/PSBTBuilder.js +0 -80
  52. package/dist/bitcoin/fee-calculation.d.ts +0 -14
  53. package/dist/bitcoin/fee-calculation.js +0 -31
  54. package/dist/bitcoin/providers/OrdNodeProvider.d.ts +0 -38
  55. package/dist/bitcoin/providers/OrdNodeProvider.js +0 -67
  56. package/dist/bitcoin/providers/OrdinalsProvider.d.ts +0 -33
  57. package/dist/bitcoin/providers/OrdinalsProvider.js +0 -50
  58. package/dist/bitcoin/providers/types.d.ts +0 -63
  59. package/dist/bitcoin/providers/types.js +0 -1
  60. package/dist/bitcoin/transactions/commit.d.ts +0 -89
  61. package/dist/bitcoin/transactions/commit.js +0 -311
  62. package/dist/bitcoin/transactions/index.d.ts +0 -7
  63. package/dist/bitcoin/transactions/index.js +0 -8
  64. package/dist/bitcoin/transfer.d.ts +0 -9
  65. package/dist/bitcoin/transfer.js +0 -26
  66. package/dist/bitcoin/utxo-selection.d.ts +0 -78
  67. package/dist/bitcoin/utxo-selection.js +0 -237
  68. package/dist/bitcoin/utxo.d.ts +0 -26
  69. package/dist/bitcoin/utxo.js +0 -78
  70. package/dist/contexts/credentials-v1.json +0 -195
  71. package/dist/contexts/credentials-v2-examples.json +0 -5
  72. package/dist/contexts/credentials-v2.json +0 -301
  73. package/dist/contexts/credentials.json +0 -195
  74. package/dist/contexts/data-integrity-v2.json +0 -81
  75. package/dist/contexts/dids.json +0 -57
  76. package/dist/contexts/ed255192020.json +0 -93
  77. package/dist/contexts/ordinals-plus.json +0 -23
  78. package/dist/contexts/originals.json +0 -22
  79. package/dist/core/OriginalsSDK.d.ts +0 -158
  80. package/dist/core/OriginalsSDK.js +0 -274
  81. package/dist/crypto/Multikey.d.ts +0 -30
  82. package/dist/crypto/Multikey.js +0 -149
  83. package/dist/crypto/Signer.d.ts +0 -21
  84. package/dist/crypto/Signer.js +0 -196
  85. package/dist/crypto/noble-init.d.ts +0 -18
  86. package/dist/crypto/noble-init.js +0 -106
  87. package/dist/did/BtcoDidResolver.d.ts +0 -57
  88. package/dist/did/BtcoDidResolver.js +0 -166
  89. package/dist/did/DIDManager.d.ts +0 -101
  90. package/dist/did/DIDManager.js +0 -493
  91. package/dist/did/Ed25519Verifier.d.ts +0 -30
  92. package/dist/did/Ed25519Verifier.js +0 -59
  93. package/dist/did/KeyManager.d.ts +0 -17
  94. package/dist/did/KeyManager.js +0 -207
  95. package/dist/did/WebVHManager.d.ts +0 -100
  96. package/dist/did/WebVHManager.js +0 -304
  97. package/dist/did/createBtcoDidDocument.d.ts +0 -10
  98. package/dist/did/createBtcoDidDocument.js +0 -42
  99. package/dist/did/providers/OrdinalsClientProviderAdapter.d.ts +0 -23
  100. package/dist/did/providers/OrdinalsClientProviderAdapter.js +0 -51
  101. package/dist/events/EventEmitter.d.ts +0 -115
  102. package/dist/events/EventEmitter.js +0 -198
  103. package/dist/events/index.d.ts +0 -7
  104. package/dist/events/index.js +0 -6
  105. package/dist/events/types.d.ts +0 -286
  106. package/dist/events/types.js +0 -9
  107. package/dist/examples/basic-usage.d.ts +0 -3
  108. package/dist/examples/basic-usage.js +0 -62
  109. package/dist/examples/run.d.ts +0 -1
  110. package/dist/examples/run.js +0 -4
  111. package/dist/index.d.ts +0 -39
  112. package/dist/index.js +0 -47
  113. package/dist/lifecycle/BatchOperations.d.ts +0 -147
  114. package/dist/lifecycle/BatchOperations.js +0 -251
  115. package/dist/lifecycle/LifecycleManager.d.ts +0 -116
  116. package/dist/lifecycle/LifecycleManager.js +0 -971
  117. package/dist/lifecycle/OriginalsAsset.d.ts +0 -164
  118. package/dist/lifecycle/OriginalsAsset.js +0 -380
  119. package/dist/lifecycle/ProvenanceQuery.d.ts +0 -126
  120. package/dist/lifecycle/ProvenanceQuery.js +0 -220
  121. package/dist/lifecycle/ResourceVersioning.d.ts +0 -73
  122. package/dist/lifecycle/ResourceVersioning.js +0 -127
  123. package/dist/migration/MigrationManager.d.ts +0 -86
  124. package/dist/migration/MigrationManager.js +0 -412
  125. package/dist/migration/audit/AuditLogger.d.ts +0 -51
  126. package/dist/migration/audit/AuditLogger.js +0 -156
  127. package/dist/migration/checkpoint/CheckpointManager.d.ts +0 -31
  128. package/dist/migration/checkpoint/CheckpointManager.js +0 -96
  129. package/dist/migration/checkpoint/CheckpointStorage.d.ts +0 -26
  130. package/dist/migration/checkpoint/CheckpointStorage.js +0 -89
  131. package/dist/migration/index.d.ts +0 -22
  132. package/dist/migration/index.js +0 -27
  133. package/dist/migration/operations/BaseMigration.d.ts +0 -48
  134. package/dist/migration/operations/BaseMigration.js +0 -83
  135. package/dist/migration/operations/PeerToBtcoMigration.d.ts +0 -25
  136. package/dist/migration/operations/PeerToBtcoMigration.js +0 -67
  137. package/dist/migration/operations/PeerToWebvhMigration.d.ts +0 -19
  138. package/dist/migration/operations/PeerToWebvhMigration.js +0 -46
  139. package/dist/migration/operations/WebvhToBtcoMigration.d.ts +0 -25
  140. package/dist/migration/operations/WebvhToBtcoMigration.js +0 -67
  141. package/dist/migration/rollback/RollbackManager.d.ts +0 -29
  142. package/dist/migration/rollback/RollbackManager.js +0 -146
  143. package/dist/migration/state/StateMachine.d.ts +0 -25
  144. package/dist/migration/state/StateMachine.js +0 -76
  145. package/dist/migration/state/StateTracker.d.ts +0 -36
  146. package/dist/migration/state/StateTracker.js +0 -123
  147. package/dist/migration/types.d.ts +0 -306
  148. package/dist/migration/types.js +0 -33
  149. package/dist/migration/validation/BitcoinValidator.d.ts +0 -13
  150. package/dist/migration/validation/BitcoinValidator.js +0 -83
  151. package/dist/migration/validation/CredentialValidator.d.ts +0 -13
  152. package/dist/migration/validation/CredentialValidator.js +0 -46
  153. package/dist/migration/validation/DIDCompatibilityValidator.d.ts +0 -16
  154. package/dist/migration/validation/DIDCompatibilityValidator.js +0 -127
  155. package/dist/migration/validation/LifecycleValidator.d.ts +0 -10
  156. package/dist/migration/validation/LifecycleValidator.js +0 -52
  157. package/dist/migration/validation/StorageValidator.d.ts +0 -10
  158. package/dist/migration/validation/StorageValidator.js +0 -65
  159. package/dist/migration/validation/ValidationPipeline.d.ts +0 -29
  160. package/dist/migration/validation/ValidationPipeline.js +0 -180
  161. package/dist/storage/LocalStorageAdapter.d.ts +0 -11
  162. package/dist/storage/LocalStorageAdapter.js +0 -53
  163. package/dist/storage/MemoryStorageAdapter.d.ts +0 -6
  164. package/dist/storage/MemoryStorageAdapter.js +0 -21
  165. package/dist/storage/StorageAdapter.d.ts +0 -16
  166. package/dist/storage/StorageAdapter.js +0 -1
  167. package/dist/storage/index.d.ts +0 -2
  168. package/dist/storage/index.js +0 -2
  169. package/dist/types/bitcoin.d.ts +0 -84
  170. package/dist/types/bitcoin.js +0 -1
  171. package/dist/types/common.d.ts +0 -82
  172. package/dist/types/common.js +0 -1
  173. package/dist/types/credentials.d.ts +0 -75
  174. package/dist/types/credentials.js +0 -1
  175. package/dist/types/did.d.ts +0 -26
  176. package/dist/types/did.js +0 -1
  177. package/dist/types/index.d.ts +0 -5
  178. package/dist/types/index.js +0 -5
  179. package/dist/types/network.d.ts +0 -78
  180. package/dist/types/network.js +0 -145
  181. package/dist/utils/EventLogger.d.ts +0 -71
  182. package/dist/utils/EventLogger.js +0 -232
  183. package/dist/utils/Logger.d.ts +0 -106
  184. package/dist/utils/Logger.js +0 -257
  185. package/dist/utils/MetricsCollector.d.ts +0 -110
  186. package/dist/utils/MetricsCollector.js +0 -264
  187. package/dist/utils/bitcoin-address.d.ts +0 -38
  188. package/dist/utils/bitcoin-address.js +0 -113
  189. package/dist/utils/cbor.d.ts +0 -2
  190. package/dist/utils/cbor.js +0 -9
  191. package/dist/utils/encoding.d.ts +0 -37
  192. package/dist/utils/encoding.js +0 -120
  193. package/dist/utils/hash.d.ts +0 -1
  194. package/dist/utils/hash.js +0 -5
  195. package/dist/utils/retry.d.ts +0 -10
  196. package/dist/utils/retry.js +0 -35
  197. package/dist/utils/satoshi-validation.d.ts +0 -60
  198. package/dist/utils/satoshi-validation.js +0 -156
  199. package/dist/utils/serialization.d.ts +0 -14
  200. package/dist/utils/serialization.js +0 -76
  201. package/dist/utils/telemetry.d.ts +0 -17
  202. package/dist/utils/telemetry.js +0 -24
  203. package/dist/utils/validation.d.ts +0 -5
  204. package/dist/utils/validation.js +0 -98
  205. package/dist/vc/CredentialManager.d.ts +0 -22
  206. package/dist/vc/CredentialManager.js +0 -227
  207. package/dist/vc/Issuer.d.ts +0 -27
  208. package/dist/vc/Issuer.js +0 -70
  209. package/dist/vc/Verifier.d.ts +0 -16
  210. package/dist/vc/Verifier.js +0 -50
  211. package/dist/vc/cryptosuites/bbs.d.ts +0 -44
  212. package/dist/vc/cryptosuites/bbs.js +0 -213
  213. package/dist/vc/cryptosuites/bbsSimple.d.ts +0 -9
  214. package/dist/vc/cryptosuites/bbsSimple.js +0 -12
  215. package/dist/vc/cryptosuites/eddsa.d.ts +0 -30
  216. package/dist/vc/cryptosuites/eddsa.js +0 -81
  217. package/dist/vc/documentLoader.d.ts +0 -16
  218. package/dist/vc/documentLoader.js +0 -59
  219. package/dist/vc/proofs/data-integrity.d.ts +0 -21
  220. package/dist/vc/proofs/data-integrity.js +0 -15
  221. package/dist/vc/utils/jsonld.d.ts +0 -2
  222. package/dist/vc/utils/jsonld.js +0 -15
  223. package/test/logs/did_webvh_QmNTn9Kkp8dQ75WrF9xqJ2kuDp9QhKc3aPiERRMj8XoTBN_example_com.jsonl +0 -1
  224. package/test/logs/did_webvh_QmNu4MNr8Lr5txx5gYNhuhZDchXsZEu3hJXKYuphpWTPDp_example_com_users_etc_passwd.jsonl +0 -1
  225. package/test/logs/did_webvh_QmR9MrGZACzjKETA8SBRNCKG11HxU85c4bVR2qN5eDCfsD_example_com.jsonl +0 -1
  226. package/test/logs/did_webvh_QmUc5suaqRM2P4nrXxZwqYMfqzhdMqjuL7oJaJbEpCQVCd_example_com_users_etc_passwd.jsonl +0 -1
  227. package/test/logs/did_webvh_QmUkiB2RCV2VZ1RTXsCebWN25Eiy9TLvpzDWAJNjhgvB4X_example_com_etc_passwd.jsonl +0 -1
  228. package/test/logs/did_webvh_QmUoRTe8UMwpAQXZSAW7pjAgZK1tq2X3C6Kfxq3UXGcaGy_example_com_secret.jsonl +0 -1
  229. package/test/logs/did_webvh_QmWWot3chx1t6KwTmcE5i2FeDZ5JMkQw3qXycsKDVmJ9Be_example_com_users_alice.jsonl +0 -1
  230. package/test/logs/did_webvh_QmWvVgALL5kjZdpgR7KZay7J8UiiUr834kkRmWeFAxjAuC_example_com_users_etc_passwd.jsonl +0 -1
  231. package/test/logs/did_webvh_QmWwaRQHUZAFcKihFC6xR6tRTTrQhHPTku6azf1egWbpy1_example_com_users_alice.jsonl +0 -1
  232. package/test/logs/did_webvh_QmXJLtkz23r7AozbtXsZMKWnVU6rd38CkVtjdWuATU3Yp6_example_com_users_alice123_profile.jsonl +0 -1
  233. package/test/logs/did_webvh_QmYsce448po14oDE1wXbyaP6wY9HQgHSKLwdezn1k577SF_example_com_my_org_user_name_test_123.jsonl +0 -1
  234. package/test/logs/did_webvh_QmZBeNzzqajxdfwcDUPZ4P8C5YSXyRztrAwmPiKuKUxmAK_example_com.jsonl +0 -1
  235. package/test/logs/did_webvh_QmZhJsqxizwVbRtqCUkmE6XQunSxtxMt3gbTYadVBNAaEq_example_com.jsonl +0 -1
  236. package/test/logs/did_webvh_QmZk7NHU2D57RzzbMq4tWW9gBa9AqtVTWfiRM6RFdwGVj2_example_com.jsonl +0 -1
  237. package/test/logs/did_webvh_QmZshSXp9w8ovH62zGGBS1b5pGGPsuYiu1VQ935sga2hWF_example_com_level1_level2.jsonl +0 -1
  238. package/test/logs/did_webvh_QmbWAmw7HQL7vKJyCsctZihXf1rmT4sGvggKCPKWcUWjw1_example_com.jsonl +0 -1
  239. package/test/logs/did_webvh_QmbdLUMbYs3juR39TLB6hhrFWLcNg45ybUzeBJCS1MhCh1_example_com_C_Windows_System32.jsonl +0 -1
  240. package/test/logs/did_webvh_QmcaQ1Ma4gkSbae85aCm8Mv4rvdT2Sb2RR3JzYwrm5XBq8_example_com_etc_passwd.jsonl +0 -1
  241. package/test/logs/did_webvh_QmcbA7WQhsBqZSoDpKJHjV8Q5o53h8vmgJhQfo6rqTY5ho_example_com.jsonl +0 -1
  242. package/test/logs/did_webvh_Qmdy8uWr2gkUJrXsThynAug3DASTWwb3onEj89LKmMGZYB_example_com.jsonl +0 -1
  243. package/tests/e2e/README.md +0 -97
  244. package/tests/e2e/example.spec.ts +0 -78
@@ -0,0 +1,514 @@
1
+ /**
2
+ * Example: Full Lifecycle Flow
3
+ *
4
+ * This comprehensive example demonstrates the complete lifecycle of an Original:
5
+ *
6
+ * 1. Create a draft (did:peer) - Private, offline creation
7
+ * 2. Validate and estimate costs
8
+ * 3. Publish to web (did:webvh) - Public discovery
9
+ * 4. Inscribe on Bitcoin (did:btco) - Permanent ownership
10
+ * 5. Transfer ownership
11
+ * 6. Track provenance throughout
12
+ *
13
+ * This example uses the clean lifecycle API with progress callbacks.
14
+ */
15
+
16
+ import {
17
+ OriginalsSDK,
18
+ OrdMockProvider,
19
+ ResourceManager,
20
+ OriginalKind,
21
+ type LifecycleProgress,
22
+ type OriginalsAsset,
23
+ type CostEstimate,
24
+ type MigrationValidation
25
+ } from '../index';
26
+ import { sha256 } from '@noble/hashes/sha2.js';
27
+
28
+ /**
29
+ * Helper to compute content hash
30
+ */
31
+ function computeHash(content: string | Buffer): string {
32
+ const buffer = typeof content === 'string' ? Buffer.from(content) : content;
33
+ return Buffer.from(sha256(buffer)).toString('hex');
34
+ }
35
+
36
+ /**
37
+ * Progress logger for lifecycle operations
38
+ */
39
+ function createProgressLogger(_operation: string) {
40
+ return (progress: LifecycleProgress) => {
41
+ const bar = '█'.repeat(Math.floor(progress.percentage / 5)) + '░'.repeat(20 - Math.floor(progress.percentage / 5));
42
+ console.log(` [${bar}] ${progress.percentage}% - ${progress.phase}: ${progress.message}`);
43
+ if (progress.details?.transactionId) {
44
+ console.log(` Transaction: ${progress.details.transactionId}`);
45
+ }
46
+ };
47
+ }
48
+
49
+ /**
50
+ * Initialize SDK with all necessary providers
51
+ */
52
+ function initializeSDK(): OriginalsSDK {
53
+ return OriginalsSDK.create({
54
+ network: 'regtest',
55
+ defaultKeyType: 'Ed25519',
56
+ webvhNetwork: 'magby',
57
+ ordinalsProvider: new OrdMockProvider(),
58
+ enableLogging: false,
59
+ });
60
+ }
61
+
62
+ /**
63
+ * Step 1: Create resources using ResourceManager
64
+ */
65
+ function createResources(resourceManager: ResourceManager): void {
66
+ console.log('\n📁 STEP 1: Creating Resources with ResourceManager\n');
67
+
68
+ // Create main content
69
+ const mainContent = `
70
+ # My Digital Artwork
71
+
72
+ This is a unique digital creation that will be permanently recorded
73
+ on the Bitcoin blockchain.
74
+
75
+ ## Description
76
+
77
+ A beautiful generative art piece created with mathematical precision.
78
+
79
+ ## Attribution
80
+
81
+ Created by: Artist Name
82
+ Date: ${new Date().toISOString()}
83
+ `.trim();
84
+
85
+ // Create the resource
86
+ const mainResource = resourceManager.createResource(mainContent, {
87
+ id: 'content.md',
88
+ type: 'document',
89
+ contentType: 'text/markdown',
90
+ description: 'Main artwork description'
91
+ });
92
+
93
+ console.log('Created resource:');
94
+ console.log(` ID: ${mainResource.id}`);
95
+ console.log(` Type: ${mainResource.type}`);
96
+ console.log(` Content Type: ${mainResource.contentType}`);
97
+ console.log(` Hash: ${mainResource.hash.substring(0, 16)}...`);
98
+ console.log(` Size: ${mainResource.size} bytes`);
99
+ console.log(` Version: ${mainResource.version}`);
100
+
101
+ // Update the resource (creates version 2)
102
+ const updatedContent = mainContent + '\n\n## Update\n\nAdded additional metadata.';
103
+ const v2Resource = resourceManager.updateResource(mainResource, updatedContent, {
104
+ changes: 'Added update section with additional metadata'
105
+ });
106
+
107
+ console.log('\nUpdated resource (new version):');
108
+ console.log(` Version: ${v2Resource.version}`);
109
+ console.log(` Previous Hash: ${v2Resource.previousVersionHash?.substring(0, 16)}...`);
110
+ console.log(` New Hash: ${v2Resource.hash.substring(0, 16)}...`);
111
+
112
+ // Verify the version chain
113
+ const chainValidation = resourceManager.verifyVersionChain(mainResource.id);
114
+ console.log(`\nVersion chain validation: ${chainValidation.valid ? '✓ Valid' : '✗ Invalid'}`);
115
+ if (chainValidation.warnings.length > 0) {
116
+ console.log(' Warnings:', chainValidation.warnings.join(', '));
117
+ }
118
+ }
119
+
120
+ /**
121
+ * Step 2: Create a draft asset (did:peer layer)
122
+ */
123
+ async function createDraft(sdk: OriginalsSDK): Promise<OriginalsAsset> {
124
+ console.log('\n📝 STEP 2: Creating Draft Asset (did:peer)\n');
125
+
126
+ const content = `
127
+ {
128
+ "title": "Genesis Artwork #001",
129
+ "artist": "Digital Creator",
130
+ "medium": "Generative Algorithm",
131
+ "created": "${new Date().toISOString()}",
132
+ "description": "A unique piece of digital art inscribed forever on Bitcoin"
133
+ }
134
+ `.trim();
135
+
136
+ const resources = [{
137
+ id: 'metadata.json',
138
+ type: 'data',
139
+ content,
140
+ contentType: 'application/json',
141
+ hash: computeHash(content),
142
+ size: content.length,
143
+ }];
144
+
145
+ // Create draft with progress tracking
146
+ const draft = await sdk.lifecycle.createDraft(resources, {
147
+ onProgress: createProgressLogger('Create Draft'),
148
+ });
149
+
150
+ console.log('\nDraft created:');
151
+ console.log(` Asset ID: ${draft.id}`);
152
+ console.log(` Current Layer: ${draft.currentLayer}`);
153
+ console.log(` Resources: ${draft.resources.length}`);
154
+
155
+ // Check provenance
156
+ const provenance = draft.getProvenance();
157
+ console.log(` Created At: ${provenance.createdAt}`);
158
+ console.log(` Creator: ${provenance.creator.substring(0, 30)}...`);
159
+
160
+ return draft;
161
+ }
162
+
163
+ /**
164
+ * Step 3: Validate migration and estimate costs
165
+ */
166
+ async function validateAndEstimate(sdk: OriginalsSDK, asset: OriginalsAsset): Promise<void> {
167
+ console.log('\n🔍 STEP 3: Validating Migration & Estimating Costs\n');
168
+
169
+ // Validate migration to did:webvh
170
+ console.log('Validating migration to did:webvh:');
171
+ const webvhValidation = await sdk.lifecycle.validateMigration(asset, 'did:webvh');
172
+ printValidation(webvhValidation);
173
+
174
+ // Validate migration to did:btco
175
+ console.log('\nValidating migration to did:btco:');
176
+ const btcoValidation = await sdk.lifecycle.validateMigration(asset, 'did:btco');
177
+ printValidation(btcoValidation);
178
+
179
+ // Estimate costs for Bitcoin inscription
180
+ console.log('\nCost estimates for Bitcoin inscription:');
181
+ const feeRates = [1, 5, 10, 25, 50];
182
+ for (const feeRate of feeRates) {
183
+ const estimate = await sdk.lifecycle.estimateCost(asset, 'did:btco', feeRate);
184
+ printCostEstimate(estimate, feeRate);
185
+ }
186
+ }
187
+
188
+ function printValidation(validation: MigrationValidation): void {
189
+ console.log(` Valid: ${validation.valid ? '✓' : '✗'}`);
190
+ console.log(` Current Layer: ${validation.currentLayer}`);
191
+ console.log(` Target Layer: ${validation.targetLayer}`);
192
+ console.log(' Checks:');
193
+ Object.entries(validation.checks).forEach(([check, passed]) => {
194
+ if (passed !== undefined) {
195
+ console.log(` - ${check}: ${passed ? '✓' : '✗'}`);
196
+ }
197
+ });
198
+ if (validation.errors.length > 0) {
199
+ console.log(' Errors:', validation.errors.join(', '));
200
+ }
201
+ if (validation.warnings.length > 0) {
202
+ console.log(' Warnings:', validation.warnings.join(', '));
203
+ }
204
+ }
205
+
206
+ function printCostEstimate(estimate: CostEstimate, feeRate: number): void {
207
+ console.log(` ${feeRate} sat/vB:`);
208
+ console.log(` Total: ${estimate.totalSats} sats (~$${(estimate.totalSats * 0.0006).toFixed(4)} @ $60k/BTC)`);
209
+ console.log(` Breakdown: network=${estimate.breakdown.networkFee}, data=${estimate.breakdown.dataCost}, dust=${estimate.breakdown.dustValue}`);
210
+ console.log(` Confidence: ${estimate.confidence}`);
211
+ }
212
+
213
+ /**
214
+ * Step 4: Publish to web (did:webvh layer)
215
+ */
216
+ async function publishToWeb(sdk: OriginalsSDK, asset: OriginalsAsset): Promise<OriginalsAsset> {
217
+ console.log('\n🌐 STEP 4: Publishing to Web (did:webvh)\n');
218
+
219
+ // Subscribe to migration events
220
+ const unsubscribe = asset.on('asset:migrated', (event) => {
221
+ const migrationEvent = event as { asset: { fromLayer: string; toLayer: string } };
222
+ console.log(` 🔔 Event: Migrated from ${migrationEvent.asset.fromLayer} to ${migrationEvent.asset.toLayer}`);
223
+ });
224
+
225
+ try {
226
+ const published = await sdk.lifecycle.publish(
227
+ asset,
228
+ 'did:webvh:magby.originals.build:example:artwork',
229
+ {
230
+ onProgress: createProgressLogger('Publish'),
231
+ }
232
+ );
233
+
234
+ console.log('\nPublished to web:');
235
+ console.log(` Asset ID: ${published.id}`);
236
+ console.log(` Current Layer: ${published.currentLayer}`);
237
+ console.log(` Bindings: ${JSON.stringify(published.bindings || {})}`);
238
+
239
+ // Check provenance after migration
240
+ const provenance = published.getProvenance();
241
+ console.log(` Migrations: ${provenance.migrations.length}`);
242
+
243
+ if (provenance.migrations.length > 0) {
244
+ const lastMigration = provenance.migrations[provenance.migrations.length - 1];
245
+ console.log(` Last migration: ${lastMigration.from} → ${lastMigration.to} at ${lastMigration.timestamp}`);
246
+ }
247
+
248
+ // Check credentials
249
+ console.log(` Credentials: ${published.credentials.length}`);
250
+ published.credentials.forEach((cred, i) => {
251
+ console.log(` ${i + 1}. Type: ${cred.type.join(', ')}`);
252
+ });
253
+
254
+ return published;
255
+ } finally {
256
+ unsubscribe();
257
+ }
258
+ }
259
+
260
+ /**
261
+ * Step 5: Inscribe on Bitcoin (did:btco layer)
262
+ */
263
+ async function inscribeOnBitcoin(sdk: OriginalsSDK, asset: OriginalsAsset): Promise<OriginalsAsset> {
264
+ console.log('\n₿ STEP 5: Inscribing on Bitcoin (did:btco)\n');
265
+
266
+ // Subscribe to migration events
267
+ asset.on('asset:migrated', (_event) => {
268
+ console.log(` 🔔 Event: Inscribed on Bitcoin`);
269
+ });
270
+
271
+ const inscribed = await sdk.lifecycle.inscribe(asset, {
272
+ feeRate: 10,
273
+ onProgress: createProgressLogger('Inscribe'),
274
+ });
275
+
276
+ console.log('\nInscribed on Bitcoin:');
277
+ console.log(` Asset ID: ${inscribed.id}`);
278
+ console.log(` Current Layer: ${inscribed.currentLayer}`);
279
+ console.log(` Bindings: ${JSON.stringify(inscribed.bindings || {})}`);
280
+
281
+ // Check provenance after inscription
282
+ const provenance = inscribed.getProvenance();
283
+ console.log(` Total migrations: ${provenance.migrations.length}`);
284
+
285
+ const btcoMigration = provenance.migrations.find(m => m.to === 'did:btco');
286
+ if (btcoMigration) {
287
+ console.log('\n Bitcoin inscription details:');
288
+ console.log(` Transaction ID: ${btcoMigration.transactionId || 'N/A'}`);
289
+ console.log(` Inscription ID: ${btcoMigration.inscriptionId || 'N/A'}`);
290
+ console.log(` Satoshi: ${btcoMigration.satoshi || 'N/A'}`);
291
+ console.log(` Fee Rate: ${btcoMigration.feeRate || 'N/A'} sat/vB`);
292
+ console.log(` Commit TX: ${btcoMigration.commitTxId || 'N/A'}`);
293
+ console.log(` Reveal TX: ${btcoMigration.revealTxId || 'N/A'}`);
294
+ }
295
+
296
+ return inscribed;
297
+ }
298
+
299
+ /**
300
+ * Step 6: Transfer ownership
301
+ */
302
+ async function transferOwnership(sdk: OriginalsSDK, asset: OriginalsAsset): Promise<void> {
303
+ console.log('\n🔄 STEP 6: Transferring Ownership\n');
304
+
305
+ // New owner address (mock address for regtest)
306
+ const newOwner = 'bcrt1qnewowner123456789abcdef';
307
+
308
+ // Subscribe to transfer events
309
+ asset.on('asset:transferred', (event) => {
310
+ const transferEvent = event as { to: string };
311
+ console.log(` 🔔 Event: Ownership transferred to ${transferEvent.to}`);
312
+ });
313
+
314
+ const tx = await sdk.lifecycle.transfer(asset, newOwner, {
315
+ onProgress: createProgressLogger('Transfer'),
316
+ });
317
+
318
+ console.log('\nOwnership transferred:');
319
+ console.log(` Transaction ID: ${tx.txid}`);
320
+ console.log(` New Owner: ${newOwner}`);
321
+ console.log(` Fee: ${tx.fee} sats`);
322
+
323
+ // Check final provenance
324
+ const provenance = asset.getProvenance();
325
+ console.log(`\n Transfer history: ${provenance.transfers.length} transfer(s)`);
326
+ provenance.transfers.forEach((transfer, i) => {
327
+ console.log(` ${i + 1}. ${transfer.from.substring(0, 20)}... → ${transfer.to.substring(0, 20)}...`);
328
+ console.log(` TX: ${transfer.transactionId}`);
329
+ console.log(` At: ${transfer.timestamp}`);
330
+ });
331
+ }
332
+
333
+ /**
334
+ * Step 7: View complete provenance
335
+ */
336
+ function viewProvenance(asset: OriginalsAsset): void {
337
+ console.log('\n📜 STEP 7: Complete Provenance Chain\n');
338
+
339
+ const provenance = asset.getProvenance();
340
+ const summary = asset.getProvenanceSummary();
341
+
342
+ console.log('Provenance Summary:');
343
+ console.log(` Created: ${summary.created}`);
344
+ console.log(` Creator: ${summary.creator.substring(0, 40)}...`);
345
+ console.log(` Current Layer: ${summary.currentLayer}`);
346
+ console.log(` Migration Count: ${summary.migrationCount}`);
347
+ console.log(` Transfer Count: ${summary.transferCount}`);
348
+ console.log(` Last Activity: ${summary.lastActivity}`);
349
+
350
+ console.log('\nMigration History:');
351
+ provenance.migrations.forEach((migration, i) => {
352
+ console.log(` ${i + 1}. ${migration.from} → ${migration.to}`);
353
+ console.log(` Timestamp: ${migration.timestamp}`);
354
+ if (migration.transactionId) {
355
+ console.log(` TX: ${migration.transactionId}`);
356
+ }
357
+ if (migration.inscriptionId) {
358
+ console.log(` Inscription: ${migration.inscriptionId}`);
359
+ }
360
+ });
361
+
362
+ console.log('\nTransfer History:');
363
+ if (provenance.transfers.length === 0) {
364
+ console.log(' No transfers recorded');
365
+ } else {
366
+ provenance.transfers.forEach((transfer, i) => {
367
+ console.log(` ${i + 1}. ${transfer.timestamp}`);
368
+ console.log(` From: ${transfer.from}`);
369
+ console.log(` To: ${transfer.to}`);
370
+ console.log(` TX: ${transfer.transactionId}`);
371
+ });
372
+ }
373
+
374
+ console.log('\nResource Updates:');
375
+ if (provenance.resourceUpdates.length === 0) {
376
+ console.log(' No resource updates recorded');
377
+ } else {
378
+ provenance.resourceUpdates.forEach((update, i) => {
379
+ console.log(` ${i + 1}. Resource: ${update.resourceId}`);
380
+ console.log(` Version: ${update.fromVersion} → ${update.toVersion}`);
381
+ console.log(` At: ${update.timestamp}`);
382
+ });
383
+ }
384
+ }
385
+
386
+ /**
387
+ * Bonus: Create and publish a typed Original
388
+ */
389
+ async function typedOriginalFlow(sdk: OriginalsSDK): Promise<void> {
390
+ console.log('\n🎨 BONUS: Typed Media Original Flow\n');
391
+
392
+ const imageDescription = `
393
+ {
394
+ "title": "Digital Sunrise",
395
+ "artist": "AI Collaborator",
396
+ "medium": "Generative AI + Human Curation",
397
+ "dimensions": "2048x2048",
398
+ "colorSpace": "sRGB"
399
+ }
400
+ `.trim();
401
+
402
+ const mediaAsset = await sdk.lifecycle.createTypedOriginal(
403
+ OriginalKind.Media,
404
+ {
405
+ kind: OriginalKind.Media,
406
+ name: 'Digital Sunrise',
407
+ version: '1.0.0',
408
+ description: 'A stunning generative sunrise created with AI',
409
+ resources: [{
410
+ id: 'metadata.json',
411
+ type: 'data',
412
+ content: imageDescription,
413
+ contentType: 'application/json',
414
+ hash: computeHash(imageDescription),
415
+ size: imageDescription.length,
416
+ }],
417
+ tags: ['generative', 'ai', 'sunrise', 'digital-art'],
418
+ author: {
419
+ name: 'AI Collaborator',
420
+ },
421
+ license: 'CC-BY-4.0',
422
+ metadata: {
423
+ mediaType: 'image',
424
+ mimeType: 'image/png',
425
+ dimensions: {
426
+ width: 2048,
427
+ height: 2048,
428
+ aspectRatio: '1:1',
429
+ },
430
+ altText: 'A vibrant digital sunrise over a futuristic cityscape',
431
+ colorSpace: 'sRGB',
432
+ },
433
+ }
434
+ );
435
+
436
+ console.log('Created Media Original:');
437
+ console.log(` ID: ${mediaAsset.id}`);
438
+ console.log(` Kind: ${OriginalKind.Media}`);
439
+
440
+ // Get the manifest
441
+ const manifest = sdk.lifecycle.getManifest(mediaAsset);
442
+ if (manifest && manifest.metadata) {
443
+ const meta = manifest.metadata as { mediaType?: string; dimensions?: { width: number; height: number } };
444
+ console.log(` Name: ${manifest.name}`);
445
+ console.log(` Media Type: ${meta.mediaType}`);
446
+ console.log(` Dimensions: ${meta.dimensions?.width}x${meta.dimensions?.height}`);
447
+ }
448
+
449
+ // Estimate inscription cost for this typed original
450
+ const cost = await sdk.lifecycle.estimateTypedOriginalCost(manifest!, 'did:btco', 10);
451
+ console.log(`\n Estimated inscription cost: ${cost.totalSats} sats`);
452
+ }
453
+
454
+ /**
455
+ * Main execution - full lifecycle demonstration
456
+ */
457
+ async function main(): Promise<void> {
458
+ console.log('╔════════════════════════════════════════════════════════════════╗');
459
+ console.log('║ ORIGINALS SDK - FULL LIFECYCLE FLOW ║');
460
+ console.log('║ ║');
461
+ console.log('║ did:peer → did:webvh → did:btco → Transfer ║');
462
+ console.log('╚════════════════════════════════════════════════════════════════╝');
463
+
464
+ try {
465
+ // Initialize
466
+ const sdk = initializeSDK();
467
+ const resourceManager = new ResourceManager();
468
+
469
+ // Execute lifecycle steps
470
+ createResources(resourceManager);
471
+
472
+ const draft = await createDraft(sdk);
473
+
474
+ await validateAndEstimate(sdk, draft);
475
+
476
+ const published = await publishToWeb(sdk, draft);
477
+
478
+ const inscribed = await inscribeOnBitcoin(sdk, published);
479
+
480
+ await transferOwnership(sdk, inscribed);
481
+
482
+ viewProvenance(inscribed);
483
+
484
+ await typedOriginalFlow(sdk);
485
+
486
+ console.log('\n╔════════════════════════════════════════════════════════════════╗');
487
+ console.log('║ LIFECYCLE COMPLETE ✓ ║');
488
+ console.log('╚════════════════════════════════════════════════════════════════╝\n');
489
+
490
+ } catch (error) {
491
+ console.error('\n❌ Error during lifecycle flow:', error);
492
+ process.exit(1);
493
+ }
494
+ }
495
+
496
+ // Export for use as module
497
+ export {
498
+ main,
499
+ initializeSDK,
500
+ createResources,
501
+ createDraft,
502
+ validateAndEstimate,
503
+ publishToWeb,
504
+ inscribeOnBitcoin,
505
+ transferOwnership,
506
+ viewProvenance,
507
+ typedOriginalFlow,
508
+ };
509
+
510
+ // Run if executed directly
511
+ if (require.main === module) {
512
+ void main();
513
+ }
514
+
@@ -1,5 +1,60 @@
1
- import { basicExample } from './basic-usage';
2
- import { digitalArtExample } from './basic-usage';
1
+ /**
2
+ * Example Runner
3
+ *
4
+ * Run all SDK examples to demonstrate functionality.
5
+ *
6
+ * Usage:
7
+ * bun run src/examples/run.ts
8
+ * bun run src/examples/run.ts basic
9
+ * bun run src/examples/run.ts module
10
+ * bun run src/examples/run.ts lifecycle
11
+ */
3
12
 
4
- basicExample();
5
- digitalArtExample();
13
+ import { basicExample, digitalArtExample } from './basic-usage';
14
+ import { main as createModuleExample } from './create-module-original';
15
+ import { main as fullLifecycleExample } from './full-lifecycle-flow';
16
+
17
+ async function runAll(): Promise<void> {
18
+ console.log('Running all Originals SDK examples...\n');
19
+
20
+ console.log('='.repeat(60));
21
+ console.log('BASIC USAGE EXAMPLES');
22
+ console.log('='.repeat(60));
23
+ await basicExample();
24
+ await digitalArtExample();
25
+
26
+ console.log('\n' + '='.repeat(60));
27
+ console.log('CREATE MODULE ORIGINAL EXAMPLES');
28
+ console.log('='.repeat(60));
29
+ await createModuleExample();
30
+
31
+ console.log('\n' + '='.repeat(60));
32
+ console.log('FULL LIFECYCLE FLOW EXAMPLE');
33
+ console.log('='.repeat(60));
34
+ await fullLifecycleExample();
35
+
36
+ console.log('\n' + '='.repeat(60));
37
+ console.log('ALL EXAMPLES COMPLETED SUCCESSFULLY');
38
+ console.log('='.repeat(60));
39
+ }
40
+
41
+ async function main(): Promise<void> {
42
+ const arg = process.argv[2];
43
+
44
+ switch (arg) {
45
+ case 'basic':
46
+ await basicExample();
47
+ await digitalArtExample();
48
+ break;
49
+ case 'module':
50
+ await createModuleExample();
51
+ break;
52
+ case 'lifecycle':
53
+ await fullLifecycleExample();
54
+ break;
55
+ default:
56
+ await runAll();
57
+ }
58
+ }
59
+
60
+ main().catch(console.error);
package/src/index.ts CHANGED
@@ -25,8 +25,24 @@ export { DIDManager, type CreateWebVHOptions, type CreateWebVHResult } from './d
25
25
  export { KeyManager } from './did/KeyManager.js';
26
26
  export { Ed25519Verifier } from './did/Ed25519Verifier.js';
27
27
  export * as encoding from './utils/encoding.js';
28
- export { CredentialManager } from './vc/CredentialManager.js';
29
- export { LifecycleManager } from './lifecycle/LifecycleManager.js';
28
+ export {
29
+ CredentialManager,
30
+ type ResourceCreatedSubject,
31
+ type ResourceUpdatedSubject,
32
+ type MigrationSubject,
33
+ type OwnershipSubject,
34
+ type CredentialChainOptions,
35
+ type SelectiveDisclosureOptions,
36
+ type DerivedProofResult
37
+ } from './vc/CredentialManager.js';
38
+ export {
39
+ LifecycleManager,
40
+ type CostEstimate,
41
+ type MigrationValidation,
42
+ type LifecycleProgress,
43
+ type ProgressCallback,
44
+ type LifecycleOperationOptions
45
+ } from './lifecycle/LifecycleManager.js';
30
46
  export { BitcoinManager } from './bitcoin/BitcoinManager.js';
31
47
  export { OrdinalsClient } from './bitcoin/OrdinalsClient.js';
32
48
  export { buildTransferTransaction } from './bitcoin/transfer.js';
@@ -43,6 +59,19 @@ export { BBSCryptosuiteUtils } from './vc/cryptosuites/bbs.js';
43
59
  export { BbsSimple } from './vc/cryptosuites/bbsSimple.js';
44
60
  export * from './storage/index.js';
45
61
 
62
+ // Resource management exports
63
+ export { ResourceManager } from './resources/index.js';
64
+ export type {
65
+ Resource,
66
+ ResourceOptions,
67
+ ResourceUpdateOptions,
68
+ ResourceVersionHistory,
69
+ ResourceManagerConfig,
70
+ ResourceValidationResult,
71
+ ResourceType,
72
+ } from './resources/index.js';
73
+ export { MIME_TYPE_MAP, DEFAULT_RESOURCE_CONFIG } from './resources/index.js';
74
+
46
75
  // Crypto exports
47
76
  export { Signer, ES256KSigner, Ed25519Signer, ES256Signer, Bls12381G2Signer } from './crypto/Signer.js';
48
77
  export { multikey } from './crypto/Multikey.js';
@@ -64,9 +93,46 @@ export {
64
93
  type BatchOperationOptions,
65
94
  type BatchInscriptionOptions,
66
95
  type BatchInscriptionResult,
67
- type ValidationResult
96
+ type ValidationResult as BatchValidationResult
68
97
  } from './lifecycle/BatchOperations.js';
69
98
 
99
+ // Kind system exports
100
+ export {
101
+ OriginalKind,
102
+ KindRegistry,
103
+ type DependencyRef,
104
+ type BaseManifest,
105
+ type AppMetadata,
106
+ type AgentMetadata,
107
+ type ModuleMetadata,
108
+ type DatasetMetadata,
109
+ type MediaMetadata,
110
+ type DocumentMetadata,
111
+ type KindMetadataMap,
112
+ type KindMetadata,
113
+ type OriginalManifest,
114
+ type AppManifest,
115
+ type AgentManifest,
116
+ type ModuleManifest,
117
+ type DatasetManifest,
118
+ type MediaManifest,
119
+ type DocumentManifest,
120
+ type AnyManifest,
121
+ type ValidationResult as KindValidationResult,
122
+ type ValidationError as KindValidationError,
123
+ type ValidationWarning,
124
+ type CreateTypedOriginalOptions,
125
+ type KindValidator,
126
+ BaseKindValidator,
127
+ ValidationUtils,
128
+ AppValidator,
129
+ AgentValidator,
130
+ ModuleValidator,
131
+ DatasetValidator,
132
+ MediaValidator,
133
+ DocumentValidator,
134
+ } from './kinds/index.js';
135
+
70
136
  // Utility exports
71
137
  export * from './utils/validation.js';
72
138
  export * from './utils/satoshi-validation.js';