@originals/sdk 1.8.2 → 1.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/package.json +5 -6
  2. package/src/adapters/FeeOracleMock.ts +0 -9
  3. package/src/adapters/index.ts +0 -5
  4. package/src/adapters/providers/OrdHttpProvider.ts +0 -126
  5. package/src/adapters/providers/OrdMockProvider.ts +0 -101
  6. package/src/adapters/types.ts +0 -66
  7. package/src/bitcoin/BitcoinManager.ts +0 -329
  8. package/src/bitcoin/BroadcastClient.ts +0 -54
  9. package/src/bitcoin/OrdinalsClient.ts +0 -120
  10. package/src/bitcoin/PSBTBuilder.ts +0 -106
  11. package/src/bitcoin/fee-calculation.ts +0 -38
  12. package/src/bitcoin/providers/OrdNodeProvider.ts +0 -92
  13. package/src/bitcoin/providers/OrdinalsProvider.ts +0 -56
  14. package/src/bitcoin/providers/types.ts +0 -59
  15. package/src/bitcoin/transactions/commit.ts +0 -465
  16. package/src/bitcoin/transactions/index.ts +0 -13
  17. package/src/bitcoin/transfer.ts +0 -43
  18. package/src/bitcoin/utxo-selection.ts +0 -322
  19. package/src/bitcoin/utxo.ts +0 -113
  20. package/src/cel/ExternalReferenceManager.ts +0 -87
  21. package/src/cel/OriginalsCel.ts +0 -460
  22. package/src/cel/algorithms/createEventLog.ts +0 -68
  23. package/src/cel/algorithms/deactivateEventLog.ts +0 -109
  24. package/src/cel/algorithms/index.ts +0 -11
  25. package/src/cel/algorithms/updateEventLog.ts +0 -99
  26. package/src/cel/algorithms/verifyEventLog.ts +0 -306
  27. package/src/cel/algorithms/witnessEvent.ts +0 -87
  28. package/src/cel/cli/create.ts +0 -330
  29. package/src/cel/cli/index.ts +0 -383
  30. package/src/cel/cli/inspect.ts +0 -549
  31. package/src/cel/cli/migrate.ts +0 -473
  32. package/src/cel/cli/verify.ts +0 -249
  33. package/src/cel/hash.ts +0 -71
  34. package/src/cel/index.ts +0 -16
  35. package/src/cel/layers/BtcoCelManager.ts +0 -408
  36. package/src/cel/layers/PeerCelManager.ts +0 -371
  37. package/src/cel/layers/WebVHCelManager.ts +0 -361
  38. package/src/cel/layers/index.ts +0 -27
  39. package/src/cel/serialization/cbor.ts +0 -189
  40. package/src/cel/serialization/index.ts +0 -10
  41. package/src/cel/serialization/json.ts +0 -209
  42. package/src/cel/types.ts +0 -160
  43. package/src/cel/witnesses/BitcoinWitness.ts +0 -184
  44. package/src/cel/witnesses/HttpWitness.ts +0 -241
  45. package/src/cel/witnesses/WitnessService.ts +0 -51
  46. package/src/cel/witnesses/index.ts +0 -11
  47. package/src/contexts/credentials-v1.json +0 -237
  48. package/src/contexts/credentials-v2-examples.json +0 -5
  49. package/src/contexts/credentials-v2.json +0 -340
  50. package/src/contexts/credentials.json +0 -237
  51. package/src/contexts/data-integrity-v2.json +0 -81
  52. package/src/contexts/dids.json +0 -58
  53. package/src/contexts/ed255192020.json +0 -93
  54. package/src/contexts/ordinals-plus.json +0 -23
  55. package/src/contexts/originals.json +0 -22
  56. package/src/core/OriginalsSDK.ts +0 -420
  57. package/src/crypto/Multikey.ts +0 -194
  58. package/src/crypto/Signer.ts +0 -262
  59. package/src/crypto/noble-init.ts +0 -138
  60. package/src/did/BtcoDidResolver.ts +0 -231
  61. package/src/did/DIDManager.ts +0 -705
  62. package/src/did/Ed25519Verifier.ts +0 -68
  63. package/src/did/KeyManager.ts +0 -239
  64. package/src/did/WebVHManager.ts +0 -499
  65. package/src/did/createBtcoDidDocument.ts +0 -60
  66. package/src/did/providers/OrdinalsClientProviderAdapter.ts +0 -68
  67. package/src/events/EventEmitter.ts +0 -222
  68. package/src/events/index.ts +0 -19
  69. package/src/events/types.ts +0 -331
  70. package/src/examples/basic-usage.ts +0 -78
  71. package/src/examples/create-module-original.ts +0 -435
  72. package/src/examples/full-lifecycle-flow.ts +0 -514
  73. package/src/examples/run.ts +0 -60
  74. package/src/index.ts +0 -204
  75. package/src/kinds/KindRegistry.ts +0 -320
  76. package/src/kinds/index.ts +0 -74
  77. package/src/kinds/types.ts +0 -470
  78. package/src/kinds/validators/AgentValidator.ts +0 -257
  79. package/src/kinds/validators/AppValidator.ts +0 -211
  80. package/src/kinds/validators/DatasetValidator.ts +0 -242
  81. package/src/kinds/validators/DocumentValidator.ts +0 -311
  82. package/src/kinds/validators/MediaValidator.ts +0 -269
  83. package/src/kinds/validators/ModuleValidator.ts +0 -225
  84. package/src/kinds/validators/base.ts +0 -276
  85. package/src/kinds/validators/index.ts +0 -12
  86. package/src/lifecycle/BatchOperations.ts +0 -381
  87. package/src/lifecycle/LifecycleManager.ts +0 -2156
  88. package/src/lifecycle/OriginalsAsset.ts +0 -524
  89. package/src/lifecycle/ProvenanceQuery.ts +0 -280
  90. package/src/lifecycle/ResourceVersioning.ts +0 -163
  91. package/src/migration/MigrationManager.ts +0 -587
  92. package/src/migration/audit/AuditLogger.ts +0 -176
  93. package/src/migration/checkpoint/CheckpointManager.ts +0 -112
  94. package/src/migration/checkpoint/CheckpointStorage.ts +0 -101
  95. package/src/migration/index.ts +0 -33
  96. package/src/migration/operations/BaseMigration.ts +0 -126
  97. package/src/migration/operations/PeerToBtcoMigration.ts +0 -105
  98. package/src/migration/operations/PeerToWebvhMigration.ts +0 -62
  99. package/src/migration/operations/WebvhToBtcoMigration.ts +0 -105
  100. package/src/migration/rollback/RollbackManager.ts +0 -170
  101. package/src/migration/state/StateMachine.ts +0 -92
  102. package/src/migration/state/StateTracker.ts +0 -156
  103. package/src/migration/types.ts +0 -356
  104. package/src/migration/validation/BitcoinValidator.ts +0 -107
  105. package/src/migration/validation/CredentialValidator.ts +0 -62
  106. package/src/migration/validation/DIDCompatibilityValidator.ts +0 -151
  107. package/src/migration/validation/LifecycleValidator.ts +0 -64
  108. package/src/migration/validation/StorageValidator.ts +0 -79
  109. package/src/migration/validation/ValidationPipeline.ts +0 -213
  110. package/src/resources/ResourceManager.ts +0 -655
  111. package/src/resources/index.ts +0 -21
  112. package/src/resources/types.ts +0 -202
  113. package/src/storage/LocalStorageAdapter.ts +0 -64
  114. package/src/storage/MemoryStorageAdapter.ts +0 -29
  115. package/src/storage/StorageAdapter.ts +0 -25
  116. package/src/storage/index.ts +0 -3
  117. package/src/types/bitcoin.ts +0 -98
  118. package/src/types/common.ts +0 -92
  119. package/src/types/credentials.ts +0 -89
  120. package/src/types/did.ts +0 -31
  121. package/src/types/external-shims.d.ts +0 -53
  122. package/src/types/index.ts +0 -7
  123. package/src/types/network.ts +0 -178
  124. package/src/utils/EventLogger.ts +0 -298
  125. package/src/utils/Logger.ts +0 -324
  126. package/src/utils/MetricsCollector.ts +0 -358
  127. package/src/utils/bitcoin-address.ts +0 -132
  128. package/src/utils/cbor.ts +0 -31
  129. package/src/utils/encoding.ts +0 -135
  130. package/src/utils/hash.ts +0 -12
  131. package/src/utils/retry.ts +0 -46
  132. package/src/utils/satoshi-validation.ts +0 -196
  133. package/src/utils/serialization.ts +0 -102
  134. package/src/utils/telemetry.ts +0 -44
  135. package/src/utils/validation.ts +0 -123
  136. package/src/vc/CredentialManager.ts +0 -955
  137. package/src/vc/Issuer.ts +0 -105
  138. package/src/vc/Verifier.ts +0 -54
  139. package/src/vc/cryptosuites/bbs.ts +0 -253
  140. package/src/vc/cryptosuites/bbsSimple.ts +0 -21
  141. package/src/vc/cryptosuites/eddsa.ts +0 -99
  142. package/src/vc/documentLoader.ts +0 -81
  143. package/src/vc/proofs/data-integrity.ts +0 -33
  144. package/src/vc/utils/jsonld.ts +0 -18
@@ -1,514 +0,0 @@
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 = 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 = 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,60 +0,0 @@
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
- */
12
-
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);