@originals/sdk 1.4.3 → 1.4.5

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 (222) hide show
  1. package/dist/adapters/FeeOracleMock.d.ts +6 -0
  2. package/dist/adapters/FeeOracleMock.js +8 -0
  3. package/dist/adapters/index.d.ts +4 -0
  4. package/dist/adapters/index.js +4 -0
  5. package/dist/adapters/providers/OrdHttpProvider.d.ts +56 -0
  6. package/dist/adapters/providers/OrdHttpProvider.js +110 -0
  7. package/dist/adapters/providers/OrdMockProvider.d.ts +70 -0
  8. package/dist/adapters/providers/OrdMockProvider.js +75 -0
  9. package/dist/adapters/types.d.ts +71 -0
  10. package/dist/adapters/types.js +1 -0
  11. package/dist/bitcoin/BitcoinManager.d.ts +15 -0
  12. package/dist/bitcoin/BitcoinManager.js +262 -0
  13. package/dist/bitcoin/BroadcastClient.d.ts +30 -0
  14. package/dist/bitcoin/BroadcastClient.js +35 -0
  15. package/dist/bitcoin/OrdinalsClient.d.ts +21 -0
  16. package/dist/bitcoin/OrdinalsClient.js +105 -0
  17. package/dist/bitcoin/PSBTBuilder.d.ts +24 -0
  18. package/dist/bitcoin/PSBTBuilder.js +80 -0
  19. package/dist/bitcoin/fee-calculation.d.ts +14 -0
  20. package/dist/bitcoin/fee-calculation.js +31 -0
  21. package/dist/bitcoin/providers/OrdNodeProvider.d.ts +38 -0
  22. package/dist/bitcoin/providers/OrdNodeProvider.js +67 -0
  23. package/dist/bitcoin/providers/OrdinalsProvider.d.ts +33 -0
  24. package/dist/bitcoin/providers/OrdinalsProvider.js +50 -0
  25. package/dist/bitcoin/providers/types.d.ts +63 -0
  26. package/dist/bitcoin/providers/types.js +1 -0
  27. package/dist/bitcoin/transactions/commit.d.ts +89 -0
  28. package/dist/bitcoin/transactions/commit.js +311 -0
  29. package/dist/bitcoin/transactions/index.d.ts +7 -0
  30. package/dist/bitcoin/transactions/index.js +8 -0
  31. package/dist/bitcoin/transfer.d.ts +9 -0
  32. package/dist/bitcoin/transfer.js +26 -0
  33. package/dist/bitcoin/utxo-selection.d.ts +78 -0
  34. package/dist/bitcoin/utxo-selection.js +237 -0
  35. package/dist/bitcoin/utxo.d.ts +26 -0
  36. package/dist/bitcoin/utxo.js +78 -0
  37. package/dist/contexts/credentials-v1.json +195 -0
  38. package/dist/contexts/credentials-v2-examples.json +5 -0
  39. package/dist/contexts/credentials-v2.json +301 -0
  40. package/dist/contexts/credentials.json +195 -0
  41. package/dist/contexts/data-integrity-v2.json +81 -0
  42. package/dist/contexts/dids.json +57 -0
  43. package/dist/contexts/ed255192020.json +93 -0
  44. package/dist/contexts/ordinals-plus.json +23 -0
  45. package/dist/contexts/originals.json +22 -0
  46. package/dist/core/OriginalsSDK.d.ts +158 -0
  47. package/dist/core/OriginalsSDK.js +274 -0
  48. package/dist/crypto/Multikey.d.ts +30 -0
  49. package/dist/crypto/Multikey.js +149 -0
  50. package/dist/crypto/Signer.d.ts +21 -0
  51. package/dist/crypto/Signer.js +196 -0
  52. package/dist/crypto/noble-init.d.ts +18 -0
  53. package/dist/crypto/noble-init.js +106 -0
  54. package/dist/did/BtcoDidResolver.d.ts +57 -0
  55. package/dist/did/BtcoDidResolver.js +166 -0
  56. package/dist/did/DIDManager.d.ts +101 -0
  57. package/dist/did/DIDManager.js +493 -0
  58. package/dist/did/Ed25519Verifier.d.ts +30 -0
  59. package/dist/did/Ed25519Verifier.js +59 -0
  60. package/dist/did/KeyManager.d.ts +17 -0
  61. package/dist/did/KeyManager.js +207 -0
  62. package/dist/did/WebVHManager.d.ts +100 -0
  63. package/dist/did/WebVHManager.js +312 -0
  64. package/dist/did/createBtcoDidDocument.d.ts +10 -0
  65. package/dist/did/createBtcoDidDocument.js +42 -0
  66. package/dist/did/providers/OrdinalsClientProviderAdapter.d.ts +23 -0
  67. package/dist/did/providers/OrdinalsClientProviderAdapter.js +51 -0
  68. package/dist/events/EventEmitter.d.ts +115 -0
  69. package/dist/events/EventEmitter.js +198 -0
  70. package/dist/events/index.d.ts +7 -0
  71. package/dist/events/index.js +6 -0
  72. package/dist/events/types.d.ts +286 -0
  73. package/dist/events/types.js +9 -0
  74. package/dist/examples/basic-usage.d.ts +3 -0
  75. package/dist/examples/basic-usage.js +62 -0
  76. package/dist/examples/create-module-original.d.ts +32 -0
  77. package/dist/examples/create-module-original.js +376 -0
  78. package/dist/examples/full-lifecycle-flow.d.ts +56 -0
  79. package/dist/examples/full-lifecycle-flow.js +419 -0
  80. package/dist/examples/run.d.ts +12 -0
  81. package/dist/examples/run.js +51 -0
  82. package/dist/index.d.ts +43 -0
  83. package/dist/index.js +52 -0
  84. package/dist/kinds/KindRegistry.d.ts +76 -0
  85. package/dist/kinds/KindRegistry.js +216 -0
  86. package/dist/kinds/index.d.ts +33 -0
  87. package/dist/kinds/index.js +36 -0
  88. package/dist/kinds/types.d.ts +363 -0
  89. package/dist/kinds/types.js +25 -0
  90. package/dist/kinds/validators/AgentValidator.d.ts +14 -0
  91. package/dist/kinds/validators/AgentValidator.js +155 -0
  92. package/dist/kinds/validators/AppValidator.d.ts +14 -0
  93. package/dist/kinds/validators/AppValidator.js +135 -0
  94. package/dist/kinds/validators/DatasetValidator.d.ts +14 -0
  95. package/dist/kinds/validators/DatasetValidator.js +148 -0
  96. package/dist/kinds/validators/DocumentValidator.d.ts +14 -0
  97. package/dist/kinds/validators/DocumentValidator.js +180 -0
  98. package/dist/kinds/validators/MediaValidator.d.ts +14 -0
  99. package/dist/kinds/validators/MediaValidator.js +172 -0
  100. package/dist/kinds/validators/ModuleValidator.d.ts +14 -0
  101. package/dist/kinds/validators/ModuleValidator.js +140 -0
  102. package/dist/kinds/validators/base.d.ts +96 -0
  103. package/dist/kinds/validators/base.js +218 -0
  104. package/dist/kinds/validators/index.d.ts +10 -0
  105. package/dist/kinds/validators/index.js +10 -0
  106. package/dist/lifecycle/BatchOperations.d.ts +147 -0
  107. package/dist/lifecycle/BatchOperations.js +251 -0
  108. package/dist/lifecycle/LifecycleManager.d.ts +362 -0
  109. package/dist/lifecycle/LifecycleManager.js +1692 -0
  110. package/dist/lifecycle/OriginalsAsset.d.ts +164 -0
  111. package/dist/lifecycle/OriginalsAsset.js +380 -0
  112. package/dist/lifecycle/ProvenanceQuery.d.ts +126 -0
  113. package/dist/lifecycle/ProvenanceQuery.js +220 -0
  114. package/dist/lifecycle/ResourceVersioning.d.ts +73 -0
  115. package/dist/lifecycle/ResourceVersioning.js +127 -0
  116. package/dist/migration/MigrationManager.d.ts +86 -0
  117. package/dist/migration/MigrationManager.js +412 -0
  118. package/dist/migration/audit/AuditLogger.d.ts +51 -0
  119. package/dist/migration/audit/AuditLogger.js +156 -0
  120. package/dist/migration/checkpoint/CheckpointManager.d.ts +31 -0
  121. package/dist/migration/checkpoint/CheckpointManager.js +96 -0
  122. package/dist/migration/checkpoint/CheckpointStorage.d.ts +26 -0
  123. package/dist/migration/checkpoint/CheckpointStorage.js +89 -0
  124. package/dist/migration/index.d.ts +22 -0
  125. package/dist/migration/index.js +27 -0
  126. package/dist/migration/operations/BaseMigration.d.ts +48 -0
  127. package/dist/migration/operations/BaseMigration.js +83 -0
  128. package/dist/migration/operations/PeerToBtcoMigration.d.ts +25 -0
  129. package/dist/migration/operations/PeerToBtcoMigration.js +67 -0
  130. package/dist/migration/operations/PeerToWebvhMigration.d.ts +19 -0
  131. package/dist/migration/operations/PeerToWebvhMigration.js +46 -0
  132. package/dist/migration/operations/WebvhToBtcoMigration.d.ts +25 -0
  133. package/dist/migration/operations/WebvhToBtcoMigration.js +67 -0
  134. package/dist/migration/rollback/RollbackManager.d.ts +29 -0
  135. package/dist/migration/rollback/RollbackManager.js +146 -0
  136. package/dist/migration/state/StateMachine.d.ts +25 -0
  137. package/dist/migration/state/StateMachine.js +76 -0
  138. package/dist/migration/state/StateTracker.d.ts +36 -0
  139. package/dist/migration/state/StateTracker.js +123 -0
  140. package/dist/migration/types.d.ts +306 -0
  141. package/dist/migration/types.js +33 -0
  142. package/dist/migration/validation/BitcoinValidator.d.ts +13 -0
  143. package/dist/migration/validation/BitcoinValidator.js +83 -0
  144. package/dist/migration/validation/CredentialValidator.d.ts +13 -0
  145. package/dist/migration/validation/CredentialValidator.js +46 -0
  146. package/dist/migration/validation/DIDCompatibilityValidator.d.ts +16 -0
  147. package/dist/migration/validation/DIDCompatibilityValidator.js +127 -0
  148. package/dist/migration/validation/LifecycleValidator.d.ts +10 -0
  149. package/dist/migration/validation/LifecycleValidator.js +52 -0
  150. package/dist/migration/validation/StorageValidator.d.ts +10 -0
  151. package/dist/migration/validation/StorageValidator.js +65 -0
  152. package/dist/migration/validation/ValidationPipeline.d.ts +29 -0
  153. package/dist/migration/validation/ValidationPipeline.js +180 -0
  154. package/dist/resources/ResourceManager.d.ts +231 -0
  155. package/dist/resources/ResourceManager.js +573 -0
  156. package/dist/resources/index.d.ts +11 -0
  157. package/dist/resources/index.js +10 -0
  158. package/dist/resources/types.d.ts +93 -0
  159. package/dist/resources/types.js +80 -0
  160. package/dist/storage/LocalStorageAdapter.d.ts +11 -0
  161. package/dist/storage/LocalStorageAdapter.js +53 -0
  162. package/dist/storage/MemoryStorageAdapter.d.ts +6 -0
  163. package/dist/storage/MemoryStorageAdapter.js +21 -0
  164. package/dist/storage/StorageAdapter.d.ts +16 -0
  165. package/dist/storage/StorageAdapter.js +1 -0
  166. package/dist/storage/index.d.ts +2 -0
  167. package/dist/storage/index.js +2 -0
  168. package/dist/types/bitcoin.d.ts +84 -0
  169. package/dist/types/bitcoin.js +1 -0
  170. package/dist/types/common.d.ts +82 -0
  171. package/dist/types/common.js +1 -0
  172. package/dist/types/credentials.d.ts +75 -0
  173. package/dist/types/credentials.js +1 -0
  174. package/dist/types/did.d.ts +26 -0
  175. package/dist/types/did.js +1 -0
  176. package/dist/types/index.d.ts +5 -0
  177. package/dist/types/index.js +5 -0
  178. package/dist/types/network.d.ts +78 -0
  179. package/dist/types/network.js +145 -0
  180. package/dist/utils/EventLogger.d.ts +71 -0
  181. package/dist/utils/EventLogger.js +232 -0
  182. package/dist/utils/Logger.d.ts +106 -0
  183. package/dist/utils/Logger.js +257 -0
  184. package/dist/utils/MetricsCollector.d.ts +110 -0
  185. package/dist/utils/MetricsCollector.js +264 -0
  186. package/dist/utils/bitcoin-address.d.ts +38 -0
  187. package/dist/utils/bitcoin-address.js +113 -0
  188. package/dist/utils/cbor.d.ts +2 -0
  189. package/dist/utils/cbor.js +9 -0
  190. package/dist/utils/encoding.d.ts +37 -0
  191. package/dist/utils/encoding.js +120 -0
  192. package/dist/utils/hash.d.ts +1 -0
  193. package/dist/utils/hash.js +5 -0
  194. package/dist/utils/retry.d.ts +10 -0
  195. package/dist/utils/retry.js +35 -0
  196. package/dist/utils/satoshi-validation.d.ts +60 -0
  197. package/dist/utils/satoshi-validation.js +156 -0
  198. package/dist/utils/serialization.d.ts +14 -0
  199. package/dist/utils/serialization.js +76 -0
  200. package/dist/utils/telemetry.d.ts +17 -0
  201. package/dist/utils/telemetry.js +24 -0
  202. package/dist/utils/validation.d.ts +5 -0
  203. package/dist/utils/validation.js +98 -0
  204. package/dist/vc/CredentialManager.d.ts +329 -0
  205. package/dist/vc/CredentialManager.js +615 -0
  206. package/dist/vc/Issuer.d.ts +27 -0
  207. package/dist/vc/Issuer.js +70 -0
  208. package/dist/vc/Verifier.d.ts +16 -0
  209. package/dist/vc/Verifier.js +50 -0
  210. package/dist/vc/cryptosuites/bbs.d.ts +44 -0
  211. package/dist/vc/cryptosuites/bbs.js +213 -0
  212. package/dist/vc/cryptosuites/bbsSimple.d.ts +9 -0
  213. package/dist/vc/cryptosuites/bbsSimple.js +12 -0
  214. package/dist/vc/cryptosuites/eddsa.d.ts +30 -0
  215. package/dist/vc/cryptosuites/eddsa.js +81 -0
  216. package/dist/vc/documentLoader.d.ts +16 -0
  217. package/dist/vc/documentLoader.js +59 -0
  218. package/dist/vc/proofs/data-integrity.d.ts +21 -0
  219. package/dist/vc/proofs/data-integrity.js +15 -0
  220. package/dist/vc/utils/jsonld.d.ts +2 -0
  221. package/dist/vc/utils/jsonld.js +15 -0
  222. package/package.json +2 -1
@@ -0,0 +1,3 @@
1
+ declare function basicExample(): Promise<void>;
2
+ declare function digitalArtExample(): Promise<void>;
3
+ export { basicExample, digitalArtExample };
@@ -0,0 +1,62 @@
1
+ import { OriginalsSDK } from '../index';
2
+ async function basicExample() {
3
+ const sdk = OriginalsSDK.create({
4
+ network: 'regtest',
5
+ enableLogging: true,
6
+ // Example uses defaults; provide adapters in your app or tests
7
+ telemetry: {
8
+ onEvent: (e) => console.log('[telemetry]', e.name, e.attributes || {}),
9
+ onError: (err) => console.warn('[error]', err.code, err.message)
10
+ }
11
+ });
12
+ // Create new digital asset
13
+ const resources = [{
14
+ id: 'image-1',
15
+ type: 'image',
16
+ content: 'base64-encoded-image-data',
17
+ contentType: 'image/png',
18
+ hash: 'sha256-hash'
19
+ }];
20
+ try {
21
+ // Create asset in did:peer layer (private, offline)
22
+ const asset = await sdk.lifecycle.createAsset(resources);
23
+ console.log('Created asset:', asset.id);
24
+ console.log('Current layer:', asset.currentLayer); // 'did:peer'
25
+ // Publish to web for discovery (did:webvh layer)
26
+ await sdk.lifecycle.publishToWeb(asset, 'example.com');
27
+ console.log('Published to web, current layer:', asset.currentLayer); // 'did:webvh'
28
+ // Inscribe on Bitcoin for permanent ownership (did:btco layer)
29
+ await sdk.lifecycle.inscribeOnBitcoin(asset);
30
+ console.log('Inscribed on Bitcoin, current layer:', asset.currentLayer); // 'did:btco'
31
+ // Get full provenance chain
32
+ const provenance = asset.getProvenance();
33
+ console.log('Provenance:', provenance);
34
+ // Verify asset integrity
35
+ const isValid = await asset.verify();
36
+ console.log('Asset is valid:', isValid);
37
+ }
38
+ catch (error) {
39
+ console.error('Error:', error);
40
+ }
41
+ }
42
+ async function digitalArtExample() {
43
+ const sdk = OriginalsSDK.create();
44
+ // Artist creates digital artwork
45
+ const artwork = [{
46
+ id: 'artwork-001',
47
+ type: 'image',
48
+ url: 'https://artist-site.com/my-artwork.jpg',
49
+ contentType: 'image/jpeg',
50
+ hash: 'abcd1234...' // SHA-256 hash of image
51
+ }];
52
+ // Create private version for experimentation
53
+ const asset = await sdk.lifecycle.createAsset(artwork);
54
+ // Make discoverable when ready
55
+ await sdk.lifecycle.publishToWeb(asset, 'artist-gallery.com');
56
+ // Inscribe on Bitcoin when sold
57
+ await sdk.lifecycle.inscribeOnBitcoin(asset);
58
+ // Transfer to buyer
59
+ await sdk.lifecycle.transferOwnership(asset, 'buyer-address');
60
+ }
61
+ // Export examples
62
+ export { basicExample, digitalArtExample };
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Example: Creating a Module Original
3
+ *
4
+ * This example demonstrates how to create a typed Module Original using
5
+ * the Originals SDK's Kind system. Module Originals are reusable code
6
+ * packages with explicit exports, dependencies, and metadata.
7
+ */
8
+ /**
9
+ * Create a simple Module Original
10
+ */
11
+ declare function createSimpleModule(): Promise<void>;
12
+ /**
13
+ * Create a Module Original with dependencies
14
+ */
15
+ declare function createModuleWithDependencies(): Promise<void>;
16
+ /**
17
+ * Validate a module manifest before creation
18
+ */
19
+ declare function validateModuleManifest(): void;
20
+ /**
21
+ * Estimate costs for module inscription
22
+ */
23
+ declare function estimateModuleCosts(): Promise<void>;
24
+ /**
25
+ * Create templates using KindRegistry
26
+ */
27
+ declare function useModuleTemplates(): void;
28
+ /**
29
+ * Main execution
30
+ */
31
+ declare function main(): Promise<void>;
32
+ export { createSimpleModule, createModuleWithDependencies, validateModuleManifest, estimateModuleCosts, useModuleTemplates, main };
@@ -0,0 +1,376 @@
1
+ /**
2
+ * Example: Creating a Module Original
3
+ *
4
+ * This example demonstrates how to create a typed Module Original using
5
+ * the Originals SDK's Kind system. Module Originals are reusable code
6
+ * packages with explicit exports, dependencies, and metadata.
7
+ */
8
+ import { OriginalsSDK, OriginalKind, OrdMockProvider, KindRegistry } from '../index';
9
+ import { sha256 } from '@noble/hashes/sha2.js';
10
+ /**
11
+ * Helper to compute content hash
12
+ */
13
+ function computeHash(content) {
14
+ return Buffer.from(sha256(Buffer.from(content))).toString('hex');
15
+ }
16
+ /**
17
+ * Create a simple Module Original
18
+ */
19
+ async function createSimpleModule() {
20
+ console.log('=== Creating a Simple Module Original ===\n');
21
+ // Initialize SDK
22
+ const sdk = OriginalsSDK.create({
23
+ network: 'regtest',
24
+ defaultKeyType: 'Ed25519',
25
+ webvhNetwork: 'magby',
26
+ ordinalsProvider: new OrdMockProvider(),
27
+ });
28
+ // Define module source code
29
+ const moduleCode = `
30
+ /**
31
+ * A simple greeting utility module
32
+ */
33
+
34
+ /**
35
+ * Generate a personalized greeting
36
+ * @param name - The name to greet
37
+ * @returns A friendly greeting string
38
+ */
39
+ export function greet(name) {
40
+ return \`Hello, \${name}! Welcome to Originals.\`;
41
+ }
42
+
43
+ /**
44
+ * Generate a farewell message
45
+ * @param name - The name to say goodbye to
46
+ * @returns A farewell string
47
+ */
48
+ export function farewell(name) {
49
+ return \`Goodbye, \${name}! See you soon.\`;
50
+ }
51
+
52
+ /**
53
+ * Get a random greeting from a list
54
+ * @returns A random greeting string
55
+ */
56
+ export function randomGreeting() {
57
+ const greetings = ['Hey!', 'Hi there!', 'Howdy!', 'Welcome!', 'Greetings!'];
58
+ return greetings[Math.floor(Math.random() * greetings.length)];
59
+ }
60
+ `.trim();
61
+ // Define TypeScript type definitions
62
+ const typeDefs = `
63
+ /**
64
+ * Type definitions for greeting-utils module
65
+ */
66
+
67
+ /**
68
+ * Generate a personalized greeting
69
+ */
70
+ export declare function greet(name: string): string;
71
+
72
+ /**
73
+ * Generate a farewell message
74
+ */
75
+ export declare function farewell(name: string): string;
76
+
77
+ /**
78
+ * Get a random greeting from a list
79
+ */
80
+ export declare function randomGreeting(): string;
81
+ `.trim();
82
+ // Create resources
83
+ const resources = [
84
+ {
85
+ id: 'index.js',
86
+ type: 'code',
87
+ content: moduleCode,
88
+ contentType: 'application/javascript',
89
+ hash: computeHash(moduleCode),
90
+ size: moduleCode.length,
91
+ },
92
+ {
93
+ id: 'index.d.ts',
94
+ type: 'code',
95
+ content: typeDefs,
96
+ contentType: 'application/typescript',
97
+ hash: computeHash(typeDefs),
98
+ size: typeDefs.length,
99
+ },
100
+ ];
101
+ // Create typed Module Original
102
+ const moduleAsset = await sdk.lifecycle.createTypedOriginal(OriginalKind.Module, {
103
+ kind: OriginalKind.Module,
104
+ name: 'greeting-utils',
105
+ version: '1.0.0',
106
+ description: 'A simple greeting utility module for generating personalized messages',
107
+ resources,
108
+ tags: ['utility', 'greeting', 'message', 'text'],
109
+ author: {
110
+ name: 'Originals Developer',
111
+ email: 'dev@originals.example',
112
+ },
113
+ license: 'MIT',
114
+ homepage: 'https://github.com/originals/greeting-utils',
115
+ metadata: {
116
+ format: 'esm',
117
+ main: 'index.js',
118
+ types: 'index.d.ts',
119
+ exports: {
120
+ '.': {
121
+ import: './index.js',
122
+ types: './index.d.ts',
123
+ },
124
+ },
125
+ sideEffects: false,
126
+ },
127
+ });
128
+ console.log('Created Module Original:');
129
+ console.log(` ID: ${moduleAsset.id}`);
130
+ console.log(` Layer: ${moduleAsset.currentLayer}`);
131
+ console.log(` Resources: ${moduleAsset.resources.length}`);
132
+ console.log('');
133
+ // Get the manifest back
134
+ const manifest = sdk.lifecycle.getManifest(moduleAsset);
135
+ if (manifest && manifest.metadata) {
136
+ const meta = manifest.metadata;
137
+ console.log('Manifest details:');
138
+ console.log(` Name: ${manifest.name}`);
139
+ console.log(` Version: ${manifest.version}`);
140
+ console.log(` Format: ${meta.format}`);
141
+ console.log(` Main: ${meta.main}`);
142
+ }
143
+ console.log('');
144
+ }
145
+ /**
146
+ * Create a Module Original with dependencies
147
+ */
148
+ async function createModuleWithDependencies() {
149
+ console.log('=== Creating Module with Dependencies ===\n');
150
+ const sdk = OriginalsSDK.create({
151
+ network: 'regtest',
152
+ defaultKeyType: 'Ed25519',
153
+ ordinalsProvider: new OrdMockProvider(),
154
+ });
155
+ // Define module code that depends on another module
156
+ const moduleCode = `
157
+ /**
158
+ * Advanced formatter module that extends greeting-utils
159
+ */
160
+ import { greet, farewell } from 'greeting-utils';
161
+
162
+ /**
163
+ * Format a message with a timestamp
164
+ * @param message - The message to format
165
+ * @returns Formatted message with timestamp
166
+ */
167
+ export function withTimestamp(message) {
168
+ const now = new Date().toISOString();
169
+ return \`[\${now}] \${message}\`;
170
+ }
171
+
172
+ /**
173
+ * Create a welcome message with timestamp
174
+ * @param name - The name to welcome
175
+ * @returns Timestamped welcome message
176
+ */
177
+ export function timedGreeting(name) {
178
+ return withTimestamp(greet(name));
179
+ }
180
+
181
+ /**
182
+ * Create a farewell message with timestamp
183
+ * @param name - The name to say goodbye to
184
+ * @returns Timestamped farewell message
185
+ */
186
+ export function timedFarewell(name) {
187
+ return withTimestamp(farewell(name));
188
+ }
189
+
190
+ /**
191
+ * Format text with various styles
192
+ * @param text - Text to format
193
+ * @param style - Style option: 'upper' | 'lower' | 'title'
194
+ */
195
+ export function formatText(text, style = 'title') {
196
+ switch (style) {
197
+ case 'upper': return text.toUpperCase();
198
+ case 'lower': return text.toLowerCase();
199
+ case 'title': return text.split(' ').map(w => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()).join(' ');
200
+ default: return text;
201
+ }
202
+ }
203
+ `.trim();
204
+ const moduleAsset = await sdk.lifecycle.createTypedOriginal(OriginalKind.Module, {
205
+ kind: OriginalKind.Module,
206
+ name: 'advanced-formatter',
207
+ version: '1.0.0',
208
+ description: 'Advanced text formatting utilities',
209
+ resources: [{
210
+ id: 'index.js',
211
+ type: 'code',
212
+ content: moduleCode,
213
+ contentType: 'application/javascript',
214
+ hash: computeHash(moduleCode),
215
+ size: moduleCode.length,
216
+ }],
217
+ // Declare dependency on greeting-utils
218
+ dependencies: [{
219
+ did: 'did:peer:example-greeting-utils-did',
220
+ name: 'greeting-utils',
221
+ version: '^1.0.0',
222
+ }],
223
+ tags: ['formatter', 'text', 'utility'],
224
+ license: 'MIT',
225
+ metadata: {
226
+ format: 'esm',
227
+ main: 'index.js',
228
+ peerDependencies: {
229
+ 'greeting-utils': '^1.0.0',
230
+ },
231
+ },
232
+ });
233
+ console.log('Created Module with dependencies:');
234
+ console.log(` ID: ${moduleAsset.id}`);
235
+ console.log(` Dependencies: ${moduleAsset.resources.length > 0 ? 'greeting-utils ^1.0.0' : 'none'}`);
236
+ console.log('');
237
+ }
238
+ /**
239
+ * Validate a module manifest before creation
240
+ */
241
+ function validateModuleManifest() {
242
+ console.log('=== Validating Module Manifest ===\n');
243
+ const registry = KindRegistry.getInstance();
244
+ // Valid manifest
245
+ const validManifest = {
246
+ kind: OriginalKind.Module,
247
+ name: 'my-module',
248
+ version: '1.0.0',
249
+ resources: [{
250
+ id: 'index.js',
251
+ type: 'code',
252
+ contentType: 'application/javascript',
253
+ hash: 'abc123',
254
+ }],
255
+ metadata: {
256
+ format: 'esm',
257
+ main: 'index.js',
258
+ },
259
+ };
260
+ const validResult = registry.validate(validManifest);
261
+ console.log('Valid manifest result:', validResult.isValid ? 'VALID' : 'INVALID');
262
+ if (validResult.warnings.length > 0) {
263
+ console.log('Warnings:', validResult.warnings.map(w => w.message).join(', '));
264
+ }
265
+ console.log('');
266
+ // Invalid manifest (missing required field)
267
+ const invalidManifest = {
268
+ kind: OriginalKind.Module,
269
+ name: 'bad-module',
270
+ version: '1.0.0',
271
+ resources: [],
272
+ metadata: {
273
+ format: 'esm',
274
+ // Missing 'main' field!
275
+ },
276
+ };
277
+ // Cast through unknown since this is intentionally invalid for testing validation
278
+ const invalidResult = registry.validate(invalidManifest);
279
+ console.log('Invalid manifest result:', invalidResult.isValid ? 'VALID' : 'INVALID');
280
+ if (!invalidResult.isValid) {
281
+ console.log('Errors:');
282
+ invalidResult.errors.forEach(e => {
283
+ console.log(` - [${e.code}] ${e.message}`);
284
+ });
285
+ }
286
+ console.log('');
287
+ }
288
+ /**
289
+ * Estimate costs for module inscription
290
+ */
291
+ async function estimateModuleCosts() {
292
+ console.log('=== Estimating Module Inscription Costs ===\n');
293
+ const sdk = OriginalsSDK.create({
294
+ network: 'regtest',
295
+ defaultKeyType: 'Ed25519',
296
+ ordinalsProvider: new OrdMockProvider(),
297
+ });
298
+ const moduleCode = `export const VERSION = '1.0.0';`;
299
+ const moduleAsset = await sdk.lifecycle.createTypedOriginal(OriginalKind.Module, {
300
+ kind: OriginalKind.Module,
301
+ name: 'tiny-module',
302
+ version: '1.0.0',
303
+ resources: [{
304
+ id: 'index.js',
305
+ type: 'code',
306
+ content: moduleCode,
307
+ contentType: 'application/javascript',
308
+ hash: computeHash(moduleCode),
309
+ size: moduleCode.length,
310
+ }],
311
+ metadata: {
312
+ format: 'esm',
313
+ main: 'index.js',
314
+ },
315
+ });
316
+ // Estimate costs at different fee rates
317
+ const feeRates = [1, 5, 10, 20, 50];
318
+ console.log('Cost estimates by fee rate:');
319
+ for (const feeRate of feeRates) {
320
+ const cost = await sdk.lifecycle.estimateCost(moduleAsset, 'did:btco', feeRate);
321
+ console.log(` ${feeRate} sat/vB: ${cost.totalSats} sats (~${(cost.totalSats / 100000000).toFixed(8)} BTC)`);
322
+ }
323
+ console.log('');
324
+ // Validate migration before attempting
325
+ const validation = await sdk.lifecycle.validateMigration(moduleAsset, 'did:btco');
326
+ console.log('Migration validation:');
327
+ console.log(` Valid: ${validation.valid}`);
328
+ console.log(` Checks:`);
329
+ Object.entries(validation.checks).forEach(([check, passed]) => {
330
+ console.log(` - ${check}: ${passed ? '✓' : '✗'}`);
331
+ });
332
+ console.log('');
333
+ }
334
+ /**
335
+ * Create templates using KindRegistry
336
+ */
337
+ function useModuleTemplates() {
338
+ console.log('=== Using Module Templates ===\n');
339
+ // Create a template for a Module
340
+ const template = KindRegistry.createTemplate(OriginalKind.Module, 'my-new-module', '0.1.0');
341
+ console.log('Module template:');
342
+ console.log(JSON.stringify(template, null, 2));
343
+ console.log('');
344
+ // Parse kind from string
345
+ const kindFromShort = KindRegistry.parseKind('module');
346
+ const kindFromFull = KindRegistry.parseKind('originals:kind:module');
347
+ console.log('Kind parsing:');
348
+ console.log(` 'module' -> ${kindFromShort}`);
349
+ console.log(` 'originals:kind:module' -> ${kindFromFull}`);
350
+ console.log(` Display name: ${KindRegistry.getDisplayName(OriginalKind.Module)}`);
351
+ console.log(` Short name: ${KindRegistry.getShortName(OriginalKind.Module)}`);
352
+ console.log('');
353
+ }
354
+ /**
355
+ * Main execution
356
+ */
357
+ async function main() {
358
+ try {
359
+ await createSimpleModule();
360
+ await createModuleWithDependencies();
361
+ validateModuleManifest();
362
+ await estimateModuleCosts();
363
+ useModuleTemplates();
364
+ console.log('=== All Module Examples Completed ===');
365
+ }
366
+ catch (error) {
367
+ console.error('Error:', error);
368
+ process.exit(1);
369
+ }
370
+ }
371
+ // Export for use as module
372
+ export { createSimpleModule, createModuleWithDependencies, validateModuleManifest, estimateModuleCosts, useModuleTemplates, main };
373
+ // Run if executed directly
374
+ if (require.main === module) {
375
+ void main();
376
+ }
@@ -0,0 +1,56 @@
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
+ import { OriginalsSDK, ResourceManager, type OriginalsAsset } from '../index';
16
+ /**
17
+ * Initialize SDK with all necessary providers
18
+ */
19
+ declare function initializeSDK(): OriginalsSDK;
20
+ /**
21
+ * Step 1: Create resources using ResourceManager
22
+ */
23
+ declare function createResources(resourceManager: ResourceManager): void;
24
+ /**
25
+ * Step 2: Create a draft asset (did:peer layer)
26
+ */
27
+ declare function createDraft(sdk: OriginalsSDK): Promise<OriginalsAsset>;
28
+ /**
29
+ * Step 3: Validate migration and estimate costs
30
+ */
31
+ declare function validateAndEstimate(sdk: OriginalsSDK, asset: OriginalsAsset): Promise<void>;
32
+ /**
33
+ * Step 4: Publish to web (did:webvh layer)
34
+ */
35
+ declare function publishToWeb(sdk: OriginalsSDK, asset: OriginalsAsset): Promise<OriginalsAsset>;
36
+ /**
37
+ * Step 5: Inscribe on Bitcoin (did:btco layer)
38
+ */
39
+ declare function inscribeOnBitcoin(sdk: OriginalsSDK, asset: OriginalsAsset): Promise<OriginalsAsset>;
40
+ /**
41
+ * Step 6: Transfer ownership
42
+ */
43
+ declare function transferOwnership(sdk: OriginalsSDK, asset: OriginalsAsset): Promise<void>;
44
+ /**
45
+ * Step 7: View complete provenance
46
+ */
47
+ declare function viewProvenance(asset: OriginalsAsset): void;
48
+ /**
49
+ * Bonus: Create and publish a typed Original
50
+ */
51
+ declare function typedOriginalFlow(sdk: OriginalsSDK): Promise<void>;
52
+ /**
53
+ * Main execution - full lifecycle demonstration
54
+ */
55
+ declare function main(): Promise<void>;
56
+ export { main, initializeSDK, createResources, createDraft, validateAndEstimate, publishToWeb, inscribeOnBitcoin, transferOwnership, viewProvenance, typedOriginalFlow, };