@originals/sdk 1.1.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 (247) hide show
  1. package/package.json +3 -2
  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/tsconfig.json +0 -1
  34. package/.turbo/turbo-build.log +0 -1
  35. package/.turbo/turbo-test.log +0 -68353
  36. package/dist/adapters/FeeOracleMock.d.ts +0 -6
  37. package/dist/adapters/FeeOracleMock.js +0 -8
  38. package/dist/adapters/index.d.ts +0 -4
  39. package/dist/adapters/index.js +0 -4
  40. package/dist/adapters/providers/OrdHttpProvider.d.ts +0 -56
  41. package/dist/adapters/providers/OrdHttpProvider.js +0 -110
  42. package/dist/adapters/providers/OrdMockProvider.d.ts +0 -70
  43. package/dist/adapters/providers/OrdMockProvider.js +0 -75
  44. package/dist/adapters/types.d.ts +0 -71
  45. package/dist/adapters/types.js +0 -1
  46. package/dist/bitcoin/BitcoinManager.d.ts +0 -15
  47. package/dist/bitcoin/BitcoinManager.js +0 -262
  48. package/dist/bitcoin/BroadcastClient.d.ts +0 -30
  49. package/dist/bitcoin/BroadcastClient.js +0 -35
  50. package/dist/bitcoin/OrdinalsClient.d.ts +0 -21
  51. package/dist/bitcoin/OrdinalsClient.js +0 -105
  52. package/dist/bitcoin/PSBTBuilder.d.ts +0 -24
  53. package/dist/bitcoin/PSBTBuilder.js +0 -80
  54. package/dist/bitcoin/fee-calculation.d.ts +0 -14
  55. package/dist/bitcoin/fee-calculation.js +0 -31
  56. package/dist/bitcoin/providers/OrdNodeProvider.d.ts +0 -38
  57. package/dist/bitcoin/providers/OrdNodeProvider.js +0 -67
  58. package/dist/bitcoin/providers/OrdinalsProvider.d.ts +0 -33
  59. package/dist/bitcoin/providers/OrdinalsProvider.js +0 -50
  60. package/dist/bitcoin/providers/types.d.ts +0 -63
  61. package/dist/bitcoin/providers/types.js +0 -1
  62. package/dist/bitcoin/transactions/commit.d.ts +0 -89
  63. package/dist/bitcoin/transactions/commit.js +0 -311
  64. package/dist/bitcoin/transactions/index.d.ts +0 -7
  65. package/dist/bitcoin/transactions/index.js +0 -8
  66. package/dist/bitcoin/transfer.d.ts +0 -9
  67. package/dist/bitcoin/transfer.js +0 -26
  68. package/dist/bitcoin/utxo-selection.d.ts +0 -78
  69. package/dist/bitcoin/utxo-selection.js +0 -237
  70. package/dist/bitcoin/utxo.d.ts +0 -26
  71. package/dist/bitcoin/utxo.js +0 -78
  72. package/dist/contexts/credentials-v1.json +0 -195
  73. package/dist/contexts/credentials-v2-examples.json +0 -5
  74. package/dist/contexts/credentials-v2.json +0 -301
  75. package/dist/contexts/credentials.json +0 -195
  76. package/dist/contexts/data-integrity-v2.json +0 -81
  77. package/dist/contexts/dids.json +0 -57
  78. package/dist/contexts/ed255192020.json +0 -93
  79. package/dist/contexts/ordinals-plus.json +0 -23
  80. package/dist/contexts/originals.json +0 -22
  81. package/dist/core/OriginalsSDK.d.ts +0 -158
  82. package/dist/core/OriginalsSDK.js +0 -274
  83. package/dist/crypto/Multikey.d.ts +0 -30
  84. package/dist/crypto/Multikey.js +0 -149
  85. package/dist/crypto/Signer.d.ts +0 -21
  86. package/dist/crypto/Signer.js +0 -196
  87. package/dist/crypto/noble-init.d.ts +0 -18
  88. package/dist/crypto/noble-init.js +0 -106
  89. package/dist/did/BtcoDidResolver.d.ts +0 -57
  90. package/dist/did/BtcoDidResolver.js +0 -166
  91. package/dist/did/DIDManager.d.ts +0 -101
  92. package/dist/did/DIDManager.js +0 -493
  93. package/dist/did/Ed25519Verifier.d.ts +0 -30
  94. package/dist/did/Ed25519Verifier.js +0 -59
  95. package/dist/did/KeyManager.d.ts +0 -17
  96. package/dist/did/KeyManager.js +0 -207
  97. package/dist/did/WebVHManager.d.ts +0 -100
  98. package/dist/did/WebVHManager.js +0 -304
  99. package/dist/did/createBtcoDidDocument.d.ts +0 -10
  100. package/dist/did/createBtcoDidDocument.js +0 -42
  101. package/dist/did/providers/OrdinalsClientProviderAdapter.d.ts +0 -23
  102. package/dist/did/providers/OrdinalsClientProviderAdapter.js +0 -51
  103. package/dist/events/EventEmitter.d.ts +0 -115
  104. package/dist/events/EventEmitter.js +0 -198
  105. package/dist/events/index.d.ts +0 -7
  106. package/dist/events/index.js +0 -6
  107. package/dist/events/types.d.ts +0 -286
  108. package/dist/events/types.js +0 -9
  109. package/dist/examples/basic-usage.d.ts +0 -3
  110. package/dist/examples/basic-usage.js +0 -62
  111. package/dist/examples/run.d.ts +0 -1
  112. package/dist/examples/run.js +0 -4
  113. package/dist/index.d.ts +0 -39
  114. package/dist/index.js +0 -47
  115. package/dist/lifecycle/BatchOperations.d.ts +0 -147
  116. package/dist/lifecycle/BatchOperations.js +0 -251
  117. package/dist/lifecycle/LifecycleManager.d.ts +0 -116
  118. package/dist/lifecycle/LifecycleManager.js +0 -971
  119. package/dist/lifecycle/OriginalsAsset.d.ts +0 -164
  120. package/dist/lifecycle/OriginalsAsset.js +0 -380
  121. package/dist/lifecycle/ProvenanceQuery.d.ts +0 -126
  122. package/dist/lifecycle/ProvenanceQuery.js +0 -220
  123. package/dist/lifecycle/ResourceVersioning.d.ts +0 -73
  124. package/dist/lifecycle/ResourceVersioning.js +0 -127
  125. package/dist/migration/MigrationManager.d.ts +0 -86
  126. package/dist/migration/MigrationManager.js +0 -412
  127. package/dist/migration/audit/AuditLogger.d.ts +0 -51
  128. package/dist/migration/audit/AuditLogger.js +0 -156
  129. package/dist/migration/checkpoint/CheckpointManager.d.ts +0 -31
  130. package/dist/migration/checkpoint/CheckpointManager.js +0 -96
  131. package/dist/migration/checkpoint/CheckpointStorage.d.ts +0 -26
  132. package/dist/migration/checkpoint/CheckpointStorage.js +0 -89
  133. package/dist/migration/index.d.ts +0 -22
  134. package/dist/migration/index.js +0 -27
  135. package/dist/migration/operations/BaseMigration.d.ts +0 -48
  136. package/dist/migration/operations/BaseMigration.js +0 -83
  137. package/dist/migration/operations/PeerToBtcoMigration.d.ts +0 -25
  138. package/dist/migration/operations/PeerToBtcoMigration.js +0 -67
  139. package/dist/migration/operations/PeerToWebvhMigration.d.ts +0 -19
  140. package/dist/migration/operations/PeerToWebvhMigration.js +0 -46
  141. package/dist/migration/operations/WebvhToBtcoMigration.d.ts +0 -25
  142. package/dist/migration/operations/WebvhToBtcoMigration.js +0 -67
  143. package/dist/migration/rollback/RollbackManager.d.ts +0 -29
  144. package/dist/migration/rollback/RollbackManager.js +0 -146
  145. package/dist/migration/state/StateMachine.d.ts +0 -25
  146. package/dist/migration/state/StateMachine.js +0 -76
  147. package/dist/migration/state/StateTracker.d.ts +0 -36
  148. package/dist/migration/state/StateTracker.js +0 -123
  149. package/dist/migration/types.d.ts +0 -306
  150. package/dist/migration/types.js +0 -33
  151. package/dist/migration/validation/BitcoinValidator.d.ts +0 -13
  152. package/dist/migration/validation/BitcoinValidator.js +0 -83
  153. package/dist/migration/validation/CredentialValidator.d.ts +0 -13
  154. package/dist/migration/validation/CredentialValidator.js +0 -46
  155. package/dist/migration/validation/DIDCompatibilityValidator.d.ts +0 -16
  156. package/dist/migration/validation/DIDCompatibilityValidator.js +0 -127
  157. package/dist/migration/validation/LifecycleValidator.d.ts +0 -10
  158. package/dist/migration/validation/LifecycleValidator.js +0 -52
  159. package/dist/migration/validation/StorageValidator.d.ts +0 -10
  160. package/dist/migration/validation/StorageValidator.js +0 -65
  161. package/dist/migration/validation/ValidationPipeline.d.ts +0 -29
  162. package/dist/migration/validation/ValidationPipeline.js +0 -180
  163. package/dist/storage/LocalStorageAdapter.d.ts +0 -11
  164. package/dist/storage/LocalStorageAdapter.js +0 -53
  165. package/dist/storage/MemoryStorageAdapter.d.ts +0 -6
  166. package/dist/storage/MemoryStorageAdapter.js +0 -21
  167. package/dist/storage/StorageAdapter.d.ts +0 -16
  168. package/dist/storage/StorageAdapter.js +0 -1
  169. package/dist/storage/index.d.ts +0 -2
  170. package/dist/storage/index.js +0 -2
  171. package/dist/types/bitcoin.d.ts +0 -84
  172. package/dist/types/bitcoin.js +0 -1
  173. package/dist/types/common.d.ts +0 -82
  174. package/dist/types/common.js +0 -1
  175. package/dist/types/credentials.d.ts +0 -75
  176. package/dist/types/credentials.js +0 -1
  177. package/dist/types/did.d.ts +0 -26
  178. package/dist/types/did.js +0 -1
  179. package/dist/types/index.d.ts +0 -5
  180. package/dist/types/index.js +0 -5
  181. package/dist/types/network.d.ts +0 -78
  182. package/dist/types/network.js +0 -145
  183. package/dist/utils/EventLogger.d.ts +0 -71
  184. package/dist/utils/EventLogger.js +0 -232
  185. package/dist/utils/Logger.d.ts +0 -106
  186. package/dist/utils/Logger.js +0 -257
  187. package/dist/utils/MetricsCollector.d.ts +0 -110
  188. package/dist/utils/MetricsCollector.js +0 -264
  189. package/dist/utils/bitcoin-address.d.ts +0 -38
  190. package/dist/utils/bitcoin-address.js +0 -113
  191. package/dist/utils/cbor.d.ts +0 -2
  192. package/dist/utils/cbor.js +0 -9
  193. package/dist/utils/encoding.d.ts +0 -37
  194. package/dist/utils/encoding.js +0 -120
  195. package/dist/utils/hash.d.ts +0 -1
  196. package/dist/utils/hash.js +0 -5
  197. package/dist/utils/retry.d.ts +0 -10
  198. package/dist/utils/retry.js +0 -35
  199. package/dist/utils/satoshi-validation.d.ts +0 -60
  200. package/dist/utils/satoshi-validation.js +0 -156
  201. package/dist/utils/serialization.d.ts +0 -14
  202. package/dist/utils/serialization.js +0 -76
  203. package/dist/utils/telemetry.d.ts +0 -17
  204. package/dist/utils/telemetry.js +0 -24
  205. package/dist/utils/validation.d.ts +0 -5
  206. package/dist/utils/validation.js +0 -98
  207. package/dist/vc/CredentialManager.d.ts +0 -22
  208. package/dist/vc/CredentialManager.js +0 -227
  209. package/dist/vc/Issuer.d.ts +0 -27
  210. package/dist/vc/Issuer.js +0 -70
  211. package/dist/vc/Verifier.d.ts +0 -16
  212. package/dist/vc/Verifier.js +0 -50
  213. package/dist/vc/cryptosuites/bbs.d.ts +0 -44
  214. package/dist/vc/cryptosuites/bbs.js +0 -213
  215. package/dist/vc/cryptosuites/bbsSimple.d.ts +0 -9
  216. package/dist/vc/cryptosuites/bbsSimple.js +0 -12
  217. package/dist/vc/cryptosuites/eddsa.d.ts +0 -30
  218. package/dist/vc/cryptosuites/eddsa.js +0 -81
  219. package/dist/vc/documentLoader.d.ts +0 -16
  220. package/dist/vc/documentLoader.js +0 -59
  221. package/dist/vc/proofs/data-integrity.d.ts +0 -21
  222. package/dist/vc/proofs/data-integrity.js +0 -15
  223. package/dist/vc/utils/jsonld.d.ts +0 -2
  224. package/dist/vc/utils/jsonld.js +0 -15
  225. package/test/logs/did_webvh_QmQsRNhXxPSCSeLjpbKYcNMZj8b1kBQAoC6cZmkFAgmpHt_example_com.jsonl +0 -1
  226. package/test/logs/did_webvh_QmSQkpD58qxcqMWHYcEmDUn3wk7hHvJwzYTrZmhh6zjPQ8_example_com_users_alice123_profile.jsonl +0 -1
  227. package/test/logs/did_webvh_QmTMda6VW3cUPdKk5Yc3onnv1vdgEumvWWdP2noAYFSjeG_example_com.jsonl +0 -1
  228. package/test/logs/did_webvh_QmTkb8KnCYcsnKKDCY4eUQuKQdKJLrCinvhw13v3zETxpE_example_com_users_etc_passwd.jsonl +0 -1
  229. package/test/logs/did_webvh_QmTn9FdCfpXFDrxHH52pwB4iNrDFVvNDjJ5FQTcDbmM3Fg_example_com.jsonl +0 -1
  230. package/test/logs/did_webvh_QmUCQUi1xjtJjnSQ1XJZgKqcWgErx1v7E2dz4DAPraAyJP_example_com_etc_passwd.jsonl +0 -1
  231. package/test/logs/did_webvh_QmUENQJCDKBJVRS5BkL6zjaUvcRjkb9xHmy7foCgRjmv3W_example_com.jsonl +0 -1
  232. package/test/logs/did_webvh_QmUPdGyjYBEnQ3aQUkmqyyBKTyjvCP5RZQGiaEDeTtf6dc_example_com.jsonl +0 -1
  233. package/test/logs/did_webvh_QmUoHTuHMWzQM29ZFrE9VLtMxkZ5u869yqee8LwcCLN39M_example_com.jsonl +0 -1
  234. package/test/logs/did_webvh_QmUrnms8G65ggVKsr9oQeWrLUBuGChwQPPb2LCFvaoNxaw_example_com_users_alice.jsonl +0 -1
  235. package/test/logs/did_webvh_QmUwiw3eSXdHG1hPvoAGu3cuK5jF4aXRYDLBAjPXfv1qzb_example_com_level1_level2.jsonl +0 -1
  236. package/test/logs/did_webvh_QmW7bzKh6yFEKNAtmVsrPGvvsMHTUQdzJSNsTZkbuGFpbj_example_com_secret.jsonl +0 -1
  237. package/test/logs/did_webvh_QmXbFTFBBJ8zpjdz9WE1DNN44A2wprFmdvAubjSffeyoAG_example_com.jsonl +0 -1
  238. package/test/logs/did_webvh_QmXyVXFPCTffGb2mTUFDeMCsScjnpLWkyUkVkB6q6QoeBf_example_com_C_Windows_System32.jsonl +0 -1
  239. package/test/logs/did_webvh_QmZK9B81gxZtvo5fYHYKDtKt8zZfZZPhmCMhbujBJuRRzE_example_com_etc_passwd.jsonl +0 -1
  240. package/test/logs/did_webvh_QmbNLCVSdXSVLrwFBvCBQPAabjtRb1SGHjkGVyw3QUbfBL_example_com_users_etc_passwd.jsonl +0 -1
  241. package/test/logs/did_webvh_QmbeaicmGW3Q7Yzbqmftc8a9jLBngokveb5A2KVKfVGZRb_example_com_my_org_user_name_test_123.jsonl +0 -1
  242. package/test/logs/did_webvh_Qmdv7c7AjUreUfoKyvkN2UpAWTozxKsv99srQetPJMJEnp_example_com_users_etc_passwd.jsonl +0 -1
  243. package/test/logs/did_webvh_QmeioWY3uypYLkYpCXe9eCYnn4xBVruP9C1d79azMrTEHG_example_com.jsonl +0 -1
  244. package/test/logs/did_webvh_Qmf4QH5dsA6Ecr5HJ6KaJL9uJRyY8RxrQdqoRCM25DzvPi_example_com_users_alice.jsonl +0 -1
  245. package/tests/e2e/README.md +0 -97
  246. package/tests/e2e/example.spec.ts +0 -78
  247. package/tsconfig.tsbuildinfo +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@originals/sdk",
3
- "version": "1.1.0",
3
+ "version": "1.4.2",
4
4
  "description": "TypeScript SDK for the Originals Protocol - creating, discovering, and transferring digital assets with cryptographically verifiable provenance",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -12,7 +12,7 @@
12
12
  }
13
13
  },
14
14
  "scripts": {
15
- "build": "tsc",
15
+ "build": "tsc && tsc-alias",
16
16
  "test": "bun test tests/integration && bun test tests/unit && bun test tests/security && bun test tests/stress",
17
17
  "test:coverage": "bun test tests/integration tests/unit --coverage",
18
18
  "check-coverage": "bun run ../../scripts/check-coverage.ts",
@@ -71,6 +71,7 @@
71
71
  "bun-types": "^1.3.1",
72
72
  "eslint": "^8.0.0",
73
73
  "prettier": "^3.0.0",
74
+ "tsc-alias": "^1.8.16",
74
75
  "typescript": "^5.0.0"
75
76
  },
76
77
  "engines": {
@@ -289,7 +289,7 @@ export class DIDManager {
289
289
  let verificationMethods: WebVHVerificationMethod[];
290
290
  let updateKeys: string[];
291
291
 
292
- // Use external signer if provided (e.g., Privy integration)
292
+ // Use external signer if provided (e.g., Turnkey integration)
293
293
  if (externalSigner) {
294
294
  if (!providedVerificationMethods || providedVerificationMethods.length === 0) {
295
295
  throw new Error('verificationMethods are required when using externalSigner');
@@ -120,7 +120,7 @@ export interface CreateWebVHOptions {
120
120
  paths?: string[];
121
121
  portable?: boolean;
122
122
  outputDir?: string; // Directory to save the DID log (did.jsonl)
123
- externalSigner?: ExternalSigner; // External signer (e.g., Privy integration)
123
+ externalSigner?: ExternalSigner; // External signer (e.g., Turnkey integration)
124
124
  externalVerifier?: ExternalVerifier; // External verifier
125
125
  verificationMethods?: VerificationMethod[]; // Pre-configured verification methods
126
126
  updateKeys?: string[]; // Pre-configured update keys (e.g., ["did:key:z6Mk..."])
@@ -162,6 +162,15 @@ export class WebVHManager {
162
162
  updateKeys: providedUpdateKeys
163
163
  } = options;
164
164
 
165
+ // Validate path segments before creating DID to prevent directory traversal
166
+ if (paths && paths.length > 0) {
167
+ for (const segment of paths) {
168
+ if (!this.isValidPathSegment(segment)) {
169
+ throw new Error(`Invalid path segment in DID: "${segment}". Path segments cannot contain '.', '..', path separators, or be absolute paths.`);
170
+ }
171
+ }
172
+ }
173
+
165
174
  // Dynamically import didwebvh-ts to avoid module resolution issues
166
175
  const mod = await import('didwebvh-ts') as unknown as {
167
176
  createDID: (options: Record<string, unknown>) => Promise<{
@@ -187,7 +196,7 @@ export class WebVHManager {
187
196
  let verificationMethods: VerificationMethod[];
188
197
  let updateKeys: string[];
189
198
 
190
- // Use external signer if provided (e.g., Privy integration)
199
+ // Use external signer if provided (e.g., Turnkey integration)
191
200
  if (externalSigner) {
192
201
  if (!providedVerificationMethods || providedVerificationMethods.length === 0) {
193
202
  throw new Error('verificationMethods are required when using externalSigner');
@@ -0,0 +1,435 @@
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
+ import {
10
+ OriginalsSDK,
11
+ OriginalKind,
12
+ OrdMockProvider,
13
+ KindRegistry,
14
+ type OriginalManifest
15
+ } from '../index';
16
+ import { sha256 } from '@noble/hashes/sha2.js';
17
+
18
+ /**
19
+ * Helper to compute content hash
20
+ */
21
+ function computeHash(content: string): string {
22
+ return Buffer.from(sha256(Buffer.from(content))).toString('hex');
23
+ }
24
+
25
+ /**
26
+ * Create a simple Module Original
27
+ */
28
+ async function createSimpleModule(): Promise<void> {
29
+ console.log('=== Creating a Simple Module Original ===\n');
30
+
31
+ // Initialize SDK
32
+ const sdk = OriginalsSDK.create({
33
+ network: 'regtest',
34
+ defaultKeyType: 'Ed25519',
35
+ webvhNetwork: 'magby',
36
+ ordinalsProvider: new OrdMockProvider(),
37
+ });
38
+
39
+ // Define module source code
40
+ const moduleCode = `
41
+ /**
42
+ * A simple greeting utility module
43
+ */
44
+
45
+ /**
46
+ * Generate a personalized greeting
47
+ * @param name - The name to greet
48
+ * @returns A friendly greeting string
49
+ */
50
+ export function greet(name) {
51
+ return \`Hello, \${name}! Welcome to Originals.\`;
52
+ }
53
+
54
+ /**
55
+ * Generate a farewell message
56
+ * @param name - The name to say goodbye to
57
+ * @returns A farewell string
58
+ */
59
+ export function farewell(name) {
60
+ return \`Goodbye, \${name}! See you soon.\`;
61
+ }
62
+
63
+ /**
64
+ * Get a random greeting from a list
65
+ * @returns A random greeting string
66
+ */
67
+ export function randomGreeting() {
68
+ const greetings = ['Hey!', 'Hi there!', 'Howdy!', 'Welcome!', 'Greetings!'];
69
+ return greetings[Math.floor(Math.random() * greetings.length)];
70
+ }
71
+ `.trim();
72
+
73
+ // Define TypeScript type definitions
74
+ const typeDefs = `
75
+ /**
76
+ * Type definitions for greeting-utils module
77
+ */
78
+
79
+ /**
80
+ * Generate a personalized greeting
81
+ */
82
+ export declare function greet(name: string): string;
83
+
84
+ /**
85
+ * Generate a farewell message
86
+ */
87
+ export declare function farewell(name: string): string;
88
+
89
+ /**
90
+ * Get a random greeting from a list
91
+ */
92
+ export declare function randomGreeting(): string;
93
+ `.trim();
94
+
95
+ // Create resources
96
+ const resources = [
97
+ {
98
+ id: 'index.js',
99
+ type: 'code',
100
+ content: moduleCode,
101
+ contentType: 'application/javascript',
102
+ hash: computeHash(moduleCode),
103
+ size: moduleCode.length,
104
+ },
105
+ {
106
+ id: 'index.d.ts',
107
+ type: 'code',
108
+ content: typeDefs,
109
+ contentType: 'application/typescript',
110
+ hash: computeHash(typeDefs),
111
+ size: typeDefs.length,
112
+ },
113
+ ];
114
+
115
+ // Create typed Module Original
116
+ const moduleAsset = await sdk.lifecycle.createTypedOriginal(
117
+ OriginalKind.Module,
118
+ {
119
+ kind: OriginalKind.Module,
120
+ name: 'greeting-utils',
121
+ version: '1.0.0',
122
+ description: 'A simple greeting utility module for generating personalized messages',
123
+ resources,
124
+ tags: ['utility', 'greeting', 'message', 'text'],
125
+ author: {
126
+ name: 'Originals Developer',
127
+ email: 'dev@originals.example',
128
+ },
129
+ license: 'MIT',
130
+ homepage: 'https://github.com/originals/greeting-utils',
131
+ metadata: {
132
+ format: 'esm',
133
+ main: 'index.js',
134
+ types: 'index.d.ts',
135
+ exports: {
136
+ '.': {
137
+ import: './index.js',
138
+ types: './index.d.ts',
139
+ },
140
+ },
141
+ sideEffects: false,
142
+ },
143
+ }
144
+ );
145
+
146
+ console.log('Created Module Original:');
147
+ console.log(` ID: ${moduleAsset.id}`);
148
+ console.log(` Layer: ${moduleAsset.currentLayer}`);
149
+ console.log(` Resources: ${moduleAsset.resources.length}`);
150
+ console.log('');
151
+
152
+ // Get the manifest back
153
+ const manifest = sdk.lifecycle.getManifest(moduleAsset);
154
+ if (manifest && manifest.metadata) {
155
+ const meta = manifest.metadata as { format?: string; main?: string };
156
+ console.log('Manifest details:');
157
+ console.log(` Name: ${manifest.name}`);
158
+ console.log(` Version: ${manifest.version}`);
159
+ console.log(` Format: ${meta.format}`);
160
+ console.log(` Main: ${meta.main}`);
161
+ }
162
+ console.log('');
163
+ }
164
+
165
+ /**
166
+ * Create a Module Original with dependencies
167
+ */
168
+ async function createModuleWithDependencies(): Promise<void> {
169
+ console.log('=== Creating Module with Dependencies ===\n');
170
+
171
+ const sdk = OriginalsSDK.create({
172
+ network: 'regtest',
173
+ defaultKeyType: 'Ed25519',
174
+ ordinalsProvider: new OrdMockProvider(),
175
+ });
176
+
177
+ // Define module code that depends on another module
178
+ const moduleCode = `
179
+ /**
180
+ * Advanced formatter module that extends greeting-utils
181
+ */
182
+ import { greet, farewell } from 'greeting-utils';
183
+
184
+ /**
185
+ * Format a message with a timestamp
186
+ * @param message - The message to format
187
+ * @returns Formatted message with timestamp
188
+ */
189
+ export function withTimestamp(message) {
190
+ const now = new Date().toISOString();
191
+ return \`[\${now}] \${message}\`;
192
+ }
193
+
194
+ /**
195
+ * Create a welcome message with timestamp
196
+ * @param name - The name to welcome
197
+ * @returns Timestamped welcome message
198
+ */
199
+ export function timedGreeting(name) {
200
+ return withTimestamp(greet(name));
201
+ }
202
+
203
+ /**
204
+ * Create a farewell message with timestamp
205
+ * @param name - The name to say goodbye to
206
+ * @returns Timestamped farewell message
207
+ */
208
+ export function timedFarewell(name) {
209
+ return withTimestamp(farewell(name));
210
+ }
211
+
212
+ /**
213
+ * Format text with various styles
214
+ * @param text - Text to format
215
+ * @param style - Style option: 'upper' | 'lower' | 'title'
216
+ */
217
+ export function formatText(text, style = 'title') {
218
+ switch (style) {
219
+ case 'upper': return text.toUpperCase();
220
+ case 'lower': return text.toLowerCase();
221
+ case 'title': return text.split(' ').map(w => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()).join(' ');
222
+ default: return text;
223
+ }
224
+ }
225
+ `.trim();
226
+
227
+ const moduleAsset = await sdk.lifecycle.createTypedOriginal(
228
+ OriginalKind.Module,
229
+ {
230
+ kind: OriginalKind.Module,
231
+ name: 'advanced-formatter',
232
+ version: '1.0.0',
233
+ description: 'Advanced text formatting utilities',
234
+ resources: [{
235
+ id: 'index.js',
236
+ type: 'code',
237
+ content: moduleCode,
238
+ contentType: 'application/javascript',
239
+ hash: computeHash(moduleCode),
240
+ size: moduleCode.length,
241
+ }],
242
+ // Declare dependency on greeting-utils
243
+ dependencies: [{
244
+ did: 'did:peer:example-greeting-utils-did',
245
+ name: 'greeting-utils',
246
+ version: '^1.0.0',
247
+ }],
248
+ tags: ['formatter', 'text', 'utility'],
249
+ license: 'MIT',
250
+ metadata: {
251
+ format: 'esm',
252
+ main: 'index.js',
253
+ peerDependencies: {
254
+ 'greeting-utils': '^1.0.0',
255
+ },
256
+ },
257
+ }
258
+ );
259
+
260
+ console.log('Created Module with dependencies:');
261
+ console.log(` ID: ${moduleAsset.id}`);
262
+ console.log(` Dependencies: ${moduleAsset.resources.length > 0 ? 'greeting-utils ^1.0.0' : 'none'}`);
263
+ console.log('');
264
+ }
265
+
266
+ /**
267
+ * Validate a module manifest before creation
268
+ */
269
+ function validateModuleManifest(): void {
270
+ console.log('=== Validating Module Manifest ===\n');
271
+
272
+ const registry = KindRegistry.getInstance();
273
+
274
+ // Valid manifest
275
+ const validManifest = {
276
+ kind: OriginalKind.Module,
277
+ name: 'my-module',
278
+ version: '1.0.0',
279
+ resources: [{
280
+ id: 'index.js',
281
+ type: 'code',
282
+ contentType: 'application/javascript',
283
+ hash: 'abc123',
284
+ }],
285
+ metadata: {
286
+ format: 'esm' as const,
287
+ main: 'index.js',
288
+ },
289
+ };
290
+
291
+ const validResult = registry.validate(validManifest);
292
+ console.log('Valid manifest result:', validResult.isValid ? 'VALID' : 'INVALID');
293
+ if (validResult.warnings.length > 0) {
294
+ console.log('Warnings:', validResult.warnings.map(w => w.message).join(', '));
295
+ }
296
+ console.log('');
297
+
298
+ // Invalid manifest (missing required field)
299
+ const invalidManifest = {
300
+ kind: OriginalKind.Module,
301
+ name: 'bad-module',
302
+ version: '1.0.0',
303
+ resources: [],
304
+ metadata: {
305
+ format: 'esm' as const,
306
+ // Missing 'main' field!
307
+ },
308
+ };
309
+
310
+ // Cast through unknown since this is intentionally invalid for testing validation
311
+ const invalidResult = registry.validate(invalidManifest as unknown as OriginalManifest<OriginalKind.Module>);
312
+ console.log('Invalid manifest result:', invalidResult.isValid ? 'VALID' : 'INVALID');
313
+ if (!invalidResult.isValid) {
314
+ console.log('Errors:');
315
+ invalidResult.errors.forEach(e => {
316
+ console.log(` - [${e.code}] ${e.message}`);
317
+ });
318
+ }
319
+ console.log('');
320
+ }
321
+
322
+ /**
323
+ * Estimate costs for module inscription
324
+ */
325
+ async function estimateModuleCosts(): Promise<void> {
326
+ console.log('=== Estimating Module Inscription Costs ===\n');
327
+
328
+ const sdk = OriginalsSDK.create({
329
+ network: 'regtest',
330
+ defaultKeyType: 'Ed25519',
331
+ ordinalsProvider: new OrdMockProvider(),
332
+ });
333
+
334
+ const moduleCode = `export const VERSION = '1.0.0';`;
335
+
336
+ const moduleAsset = await sdk.lifecycle.createTypedOriginal(
337
+ OriginalKind.Module,
338
+ {
339
+ kind: OriginalKind.Module,
340
+ name: 'tiny-module',
341
+ version: '1.0.0',
342
+ resources: [{
343
+ id: 'index.js',
344
+ type: 'code',
345
+ content: moduleCode,
346
+ contentType: 'application/javascript',
347
+ hash: computeHash(moduleCode),
348
+ size: moduleCode.length,
349
+ }],
350
+ metadata: {
351
+ format: 'esm',
352
+ main: 'index.js',
353
+ },
354
+ }
355
+ );
356
+
357
+ // Estimate costs at different fee rates
358
+ const feeRates = [1, 5, 10, 20, 50];
359
+
360
+ console.log('Cost estimates by fee rate:');
361
+ for (const feeRate of feeRates) {
362
+ const cost = await sdk.lifecycle.estimateCost(moduleAsset, 'did:btco', feeRate);
363
+ console.log(` ${feeRate} sat/vB: ${cost.totalSats} sats (~${(cost.totalSats / 100000000).toFixed(8)} BTC)`);
364
+ }
365
+ console.log('');
366
+
367
+ // Validate migration before attempting
368
+ const validation = await sdk.lifecycle.validateMigration(moduleAsset, 'did:btco');
369
+ console.log('Migration validation:');
370
+ console.log(` Valid: ${validation.valid}`);
371
+ console.log(` Checks:`);
372
+ Object.entries(validation.checks).forEach(([check, passed]) => {
373
+ console.log(` - ${check}: ${passed ? '✓' : '✗'}`);
374
+ });
375
+ console.log('');
376
+ }
377
+
378
+ /**
379
+ * Create templates using KindRegistry
380
+ */
381
+ function useModuleTemplates(): void {
382
+ console.log('=== Using Module Templates ===\n');
383
+
384
+ // Create a template for a Module
385
+ const template = KindRegistry.createTemplate(OriginalKind.Module, 'my-new-module', '0.1.0');
386
+
387
+ console.log('Module template:');
388
+ console.log(JSON.stringify(template, null, 2));
389
+ console.log('');
390
+
391
+ // Parse kind from string
392
+ const kindFromShort = KindRegistry.parseKind('module');
393
+ const kindFromFull = KindRegistry.parseKind('originals:kind:module');
394
+
395
+ console.log('Kind parsing:');
396
+ console.log(` 'module' -> ${kindFromShort}`);
397
+ console.log(` 'originals:kind:module' -> ${kindFromFull}`);
398
+ console.log(` Display name: ${KindRegistry.getDisplayName(OriginalKind.Module)}`);
399
+ console.log(` Short name: ${KindRegistry.getShortName(OriginalKind.Module)}`);
400
+ console.log('');
401
+ }
402
+
403
+ /**
404
+ * Main execution
405
+ */
406
+ async function main(): Promise<void> {
407
+ try {
408
+ await createSimpleModule();
409
+ await createModuleWithDependencies();
410
+ validateModuleManifest();
411
+ await estimateModuleCosts();
412
+ useModuleTemplates();
413
+
414
+ console.log('=== All Module Examples Completed ===');
415
+ } catch (error) {
416
+ console.error('Error:', error);
417
+ process.exit(1);
418
+ }
419
+ }
420
+
421
+ // Export for use as module
422
+ export {
423
+ createSimpleModule,
424
+ createModuleWithDependencies,
425
+ validateModuleManifest,
426
+ estimateModuleCosts,
427
+ useModuleTemplates,
428
+ main
429
+ };
430
+
431
+ // Run if executed directly
432
+ if (require.main === module) {
433
+ void main();
434
+ }
435
+