@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,21 +0,0 @@
1
- import { OrdinalsInscription, BitcoinTransaction } from '../types';
2
- export declare class OrdinalsClient {
3
- private rpcUrl;
4
- private network;
5
- constructor(rpcUrl: string, network: 'mainnet' | 'regtest' | 'signet');
6
- getInscriptionById(id: string): Promise<OrdinalsInscription | null>;
7
- getInscriptionsBySatoshi(satoshi: string): Promise<OrdinalsInscription[]>;
8
- broadcastTransaction(tx: BitcoinTransaction): Promise<string>;
9
- getTransactionStatus(txid: string): Promise<{
10
- confirmed: boolean;
11
- blockHeight?: number;
12
- confirmations?: number;
13
- }>;
14
- estimateFee(blocks?: number): Promise<number>;
15
- getSatInfo(satoshi: string): Promise<{
16
- inscription_ids: string[];
17
- }>;
18
- resolveInscription(identifier: string): Promise<OrdinalsInscription | null>;
19
- getMetadata(inscriptionId: string): Promise<Record<string, unknown> | null>;
20
- private fetchJson;
21
- }
@@ -1,105 +0,0 @@
1
- import { decode as decodeCbor } from '../utils/cbor';
2
- import { hexToBytes } from '../utils/encoding';
3
- export class OrdinalsClient {
4
- constructor(rpcUrl, network) {
5
- this.rpcUrl = rpcUrl;
6
- this.network = network;
7
- }
8
- async getInscriptionById(id) {
9
- if (!id)
10
- return null;
11
- return this.resolveInscription(id);
12
- }
13
- async getInscriptionsBySatoshi(satoshi) {
14
- const info = await this.getSatInfo(satoshi);
15
- if (!info.inscription_ids.length)
16
- return [];
17
- const inscriptions = await Promise.all(info.inscription_ids.map(id => this.resolveInscription(id)));
18
- return inscriptions.filter((x) => x !== null);
19
- }
20
- async broadcastTransaction(tx) {
21
- return tx.txid || 'txid';
22
- }
23
- async getTransactionStatus(txid) {
24
- return { confirmed: false };
25
- }
26
- async estimateFee(blocks = 1) {
27
- return Math.max(1, blocks) * 10;
28
- }
29
- // Added provider-like helper methods commonly expected by higher-level resolvers
30
- // Minimal placeholder implementations suitable for unit testing
31
- async getSatInfo(satoshi) {
32
- const data = await this.fetchJson(`/sat/${satoshi}`);
33
- if (!data)
34
- return { inscription_ids: [] };
35
- // Support both {inscription_ids: []} and {data: {inscription_ids: []}} shapes via fetchJson
36
- const inscriptionIds = Array.isArray(data.inscription_ids) ? data.inscription_ids : [];
37
- return { inscription_ids: inscriptionIds };
38
- }
39
- async resolveInscription(identifier) {
40
- if (!identifier)
41
- return null;
42
- const info = await this.fetchJson(`/inscription/${identifier}`);
43
- if (!info)
44
- return null;
45
- // Fetch content bytes
46
- const contentUrl = info.content_url || `${this.rpcUrl}/content/${identifier}`;
47
- const contentRes = await fetch(contentUrl);
48
- if (!contentRes.ok)
49
- throw new Error(`Failed to fetch inscription content: ${contentRes.status}`);
50
- const contentArrayBuf = await contentRes.arrayBuffer();
51
- const content = Buffer.from(new Uint8Array(contentArrayBuf));
52
- // owner_output may be 'txid:vout'
53
- let txid = 'unknown';
54
- let vout = 0;
55
- if (typeof info.owner_output === 'string' && info.owner_output.includes(':')) {
56
- const [tid, v] = info.owner_output.split(':');
57
- txid = tid;
58
- vout = Number(v) || 0;
59
- }
60
- // sat number provided as number or string
61
- const satoshi = String(info.sat ?? '');
62
- const inscription = {
63
- satoshi,
64
- inscriptionId: info.inscription_id || identifier,
65
- content,
66
- contentType: info.content_type || 'application/octet-stream',
67
- txid,
68
- vout,
69
- blockHeight: info.block_height
70
- };
71
- return inscription;
72
- }
73
- async getMetadata(inscriptionId) {
74
- if (!inscriptionId)
75
- return null;
76
- const base = this.rpcUrl.replace(/\/$/, '');
77
- const res = await fetch(`${base}/r/metadata/${inscriptionId}`, { headers: { 'Accept': 'application/json' } });
78
- if (!res.ok) {
79
- return null;
80
- }
81
- let text = (await res.text()).trim();
82
- if (text.startsWith('"') && text.endsWith('"')) {
83
- try {
84
- text = JSON.parse(text);
85
- }
86
- catch (_) { }
87
- }
88
- try {
89
- const bytes = hexToBytes(text);
90
- return decodeCbor(bytes);
91
- }
92
- catch (_) {
93
- return null;
94
- }
95
- }
96
- async fetchJson(path) {
97
- const url = `${this.rpcUrl.replace(/\/$/, '')}${path}`;
98
- const res = await fetch(url, { headers: { 'Accept': 'application/json' } });
99
- if (!res.ok)
100
- return null;
101
- const body = await res.json();
102
- // Accept { data: T } or T
103
- return (body && typeof body === 'object' && 'data' in body) ? body.data : body;
104
- }
105
- }
@@ -1,24 +0,0 @@
1
- import type { Utxo } from '../types/bitcoin';
2
- export interface PsbtOutput {
3
- address: string;
4
- value: number;
5
- }
6
- export interface BuildPsbtParams {
7
- utxos: Utxo[];
8
- outputs: PsbtOutput[];
9
- changeAddress: string;
10
- feeRate: number;
11
- network: 'mainnet' | 'testnet' | 'regtest' | 'signet';
12
- dustLimit?: number;
13
- }
14
- export interface BuildPsbtResult {
15
- psbtBase64: string;
16
- selectedUtxos: Utxo[];
17
- fee: number;
18
- changeOutput?: PsbtOutput;
19
- }
20
- export declare class PSBTBuilder {
21
- private readonly dustLimit;
22
- constructor(dustLimit?: number);
23
- build(params: BuildPsbtParams): BuildPsbtResult;
24
- }
@@ -1,80 +0,0 @@
1
- function estimateVBytes(inputs, outputs) {
2
- const overhead = 10; // base tx overhead
3
- const inSize = 68; // rough P2WPKH/any-segwit input size
4
- const outSize = 31; // P2WPKH output size
5
- return Math.ceil(overhead + inputs * inSize + outputs * outSize);
6
- }
7
- export class PSBTBuilder {
8
- constructor(dustLimit = 546) {
9
- this.dustLimit = dustLimit;
10
- }
11
- build(params) {
12
- const { utxos, outputs, changeAddress, feeRate } = params;
13
- if (!utxos || utxos.length === 0)
14
- throw new Error('No UTXOs');
15
- if (!outputs || outputs.length === 0)
16
- throw new Error('No outputs');
17
- // Sort UTXOs ascending by value for simple greedy selection
18
- const sorted = [...utxos].sort((a, b) => a.value - b.value);
19
- // Start with smallest set to cover target + estimated fee; refine iteratively
20
- const targetValue = outputs.reduce((s, o) => s + o.value, 0);
21
- let selected = [];
22
- let total = 0;
23
- const pick = () => {
24
- selected = [];
25
- total = 0;
26
- for (const u of sorted) {
27
- selected.push(u);
28
- total += u.value;
29
- const vbytes = estimateVBytes(selected.length, outputs.length + 1); // +1 potential change
30
- const fee = Math.ceil(vbytes * feeRate);
31
- if (total >= targetValue + fee)
32
- break;
33
- }
34
- if (total < targetValue)
35
- throw new Error('Insufficient funds');
36
- };
37
- pick();
38
- const initialVBytes = estimateVBytes(selected.length, outputs.length + 1);
39
- let fee = Math.ceil(initialVBytes * feeRate);
40
- let change = total - targetValue - fee;
41
- let includeChange = change >= this.dustLimit;
42
- // Re-estimate once we know whether change is included
43
- const finalVBytes = estimateVBytes(selected.length, outputs.length + (includeChange ? 1 : 0));
44
- fee = Math.ceil(finalVBytes * feeRate);
45
- change = total - targetValue - fee;
46
- includeChange = change >= this.dustLimit;
47
- let changeOutput;
48
- if (!includeChange) {
49
- // Add dust to fee
50
- fee = total - targetValue;
51
- }
52
- else {
53
- changeOutput = { address: changeAddress, value: change };
54
- }
55
- // Construct a minimal PSBT-like payload for dry-run/testing. We intentionally avoid
56
- // bringing heavy bitcoin libraries here; this builder focuses on deterministic
57
- // selection, fee estimation, and change handling.
58
- const payload = {
59
- version: 0,
60
- inputs: selected.map(u => ({ txid: u.txid, vout: u.vout })),
61
- outputs: [
62
- ...outputs.map(o => ({ address: o.address, value: o.value })),
63
- ...(changeOutput ? [changeOutput] : [])
64
- ],
65
- fee
66
- };
67
- // Base64 encode via Node when available; fallback to btoa if present
68
- const json = JSON.stringify(payload);
69
- let psbtBase64;
70
- try {
71
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
72
- const B = global.Buffer;
73
- psbtBase64 = B ? B.from(json, 'utf8').toString('base64') : global.btoa(json);
74
- }
75
- catch {
76
- psbtBase64 = `psbt:${json}`;
77
- }
78
- return { psbtBase64, selectedUtxos: selected, fee, changeOutput };
79
- }
80
- }
@@ -1,14 +0,0 @@
1
- /**
2
- * Bitcoin Transaction Fee Calculation
3
- *
4
- * Utilities for calculating transaction fees based on size and fee rate.
5
- * Ported from legacy ordinalsplus transaction infrastructure.
6
- */
7
- /**
8
- * Calculate transaction fee based on vbytes and fee rate, ensuring minimum relay fee.
9
- *
10
- * @param vbytes - The virtual size of the transaction.
11
- * @param feeRate - The desired fee rate in sats/vbyte.
12
- * @returns The calculated fee in satoshis (bigint).
13
- */
14
- export declare const calculateFee: (vbytes: number, feeRate: number) => bigint;
@@ -1,31 +0,0 @@
1
- /**
2
- * Bitcoin Transaction Fee Calculation
3
- *
4
- * Utilities for calculating transaction fees based on size and fee rate.
5
- * Ported from legacy ordinalsplus transaction infrastructure.
6
- */
7
- // Define minimum relay fee rate (sats/vB)
8
- // Increased slightly from Bitcoin Core default of 1.0 for safety
9
- const MIN_RELAY_FEE_RATE = 1.1;
10
- /**
11
- * Calculate transaction fee based on vbytes and fee rate, ensuring minimum relay fee.
12
- *
13
- * @param vbytes - The virtual size of the transaction.
14
- * @param feeRate - The desired fee rate in sats/vbyte.
15
- * @returns The calculated fee in satoshis (bigint).
16
- */
17
- export const calculateFee = (vbytes, feeRate) => {
18
- // Ensure inputs are valid numbers
19
- if (isNaN(vbytes) || vbytes <= 0 || isNaN(feeRate) || feeRate <= 0) {
20
- console.warn(`[calculateFee] Invalid input: vbytes=${vbytes}, feeRate=${feeRate}. Returning 0.`);
21
- return 0n;
22
- }
23
- // Calculate fee based on the desired fee rate
24
- const calculatedFee = Math.ceil(vbytes * feeRate);
25
- // Calculate the minimum fee required for relay
26
- const minimumFee = Math.ceil(vbytes * MIN_RELAY_FEE_RATE);
27
- // Return the higher of the calculated fee or minimum relay fee
28
- // Ensure the result is a positive integer (minimum 1 sat)
29
- const finalFee = BigInt(Math.max(1, calculatedFee, minimumFee));
30
- return finalFee;
31
- };
@@ -1,38 +0,0 @@
1
- import type { ResourceProvider, LinkedResource, ResourceInfo, Inscription, ResourceCrawlOptions } from './types';
2
- export interface OrdNodeProviderOptions {
3
- nodeUrl: string;
4
- timeout?: number;
5
- network?: 'mainnet' | 'testnet' | 'signet';
6
- }
7
- export declare class OrdNodeProvider implements ResourceProvider {
8
- private readonly nodeUrl;
9
- private readonly timeout;
10
- private readonly network;
11
- constructor(options: OrdNodeProviderOptions);
12
- resolve(resourceId: string): Promise<LinkedResource>;
13
- resolveInscription(inscriptionId: string): Promise<Inscription>;
14
- resolveInfo(resourceId: string): Promise<ResourceInfo>;
15
- resolveCollection(did: string, _options?: {
16
- type?: string;
17
- limit?: number;
18
- offset?: number;
19
- }): Promise<LinkedResource[]>;
20
- getSatInfo(_satNumber: string): Promise<{
21
- inscription_ids: string[];
22
- }>;
23
- getMetadata(_inscriptionId: string): Promise<any>;
24
- getAllResources(_options?: ResourceCrawlOptions): AsyncGenerator<LinkedResource[]>;
25
- getAllResourcesChronological(_options?: ResourceCrawlOptions): AsyncGenerator<LinkedResource[]>;
26
- getInscriptionLocationsByAddress(_address: string): Promise<{
27
- id: string;
28
- location: string;
29
- }[]>;
30
- getInscriptionByNumber(_inscriptionNumber: number): Promise<Inscription>;
31
- getAddressOutputs(_address: string): Promise<string[]>;
32
- getOutputDetails(_outpoint: string): Promise<{
33
- value: number;
34
- script_pubkey: string;
35
- spent: boolean;
36
- inscriptions: string[];
37
- }>;
38
- }
@@ -1,67 +0,0 @@
1
- export class OrdNodeProvider {
2
- constructor(options) {
3
- this.nodeUrl = options.nodeUrl;
4
- this.timeout = options.timeout || 5000;
5
- this.network = options.network || 'mainnet';
6
- }
7
- async resolve(resourceId) {
8
- return {
9
- id: resourceId,
10
- type: 'Unknown',
11
- contentType: 'application/octet-stream',
12
- content_url: `${this.nodeUrl}/content/${resourceId}`
13
- };
14
- }
15
- async resolveInscription(inscriptionId) {
16
- return {
17
- id: inscriptionId,
18
- sat: 0,
19
- content_type: 'text/plain',
20
- content_url: `${this.nodeUrl}/content/${inscriptionId}`
21
- };
22
- }
23
- async resolveInfo(resourceId) {
24
- return {
25
- id: resourceId,
26
- type: 'Unknown',
27
- contentType: 'application/octet-stream',
28
- createdAt: new Date().toISOString(),
29
- updatedAt: new Date().toISOString(),
30
- content_url: `${this.nodeUrl}/content/${resourceId}`
31
- };
32
- }
33
- async resolveCollection(did, _options = {}) {
34
- return [];
35
- }
36
- async getSatInfo(_satNumber) {
37
- return { inscription_ids: [] };
38
- }
39
- async getMetadata(_inscriptionId) {
40
- return null;
41
- }
42
- async *getAllResources(_options = {}) {
43
- // no-op generator yields nothing
44
- return;
45
- }
46
- async *getAllResourcesChronological(_options = {}) {
47
- // no-op generator yields nothing
48
- return;
49
- }
50
- async getInscriptionLocationsByAddress(_address) {
51
- return [];
52
- }
53
- async getInscriptionByNumber(_inscriptionNumber) {
54
- return {
55
- id: '0',
56
- sat: 0,
57
- content_type: 'text/plain',
58
- content_url: `${this.nodeUrl}/content/0`
59
- };
60
- }
61
- async getAddressOutputs(_address) {
62
- return [];
63
- }
64
- async getOutputDetails(_outpoint) {
65
- return { value: 0, script_pubkey: '', spent: false, inscriptions: [] };
66
- }
67
- }
@@ -1,33 +0,0 @@
1
- import { OrdinalsClient } from '../OrdinalsClient';
2
- export interface OrdinalsProvider {
3
- getSatInfo(satNumber: string): Promise<{
4
- inscription_ids: string[];
5
- }>;
6
- resolveInscription(inscriptionId: string): Promise<{
7
- id: string;
8
- sat: number;
9
- content_type: string;
10
- content_url: string;
11
- }>;
12
- getMetadata(inscriptionId: string): Promise<any>;
13
- estimateFee(blocks?: number): Promise<number>;
14
- }
15
- export declare class OrdinalsClientProvider implements OrdinalsProvider {
16
- private client;
17
- private options?;
18
- constructor(client: OrdinalsClient, options?: {
19
- retries?: number;
20
- baseUrl?: string;
21
- } | undefined);
22
- getSatInfo(satNumber: string): Promise<{
23
- inscription_ids: string[];
24
- }>;
25
- resolveInscription(inscriptionId: string): Promise<{
26
- id: string;
27
- sat: number;
28
- content_type: string;
29
- content_url: string;
30
- }>;
31
- getMetadata(inscriptionId: string): Promise<any>;
32
- estimateFee(blocks?: number): Promise<number>;
33
- }
@@ -1,50 +0,0 @@
1
- import { withRetry } from '../../utils/retry';
2
- export class OrdinalsClientProvider {
3
- constructor(client, options) {
4
- this.client = client;
5
- this.options = options;
6
- }
7
- async getSatInfo(satNumber) {
8
- return withRetry(() => this.client.getSatInfo(satNumber), {
9
- maxRetries: this.options?.retries ?? 2,
10
- isRetriable: () => true
11
- });
12
- }
13
- async resolveInscription(inscriptionId) {
14
- return withRetry(async () => {
15
- const res = await this.client.getInscriptionById(inscriptionId);
16
- if (!res)
17
- throw new Error('Inscription not found');
18
- if (!res.satoshi)
19
- throw new Error('Inscription missing satoshi');
20
- const sat = Number(String(res.satoshi));
21
- if (Number.isNaN(sat))
22
- throw new Error('Invalid satoshi value');
23
- if (!res.contentType)
24
- throw new Error('Inscription missing contentType');
25
- const base = (this.options?.baseUrl || '').replace(/\/$/, '');
26
- if (!base)
27
- throw new Error('baseUrl is required to construct content_url');
28
- const id = res.inscriptionId;
29
- const content_url = `${base}/content/${id}`;
30
- return {
31
- id,
32
- sat,
33
- content_type: res.contentType,
34
- content_url
35
- };
36
- }, { maxRetries: this.options?.retries ?? 2, isRetriable: () => true });
37
- }
38
- async getMetadata(inscriptionId) {
39
- return withRetry(() => this.client.getMetadata(inscriptionId), {
40
- maxRetries: this.options?.retries ?? 2,
41
- isRetriable: () => true
42
- });
43
- }
44
- async estimateFee(blocks) {
45
- return withRetry(() => this.client.estimateFee(blocks), {
46
- maxRetries: this.options?.retries ?? 2,
47
- isRetriable: () => true
48
- });
49
- }
50
- }
@@ -1,63 +0,0 @@
1
- export interface LinkedResource {
2
- id: string;
3
- type: string;
4
- contentType: string;
5
- content_url: string;
6
- }
7
- export interface Inscription {
8
- id: string;
9
- sat: number;
10
- content_type: string;
11
- content_url: string;
12
- number?: number;
13
- height?: number;
14
- timestamp?: number;
15
- }
16
- export interface ResourceInfo {
17
- id: string;
18
- type: string;
19
- contentType: string;
20
- createdAt?: string;
21
- updatedAt?: string;
22
- content_url: string;
23
- }
24
- export interface ResourceProvider {
25
- resolve(resourceId: string): Promise<LinkedResource>;
26
- resolveInscription(inscriptionId: string): Promise<Inscription>;
27
- resolveInfo(resourceId: string): Promise<ResourceInfo>;
28
- resolveCollection(did: string, options: {
29
- type?: string;
30
- limit?: number;
31
- offset?: number;
32
- }): Promise<LinkedResource[]>;
33
- getSatInfo(satNumber: string): Promise<{
34
- inscription_ids: string[];
35
- }>;
36
- getMetadata(inscriptionId: string): Promise<any>;
37
- getAllResources(options?: ResourceCrawlOptions): AsyncGenerator<LinkedResource[]>;
38
- getAllResourcesChronological(options?: ResourceCrawlOptions): AsyncGenerator<LinkedResource[]>;
39
- getInscriptionLocationsByAddress(address: string): Promise<InscriptionRefWithLocation[]>;
40
- getInscriptionByNumber(inscriptionNumber: number): Promise<Inscription>;
41
- getAddressOutputs(address: string): Promise<string[]>;
42
- getOutputDetails(outpoint: string): Promise<{
43
- value: number;
44
- script_pubkey: string;
45
- spent: boolean;
46
- inscriptions: string[];
47
- }>;
48
- }
49
- export interface ResourceCrawlOptions {
50
- batchSize?: number;
51
- startFrom?: number;
52
- maxResources?: number;
53
- filter?: (resource: LinkedResource) => boolean;
54
- }
55
- export interface ResourceBatch {
56
- resources: LinkedResource[];
57
- nextCursor?: number;
58
- hasMore: boolean;
59
- }
60
- export interface InscriptionRefWithLocation {
61
- id: string;
62
- location: string;
63
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,89 +0,0 @@
1
- /**
2
- * Commit Transaction Processing for Ordinals
3
- *
4
- * This module implements the commit transaction process for ordinals inscriptions.
5
- * It handles the generation of the commit address and preparation of the commit transaction.
6
- *
7
- * Ported from legacy ordinalsplus transaction infrastructure.
8
- */
9
- import * as btc from '@scure/btc-signer';
10
- import { Utxo } from '../../types/bitcoin.js';
11
- /**
12
- * Bitcoin network type for @scure/btc-signer
13
- */
14
- type BitcoinNetwork = 'mainnet' | 'testnet' | 'regtest' | 'signet';
15
- /**
16
- * Parameters for creating a commit transaction
17
- */
18
- export interface CommitTransactionParams {
19
- /** Inscription content as Buffer */
20
- content: Buffer;
21
- /** MIME type of the content (e.g., 'text/plain', 'image/png') */
22
- contentType: string;
23
- /** Available UTXOs to fund the transaction */
24
- utxos: Utxo[];
25
- /** Address to send change back to */
26
- changeAddress: string;
27
- /** Fee rate in sats/vB */
28
- feeRate: number;
29
- /** Bitcoin network configuration */
30
- network: BitcoinNetwork;
31
- /** Optional minimum amount for the commit output */
32
- minimumCommitAmount?: number;
33
- /** Optional metadata for the inscription */
34
- metadata?: Record<string, unknown>;
35
- /** Optional pointer to target specific satoshi */
36
- pointer?: number;
37
- }
38
- /**
39
- * Result of the commit transaction creation
40
- */
41
- export interface CommitTransactionResult {
42
- /** P2TR address for the commit output */
43
- commitAddress: string;
44
- /** Base64-encoded PSBT for the commit transaction */
45
- commitPsbtBase64: string;
46
- /** Raw PSBT object for commit transaction (for direct manipulation) */
47
- commitPsbt: btc.Transaction;
48
- /** The exact amount sent to the commit output */
49
- commitAmount: number;
50
- /** Selected UTXOs for the transaction */
51
- selectedUtxos: Utxo[];
52
- /** Fee information */
53
- fees: {
54
- /** Fee for the commit transaction in satoshis */
55
- commit: number;
56
- };
57
- /** Reveal private key (hex string) - needed for reveal transaction */
58
- revealPrivateKey: string;
59
- /** Reveal public key (hex string) */
60
- revealPublicKey: string;
61
- /** Inscription script for reveal transaction */
62
- inscriptionScript: {
63
- script: Uint8Array;
64
- controlBlock: Uint8Array;
65
- leafVersion: number;
66
- };
67
- }
68
- /**
69
- * Creates a commit transaction for an ordinals inscription
70
- *
71
- * This function:
72
- * 1. Validates and filters UTXOs to ensure they are spendable
73
- * 2. Creates an inscription with the provided content
74
- * 3. Generates a reveal keypair and script
75
- * 4. Creates a P2TR commit address
76
- * 5. Selects UTXOs to fund the transaction (with iterative reselection if needed)
77
- * 6. Builds a PSBT with commit output and change
78
- *
79
- * The function ensures that:
80
- * - All selected UTXOs have valid scriptPubKey fields
81
- * - Total input value always covers output value + fees
82
- * - UTXO selection is re-run if fee increases after accurate calculation
83
- *
84
- * @param params - Parameters for the commit transaction
85
- * @returns Complete information for the prepared commit transaction
86
- * @throws Error if no valid UTXOs are available or insufficient funds
87
- */
88
- export declare function createCommitTransaction(params: CommitTransactionParams): Promise<CommitTransactionResult>;
89
- export {};