@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
@@ -1,110 +0,0 @@
1
- function buildUrl(baseUrl, path) {
2
- const base = baseUrl.replace(/\/$/, '');
3
- return `${base}${path.startsWith('/') ? '' : '/'}${path}`;
4
- }
5
- async function fetchJson(url) {
6
- const res = await globalThis.fetch(url, {
7
- headers: {
8
- 'Accept': 'application/json'
9
- }
10
- });
11
- if (!res.ok)
12
- return null;
13
- return (await res.json());
14
- }
15
- export class OrdHttpProvider {
16
- constructor(options) {
17
- if (!options?.baseUrl) {
18
- throw new Error('OrdHttpProvider requires baseUrl');
19
- }
20
- this.baseUrl = options.baseUrl;
21
- }
22
- async getInscriptionById(id) {
23
- if (!id)
24
- return null;
25
- const data = await fetchJson(buildUrl(this.baseUrl, `/inscription/${id}`));
26
- if (!data)
27
- return null;
28
- // Expecting a shape similar to Ordinals indexers; adapt minimally
29
- const ownerOutput = data.owner_output;
30
- let txid = data.txid || 'unknown';
31
- let vout = typeof data.vout === 'number' ? data.vout : 0;
32
- if (ownerOutput && ownerOutput.includes(':')) {
33
- const [tid, v] = ownerOutput.split(':');
34
- txid = tid;
35
- vout = Number(v) || 0;
36
- }
37
- const contentType = data.content_type || 'application/octet-stream';
38
- const contentUrl = data.content_url || buildUrl(this.baseUrl, `/content/${id}`);
39
- const contentRes = await globalThis.fetch(contentUrl);
40
- if (!contentRes.ok)
41
- return null;
42
- const buf = globalThis.Buffer
43
- ? globalThis.Buffer.from(new Uint8Array(await contentRes.arrayBuffer()))
44
- : new Uint8Array(await contentRes.arrayBuffer());
45
- return {
46
- inscriptionId: data.inscription_id || id,
47
- content: buf,
48
- contentType,
49
- txid,
50
- vout,
51
- satoshi: String(data.sat ?? ''),
52
- blockHeight: data.block_height
53
- };
54
- }
55
- async getInscriptionsBySatoshi(satoshi) {
56
- if (!satoshi)
57
- return [];
58
- const data = await fetchJson(buildUrl(this.baseUrl, `/sat/${satoshi}`));
59
- const ids = Array.isArray(data?.inscription_ids) ? data.inscription_ids : [];
60
- return ids.map((inscriptionId) => ({ inscriptionId }));
61
- }
62
- async broadcastTransaction(_txHexOrObj) {
63
- // For example purposes only, return a placeholder
64
- return 'broadcast-txid';
65
- }
66
- async getTransactionStatus(_txid) {
67
- return { confirmed: false };
68
- }
69
- async estimateFee(blocks = 1) {
70
- // Basic fallback: some providers expose fee estimates; for example purposes, return linear estimate
71
- return 5 * Math.max(1, blocks);
72
- }
73
- async createInscription(params) {
74
- // Example placeholder: a real implementation would POST to a service
75
- // Here we return a deterministic mock-like result to avoid network coupling in code
76
- const inscriptionId = `insc-${Math.random().toString(36).slice(2)}`;
77
- const txid = `tx-${Math.random().toString(36).slice(2)}`;
78
- return {
79
- inscriptionId,
80
- revealTxId: txid,
81
- txid,
82
- vout: 0,
83
- blockHeight: undefined,
84
- content: params.data,
85
- contentType: params.contentType,
86
- feeRate: params.feeRate
87
- };
88
- }
89
- async transferInscription(inscriptionId, _toAddress, _options) {
90
- if (!inscriptionId)
91
- throw new Error('inscriptionId required');
92
- const txid = `tx-${Math.random().toString(36).slice(2)}`;
93
- return {
94
- txid,
95
- vin: [{ txid: 'prev', vout: 0 }],
96
- vout: [{ value: 546, scriptPubKey: 'script' }],
97
- fee: 100,
98
- confirmations: 0
99
- };
100
- }
101
- }
102
- export async function createOrdinalsProviderFromEnv() {
103
- const useLive = String((globalThis.process?.env?.USE_LIVE_ORD_PROVIDER) || '').toLowerCase() === 'true';
104
- if (useLive) {
105
- const baseUrl = (globalThis.process?.env?.ORD_PROVIDER_BASE_URL) || 'https://ord.example.com/api';
106
- return new OrdHttpProvider({ baseUrl });
107
- }
108
- const mod = await import('./OrdMockProvider');
109
- return new mod.OrdMockProvider();
110
- }
@@ -1,70 +0,0 @@
1
- import { OrdinalsProvider } from '../types';
2
- export interface OrdMockState {
3
- inscriptionsById: Map<string, {
4
- inscriptionId: string;
5
- content: Buffer;
6
- contentType: string;
7
- txid: string;
8
- vout: number;
9
- satoshi?: string;
10
- blockHeight?: number;
11
- }>;
12
- inscriptionsBySatoshi: Map<string, string[]>;
13
- feeRate: number;
14
- }
15
- export declare class OrdMockProvider implements OrdinalsProvider {
16
- private state;
17
- constructor(state?: Partial<OrdMockState>);
18
- getInscriptionById(id: string): Promise<{
19
- inscriptionId: string;
20
- content: Buffer;
21
- contentType: string;
22
- txid: string;
23
- vout: number;
24
- satoshi?: string;
25
- blockHeight?: number;
26
- } | null>;
27
- getInscriptionsBySatoshi(satoshi: string): Promise<{
28
- inscriptionId: string;
29
- }[]>;
30
- broadcastTransaction(_txHexOrObj: unknown): Promise<string>;
31
- getTransactionStatus(txid: string): Promise<{
32
- confirmed: boolean;
33
- blockHeight: number;
34
- confirmations: number;
35
- }>;
36
- estimateFee(blocks?: number): Promise<number>;
37
- createInscription(params: {
38
- data: Buffer;
39
- contentType: string;
40
- feeRate?: number;
41
- }): Promise<{
42
- inscriptionId: string;
43
- revealTxId: string;
44
- commitTxId: undefined;
45
- satoshi: string;
46
- txid: string;
47
- vout: number;
48
- blockHeight: number;
49
- content: Buffer<ArrayBufferLike>;
50
- contentType: string;
51
- feeRate: number | undefined;
52
- }>;
53
- transferInscription(inscriptionId: string, _toAddress: string, _options?: {
54
- feeRate?: number;
55
- }): Promise<{
56
- txid: string;
57
- vin: {
58
- txid: string;
59
- vout: number;
60
- }[];
61
- vout: {
62
- value: number;
63
- scriptPubKey: string;
64
- }[];
65
- fee: number;
66
- blockHeight: number;
67
- confirmations: number;
68
- satoshi: string | undefined;
69
- }>;
70
- }
@@ -1,75 +0,0 @@
1
- export class OrdMockProvider {
2
- constructor(state) {
3
- this.state = {
4
- inscriptionsById: new Map(),
5
- inscriptionsBySatoshi: new Map(),
6
- feeRate: 5,
7
- ...state
8
- };
9
- }
10
- async getInscriptionById(id) {
11
- const rec = this.state.inscriptionsById.get(id);
12
- return rec ? { ...rec } : null;
13
- }
14
- async getInscriptionsBySatoshi(satoshi) {
15
- const list = this.state.inscriptionsBySatoshi.get(satoshi) || [];
16
- return list.map((inscriptionId) => ({ inscriptionId }));
17
- }
18
- async broadcastTransaction(_txHexOrObj) {
19
- return 'mock-broadcast-txid';
20
- }
21
- async getTransactionStatus(txid) {
22
- return { confirmed: true, blockHeight: 1, confirmations: 1 };
23
- }
24
- async estimateFee(blocks = 1) {
25
- return Math.max(1, this.state.feeRate - (blocks - 1));
26
- }
27
- async createInscription(params) {
28
- const inscriptionId = `insc-${Math.random().toString(36).slice(2)}`;
29
- const txid = `tx-${Math.random().toString(36).slice(2)}`;
30
- // Generate a valid numeric satoshi identifier (not sat-123 format)
31
- const satoshi = `${Math.floor(Math.random() * 1e12)}`;
32
- const vout = 0;
33
- const record = {
34
- inscriptionId,
35
- content: params.data,
36
- contentType: params.contentType,
37
- txid,
38
- vout,
39
- satoshi,
40
- blockHeight: 1
41
- };
42
- this.state.inscriptionsById.set(inscriptionId, record);
43
- const list = this.state.inscriptionsBySatoshi.get(satoshi) || [];
44
- list.push(inscriptionId);
45
- this.state.inscriptionsBySatoshi.set(satoshi, list);
46
- return {
47
- inscriptionId,
48
- revealTxId: txid,
49
- commitTxId: undefined,
50
- satoshi,
51
- txid,
52
- vout,
53
- blockHeight: 1,
54
- content: params.data,
55
- contentType: params.contentType,
56
- feeRate: params.feeRate
57
- };
58
- }
59
- async transferInscription(inscriptionId, _toAddress, _options) {
60
- const rec = this.state.inscriptionsById.get(inscriptionId);
61
- if (!rec) {
62
- return Promise.reject(new Error('inscription not found'));
63
- }
64
- const txid = `tx-${Math.random().toString(36).slice(2)}`;
65
- return {
66
- txid,
67
- vin: [{ txid: rec.txid, vout: rec.vout }],
68
- vout: [{ value: 546, scriptPubKey: 'script' }],
69
- fee: 100,
70
- blockHeight: 1,
71
- confirmations: 0,
72
- satoshi: rec.satoshi
73
- };
74
- }
75
- }
@@ -1,71 +0,0 @@
1
- export interface StoragePutOptions {
2
- contentType?: string;
3
- cacheControl?: string;
4
- }
5
- export interface StorageGetResult {
6
- content: Buffer;
7
- contentType: string;
8
- }
9
- export interface StorageAdapter {
10
- put(objectKey: string, data: Buffer | string, options?: StoragePutOptions): Promise<string>;
11
- get(objectKey: string): Promise<StorageGetResult | null>;
12
- delete?(objectKey: string): Promise<boolean>;
13
- }
14
- export interface FeeOracleAdapter {
15
- estimateFeeRate(targetBlocks?: number): Promise<number>;
16
- }
17
- export interface OrdinalsProvider {
18
- getInscriptionById(id: string): Promise<{
19
- inscriptionId: string;
20
- content: Buffer;
21
- contentType: string;
22
- txid: string;
23
- vout: number;
24
- satoshi?: string;
25
- blockHeight?: number;
26
- } | null>;
27
- getInscriptionsBySatoshi(satoshi: string): Promise<Array<{
28
- inscriptionId: string;
29
- }>>;
30
- broadcastTransaction(txHexOrObj: unknown): Promise<string>;
31
- getTransactionStatus(txid: string): Promise<{
32
- confirmed: boolean;
33
- blockHeight?: number;
34
- confirmations?: number;
35
- }>;
36
- estimateFee(blocks?: number): Promise<number>;
37
- createInscription(params: {
38
- data: Buffer;
39
- contentType: string;
40
- feeRate?: number;
41
- }): Promise<{
42
- inscriptionId: string;
43
- revealTxId: string;
44
- commitTxId?: string;
45
- satoshi?: string;
46
- txid?: string;
47
- vout?: number;
48
- blockHeight?: number;
49
- content?: Buffer;
50
- contentType?: string;
51
- feeRate?: number;
52
- }>;
53
- transferInscription(inscriptionId: string, toAddress: string, options?: {
54
- feeRate?: number;
55
- }): Promise<{
56
- txid: string;
57
- vin: Array<{
58
- txid: string;
59
- vout: number;
60
- }>;
61
- vout: Array<{
62
- value: number;
63
- scriptPubKey: string;
64
- address?: string;
65
- }>;
66
- fee: number;
67
- blockHeight?: number;
68
- confirmations?: number;
69
- satoshi?: string;
70
- }>;
71
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,15 +0,0 @@
1
- import { OriginalsConfig, OrdinalsInscription, BitcoinTransaction } from '../types';
2
- export declare class BitcoinManager {
3
- private config;
4
- private readonly feeOracle?;
5
- private readonly ord?;
6
- constructor(config: OriginalsConfig);
7
- private resolveFeeRate;
8
- inscribeData(data: any, contentType: string, feeRate?: number): Promise<OrdinalsInscription>;
9
- trackInscription(inscriptionId: string): Promise<OrdinalsInscription | null>;
10
- transferInscription(inscription: OrdinalsInscription, toAddress: string): Promise<BitcoinTransaction>;
11
- preventFrontRunning(satoshi: string): Promise<boolean>;
12
- getSatoshiFromInscription(inscriptionId: string): Promise<string | null>;
13
- validateBTCODID(didId: string): Promise<boolean>;
14
- private extractSatoshiFromBTCODID;
15
- }
@@ -1,262 +0,0 @@
1
- import { DUST_LIMIT_SATS } from '../types';
2
- import { emitTelemetry, StructuredError } from '../utils/telemetry';
3
- import { validateBitcoinAddress } from '../utils/bitcoin-address';
4
- import { validateSatoshiNumber } from '../utils/satoshi-validation';
5
- export class BitcoinManager {
6
- constructor(config) {
7
- this.config = config;
8
- this.feeOracle = config.feeOracle;
9
- this.ord = config.ordinalsProvider;
10
- }
11
- async resolveFeeRate(targetBlocks = 1, provided) {
12
- // 1) Prefer external fee oracle
13
- if (this.feeOracle) {
14
- try {
15
- const estimated = await this.feeOracle.estimateFeeRate(targetBlocks);
16
- if (typeof estimated === 'number' && Number.isFinite(estimated) && estimated > 0) {
17
- emitTelemetry(this.config.telemetry, {
18
- name: 'bitcoin.fee.estimated',
19
- attributes: { feeRate: estimated, source: 'feeOracle' }
20
- });
21
- return estimated;
22
- }
23
- }
24
- catch (error) {
25
- emitTelemetry(this.config.telemetry, {
26
- name: 'bitcoin.fee.error',
27
- level: 'warn',
28
- attributes: { error: String(error), source: 'feeOracle' }
29
- });
30
- }
31
- }
32
- // 2) Fallback to ordinals provider if present
33
- if (this.ord) {
34
- try {
35
- const estimated = await this.ord.estimateFee(targetBlocks);
36
- if (typeof estimated === 'number' && Number.isFinite(estimated) && estimated > 0) {
37
- emitTelemetry(this.config.telemetry, {
38
- name: 'bitcoin.fee.estimated',
39
- attributes: { feeRate: estimated, source: 'ordinalsProvider' }
40
- });
41
- return estimated;
42
- }
43
- }
44
- catch (error) {
45
- emitTelemetry(this.config.telemetry, {
46
- name: 'bitcoin.fee.error',
47
- level: 'warn',
48
- attributes: { error: String(error), source: 'ordinalsProvider' }
49
- });
50
- }
51
- }
52
- // 3) If caller provided a valid non-zero fee rate, use it as last resort
53
- if (typeof provided === 'number' && Number.isFinite(provided) && provided > 0) {
54
- return provided;
55
- }
56
- return undefined;
57
- }
58
- async inscribeData(data, contentType, feeRate) {
59
- // Input validation
60
- if (!data) {
61
- throw new StructuredError('INVALID_INPUT', 'Data to inscribe cannot be null or undefined');
62
- }
63
- if (!contentType || typeof contentType !== 'string') {
64
- throw new StructuredError('INVALID_INPUT', 'Content type must be a non-empty string');
65
- }
66
- // Validate contentType is a valid MIME type
67
- if (!/^[a-zA-Z0-9][a-zA-Z0-9!#$&^_.+-]{0,126}\/[a-zA-Z0-9][a-zA-Z0-9!#$&^_.+-]{0,126}$/.test(contentType)) {
68
- throw new StructuredError('INVALID_INPUT', `Invalid MIME type format: ${contentType}`);
69
- }
70
- if (feeRate !== undefined && (typeof feeRate !== 'number' || feeRate <= 0 || !Number.isFinite(feeRate))) {
71
- throw new StructuredError('INVALID_INPUT', 'Fee rate must be a positive number');
72
- }
73
- // Security: Reject extremely high fee rates to prevent accidental fund drainage
74
- const MAX_REASONABLE_FEE_RATE = 10000; // sat/vB
75
- if (feeRate !== undefined && feeRate > MAX_REASONABLE_FEE_RATE) {
76
- throw new StructuredError('INVALID_INPUT', `Fee rate ${feeRate} exceeds maximum reasonable fee rate of ${MAX_REASONABLE_FEE_RATE} sat/vB`);
77
- }
78
- const effectiveFeeRate = await this.resolveFeeRate(1, feeRate);
79
- if (!this.ord) {
80
- throw new StructuredError('ORD_PROVIDER_REQUIRED', 'Ordinals provider must be configured to inscribe data on Bitcoin. ' +
81
- 'Please provide an ordinalsProvider in your SDK configuration. ' +
82
- 'For testing, use: import { OrdMockProvider } from \'@originals/sdk\';');
83
- }
84
- if (typeof this.ord.createInscription !== 'function') {
85
- throw new StructuredError('ORD_PROVIDER_UNSUPPORTED', 'Configured ordinals provider does not support inscription creation');
86
- }
87
- const creation = await this.ord.createInscription({ data, contentType, feeRate: effectiveFeeRate });
88
- const txid = creation.txid ?? creation.revealTxId;
89
- if (!creation.inscriptionId || !txid) {
90
- throw new StructuredError('ORD_PROVIDER_INVALID_RESPONSE', 'Ordinals provider did not return a valid inscription identifier or transaction id');
91
- }
92
- let satoshi = creation.satoshi ?? '';
93
- if (!satoshi) {
94
- satoshi = (await this.getSatoshiFromInscription(creation.inscriptionId)) ?? '';
95
- }
96
- // Validate satoshi before using it
97
- if (satoshi) {
98
- const validation = validateSatoshiNumber(satoshi);
99
- if (!validation.valid) {
100
- throw new StructuredError('INVALID_SATOSHI', `Ordinals provider returned invalid satoshi identifier: ${validation.error}`);
101
- }
102
- }
103
- let recordedFeeRate;
104
- if (this.feeOracle) {
105
- recordedFeeRate = effectiveFeeRate;
106
- }
107
- else if (typeof feeRate === 'number' && Number.isFinite(feeRate) && feeRate > 0) {
108
- recordedFeeRate = feeRate;
109
- }
110
- else {
111
- recordedFeeRate = creation.feeRate ?? effectiveFeeRate;
112
- }
113
- const inscription = {
114
- satoshi,
115
- inscriptionId: creation.inscriptionId,
116
- content: creation.content ?? data,
117
- contentType: creation.contentType ?? contentType,
118
- txid,
119
- vout: typeof creation.vout === 'number' ? creation.vout : 0,
120
- blockHeight: creation.blockHeight,
121
- revealTxId: creation.revealTxId,
122
- commitTxId: creation.commitTxId,
123
- feeRate: recordedFeeRate
124
- };
125
- return inscription;
126
- }
127
- async trackInscription(inscriptionId) {
128
- if (this.ord) {
129
- const info = await this.ord.getInscriptionById(inscriptionId);
130
- if (!info)
131
- return null;
132
- return {
133
- satoshi: info.satoshi ?? '',
134
- inscriptionId: info.inscriptionId,
135
- content: info.content,
136
- contentType: info.contentType,
137
- txid: info.txid,
138
- vout: info.vout,
139
- blockHeight: info.blockHeight
140
- };
141
- }
142
- return null;
143
- }
144
- async transferInscription(inscription, toAddress) {
145
- // Input validation
146
- if (!inscription || typeof inscription !== 'object') {
147
- throw new StructuredError('INVALID_INPUT', 'Inscription must be a valid OrdinalsInscription object');
148
- }
149
- if (!inscription.inscriptionId || typeof inscription.inscriptionId !== 'string') {
150
- throw new StructuredError('INVALID_INPUT', 'Inscription must have a valid inscriptionId');
151
- }
152
- if (!toAddress || typeof toAddress !== 'string') {
153
- throw new StructuredError('INVALID_INPUT', 'Destination address must be a non-empty string');
154
- }
155
- // Validate Bitcoin address format and checksum
156
- try {
157
- validateBitcoinAddress(toAddress, this.config.network);
158
- }
159
- catch (error) {
160
- const message = error instanceof Error ? error.message : 'Invalid Bitcoin address';
161
- throw new StructuredError('INVALID_ADDRESS', message);
162
- }
163
- const effectiveFeeRate = await this.resolveFeeRate(1);
164
- if (!this.ord) {
165
- throw new StructuredError('ORD_PROVIDER_REQUIRED', 'Ordinals provider must be configured to transfer inscriptions on Bitcoin. ' +
166
- 'Please provide an ordinalsProvider in your SDK configuration. ' +
167
- 'For testing, use: import { OrdMockProvider } from \'@originals/sdk\';');
168
- }
169
- if (typeof this.ord.transferInscription !== 'function') {
170
- throw new StructuredError('ORD_PROVIDER_UNSUPPORTED', 'Configured ordinals provider does not support inscription transfers');
171
- }
172
- const response = await this.ord.transferInscription(inscription.inscriptionId, toAddress, {
173
- feeRate: effectiveFeeRate
174
- });
175
- if (!response || !response.txid) {
176
- throw new StructuredError('ORD_PROVIDER_INVALID_RESPONSE', 'Ordinals provider did not return a valid transfer transaction');
177
- }
178
- if (response.satoshi) {
179
- inscription.satoshi = response.satoshi;
180
- }
181
- return {
182
- txid: response.txid,
183
- vin: response.vin ?? [{ txid: inscription.txid, vout: inscription.vout }],
184
- vout: response.vout?.length
185
- ? response.vout
186
- : [{ value: DUST_LIMIT_SATS, scriptPubKey: 'script', address: toAddress }],
187
- fee: response.fee,
188
- blockHeight: response.blockHeight,
189
- confirmations: response.confirmations
190
- };
191
- }
192
- async preventFrontRunning(satoshi) {
193
- if (!satoshi)
194
- throw new StructuredError('SATOSHI_REQUIRED', 'Satoshi identifier is required');
195
- // Naive implementation: check for multiple inscriptions on same satoshi via provider
196
- if (this.ord) {
197
- const list = await this.ord.getInscriptionsBySatoshi(satoshi);
198
- return list.length <= 1;
199
- }
200
- return true;
201
- }
202
- async getSatoshiFromInscription(inscriptionId) {
203
- if (this.ord) {
204
- const info = await this.ord.getInscriptionById(inscriptionId);
205
- const satoshi = info?.satoshi;
206
- // Validate satoshi before returning
207
- if (satoshi) {
208
- const validation = validateSatoshiNumber(satoshi);
209
- if (!validation.valid) {
210
- // Return null if validation fails (don't return empty or invalid string)
211
- return null;
212
- }
213
- return satoshi;
214
- }
215
- return null;
216
- }
217
- return null;
218
- }
219
- async validateBTCODID(didId) {
220
- // Validate that a did:btco DID exists on Bitcoin
221
- const satoshi = this.extractSatoshiFromBTCODID(didId);
222
- if (!satoshi)
223
- return false;
224
- // Validate the extracted satoshi number
225
- const validation = validateSatoshiNumber(satoshi);
226
- if (!validation.valid)
227
- return false;
228
- if (!this.ord)
229
- return false;
230
- const inscriptions = await this.ord.getInscriptionsBySatoshi(satoshi);
231
- return inscriptions.length > 0;
232
- }
233
- extractSatoshiFromBTCODID(didId) {
234
- // Extract satoshi identifier from did:btco DID
235
- if (!didId.startsWith('did:btco:'))
236
- return null;
237
- const parts = didId.split(':');
238
- let satoshi = null;
239
- // Handle different network prefixes:
240
- // did:btco:123456 (mainnet) - 3 parts
241
- // did:btco:test:123456 or did:btco:sig:123456 - 4 parts
242
- if (parts.length === 3) {
243
- satoshi = parts[2];
244
- }
245
- else if (parts.length === 4) {
246
- // Validate network prefix - only 'test' and 'sig' are allowed
247
- const network = parts[2];
248
- if (network !== 'test' && network !== 'sig') {
249
- return null;
250
- }
251
- satoshi = parts[3];
252
- }
253
- // Validate the extracted satoshi format
254
- if (satoshi) {
255
- const validation = validateSatoshiNumber(satoshi);
256
- if (!validation.valid) {
257
- return null;
258
- }
259
- }
260
- return satoshi;
261
- }
262
- }
@@ -1,30 +0,0 @@
1
- export interface TransactionStatus {
2
- confirmed: boolean;
3
- confirmations?: number;
4
- }
5
- export interface Broadcaster {
6
- (txHex: string): Promise<string>;
7
- }
8
- export interface StatusProvider {
9
- (txid: string): Promise<TransactionStatus>;
10
- }
11
- export interface BroadcastOptions {
12
- pollIntervalMs?: number;
13
- maxAttempts?: number;
14
- }
15
- /**
16
- * Broadcast client with idempotency and confirmation polling.
17
- * Designed to be predictable and simple, honoring behavior expected by the
18
- * ordinalsplus legacy components which are finicky about retries.
19
- */
20
- export declare class BroadcastClient {
21
- private readonly broadcaster;
22
- private readonly statusProvider;
23
- private inflight;
24
- constructor(broadcaster: Broadcaster, statusProvider: StatusProvider);
25
- broadcastIdempotent(txidKey: string, create: () => Promise<string>): Promise<string>;
26
- broadcastAndConfirm(txHex: string, options?: BroadcastOptions): Promise<{
27
- txid: string;
28
- confirmations: number;
29
- }>;
30
- }
@@ -1,35 +0,0 @@
1
- /**
2
- * Broadcast client with idempotency and confirmation polling.
3
- * Designed to be predictable and simple, honoring behavior expected by the
4
- * ordinalsplus legacy components which are finicky about retries.
5
- */
6
- export class BroadcastClient {
7
- constructor(broadcaster, statusProvider) {
8
- this.broadcaster = broadcaster;
9
- this.statusProvider = statusProvider;
10
- this.inflight = new Map();
11
- }
12
- broadcastIdempotent(txidKey, create) {
13
- if (this.inflight.has(txidKey))
14
- return this.inflight.get(txidKey);
15
- const p = (async () => create())();
16
- this.inflight.set(txidKey, p);
17
- return p.finally(() => this.inflight.delete(txidKey));
18
- }
19
- async broadcastAndConfirm(txHex, options = {}) {
20
- const txid = await this.broadcastIdempotent(txHex, () => this.broadcaster(txHex));
21
- const interval = Math.max(100, options.pollIntervalMs ?? 500);
22
- const maxAttempts = Math.max(1, options.maxAttempts ?? 20);
23
- let attempts = 0;
24
- let last = { confirmed: false };
25
- while (attempts < maxAttempts) {
26
- last = await this.statusProvider(txid);
27
- if (last.confirmed) {
28
- return { txid, confirmations: last.confirmations ?? 1 };
29
- }
30
- await new Promise(r => setTimeout(r, interval));
31
- attempts++;
32
- }
33
- return { txid, confirmations: last.confirmations ?? 0 };
34
- }
35
- }