@originals/sdk 1.4.2 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. package/package.json +4 -1
  2. package/.eslintrc.json +0 -33
  3. package/src/adapters/FeeOracleMock.ts +0 -9
  4. package/src/adapters/index.ts +0 -5
  5. package/src/adapters/providers/OrdHttpProvider.ts +0 -126
  6. package/src/adapters/providers/OrdMockProvider.ts +0 -101
  7. package/src/adapters/types.ts +0 -66
  8. package/src/bitcoin/BitcoinManager.ts +0 -330
  9. package/src/bitcoin/BroadcastClient.ts +0 -54
  10. package/src/bitcoin/OrdinalsClient.ts +0 -119
  11. package/src/bitcoin/PSBTBuilder.ts +0 -106
  12. package/src/bitcoin/fee-calculation.ts +0 -38
  13. package/src/bitcoin/providers/OrdNodeProvider.ts +0 -92
  14. package/src/bitcoin/providers/OrdinalsProvider.ts +0 -56
  15. package/src/bitcoin/providers/types.ts +0 -59
  16. package/src/bitcoin/transactions/commit.ts +0 -465
  17. package/src/bitcoin/transactions/index.ts +0 -13
  18. package/src/bitcoin/transfer.ts +0 -43
  19. package/src/bitcoin/utxo-selection.ts +0 -322
  20. package/src/bitcoin/utxo.ts +0 -113
  21. package/src/contexts/credentials-v1.json +0 -237
  22. package/src/contexts/credentials-v2-examples.json +0 -5
  23. package/src/contexts/credentials-v2.json +0 -340
  24. package/src/contexts/credentials.json +0 -237
  25. package/src/contexts/data-integrity-v2.json +0 -81
  26. package/src/contexts/dids.json +0 -58
  27. package/src/contexts/ed255192020.json +0 -93
  28. package/src/contexts/ordinals-plus.json +0 -23
  29. package/src/contexts/originals.json +0 -22
  30. package/src/core/OriginalsSDK.ts +0 -416
  31. package/src/crypto/Multikey.ts +0 -194
  32. package/src/crypto/Signer.ts +0 -254
  33. package/src/crypto/noble-init.ts +0 -121
  34. package/src/did/BtcoDidResolver.ts +0 -227
  35. package/src/did/DIDManager.ts +0 -694
  36. package/src/did/Ed25519Verifier.ts +0 -68
  37. package/src/did/KeyManager.ts +0 -236
  38. package/src/did/WebVHManager.ts +0 -498
  39. package/src/did/createBtcoDidDocument.ts +0 -59
  40. package/src/did/providers/OrdinalsClientProviderAdapter.ts +0 -68
  41. package/src/events/EventEmitter.ts +0 -222
  42. package/src/events/index.ts +0 -19
  43. package/src/events/types.ts +0 -331
  44. package/src/examples/basic-usage.ts +0 -78
  45. package/src/examples/create-module-original.ts +0 -435
  46. package/src/examples/full-lifecycle-flow.ts +0 -514
  47. package/src/examples/run.ts +0 -60
  48. package/src/index.ts +0 -150
  49. package/src/kinds/KindRegistry.ts +0 -290
  50. package/src/kinds/index.ts +0 -74
  51. package/src/kinds/types.ts +0 -470
  52. package/src/kinds/validators/AgentValidator.ts +0 -257
  53. package/src/kinds/validators/AppValidator.ts +0 -211
  54. package/src/kinds/validators/DatasetValidator.ts +0 -242
  55. package/src/kinds/validators/DocumentValidator.ts +0 -311
  56. package/src/kinds/validators/MediaValidator.ts +0 -269
  57. package/src/kinds/validators/ModuleValidator.ts +0 -225
  58. package/src/kinds/validators/base.ts +0 -276
  59. package/src/kinds/validators/index.ts +0 -12
  60. package/src/lifecycle/BatchOperations.ts +0 -373
  61. package/src/lifecycle/LifecycleManager.ts +0 -2126
  62. package/src/lifecycle/OriginalsAsset.ts +0 -524
  63. package/src/lifecycle/ProvenanceQuery.ts +0 -280
  64. package/src/lifecycle/ResourceVersioning.ts +0 -163
  65. package/src/migration/MigrationManager.ts +0 -527
  66. package/src/migration/audit/AuditLogger.ts +0 -176
  67. package/src/migration/checkpoint/CheckpointManager.ts +0 -112
  68. package/src/migration/checkpoint/CheckpointStorage.ts +0 -101
  69. package/src/migration/index.ts +0 -33
  70. package/src/migration/operations/BaseMigration.ts +0 -126
  71. package/src/migration/operations/PeerToBtcoMigration.ts +0 -105
  72. package/src/migration/operations/PeerToWebvhMigration.ts +0 -62
  73. package/src/migration/operations/WebvhToBtcoMigration.ts +0 -105
  74. package/src/migration/rollback/RollbackManager.ts +0 -170
  75. package/src/migration/state/StateMachine.ts +0 -92
  76. package/src/migration/state/StateTracker.ts +0 -156
  77. package/src/migration/types.ts +0 -344
  78. package/src/migration/validation/BitcoinValidator.ts +0 -107
  79. package/src/migration/validation/CredentialValidator.ts +0 -62
  80. package/src/migration/validation/DIDCompatibilityValidator.ts +0 -151
  81. package/src/migration/validation/LifecycleValidator.ts +0 -64
  82. package/src/migration/validation/StorageValidator.ts +0 -79
  83. package/src/migration/validation/ValidationPipeline.ts +0 -213
  84. package/src/resources/ResourceManager.ts +0 -655
  85. package/src/resources/index.ts +0 -21
  86. package/src/resources/types.ts +0 -202
  87. package/src/storage/LocalStorageAdapter.ts +0 -61
  88. package/src/storage/MemoryStorageAdapter.ts +0 -29
  89. package/src/storage/StorageAdapter.ts +0 -25
  90. package/src/storage/index.ts +0 -3
  91. package/src/types/bitcoin.ts +0 -98
  92. package/src/types/common.ts +0 -92
  93. package/src/types/credentials.ts +0 -88
  94. package/src/types/did.ts +0 -31
  95. package/src/types/external-shims.d.ts +0 -53
  96. package/src/types/index.ts +0 -7
  97. package/src/types/network.ts +0 -175
  98. package/src/utils/EventLogger.ts +0 -298
  99. package/src/utils/Logger.ts +0 -322
  100. package/src/utils/MetricsCollector.ts +0 -358
  101. package/src/utils/bitcoin-address.ts +0 -130
  102. package/src/utils/cbor.ts +0 -12
  103. package/src/utils/encoding.ts +0 -127
  104. package/src/utils/hash.ts +0 -6
  105. package/src/utils/retry.ts +0 -46
  106. package/src/utils/satoshi-validation.ts +0 -196
  107. package/src/utils/serialization.ts +0 -96
  108. package/src/utils/telemetry.ts +0 -40
  109. package/src/utils/validation.ts +0 -119
  110. package/src/vc/CredentialManager.ts +0 -918
  111. package/src/vc/Issuer.ts +0 -100
  112. package/src/vc/Verifier.ts +0 -47
  113. package/src/vc/cryptosuites/bbs.ts +0 -253
  114. package/src/vc/cryptosuites/bbsSimple.ts +0 -21
  115. package/src/vc/cryptosuites/eddsa.ts +0 -99
  116. package/src/vc/documentLoader.ts +0 -67
  117. package/src/vc/proofs/data-integrity.ts +0 -33
  118. package/src/vc/utils/jsonld.ts +0 -18
  119. package/tests/__mocks__/bbs-signatures.js +0 -17
  120. package/tests/__mocks__/mf-base58.js +0 -24
  121. package/tests/fixtures/did-documents.ts +0 -247
  122. package/tests/index.test.ts +0 -21
  123. package/tests/integration/BatchOperations.test.ts +0 -531
  124. package/tests/integration/CompleteLifecycle.e2e.test.ts +0 -735
  125. package/tests/integration/CredentialManager.test.ts +0 -42
  126. package/tests/integration/DIDManager.test.ts +0 -41
  127. package/tests/integration/DidPeerToWebVhFlow.test.ts +0 -351
  128. package/tests/integration/Events.test.ts +0 -435
  129. package/tests/integration/Lifecycle.transfer.btco.integration.test.ts +0 -25
  130. package/tests/integration/LifecycleManager.test.ts +0 -21
  131. package/tests/integration/MultikeyFlow.test.ts +0 -52
  132. package/tests/integration/TelemetryIntegration.test.ts +0 -395
  133. package/tests/integration/WebVhPublish.test.ts +0 -48
  134. package/tests/integration/createTypedOriginal.test.ts +0 -379
  135. package/tests/integration/migration/peer-to-webvh.test.ts +0 -172
  136. package/tests/manual/test-commit-creation.ts +0 -323
  137. package/tests/mocks/MockKeyStore.ts +0 -38
  138. package/tests/mocks/adapters/MemoryStorageAdapter.ts +0 -24
  139. package/tests/mocks/adapters/MockFeeOracle.ts +0 -11
  140. package/tests/mocks/adapters/MockOrdinalsProvider.ts +0 -76
  141. package/tests/mocks/adapters/OrdMockProvider.test.ts +0 -176
  142. package/tests/mocks/adapters/index.ts +0 -6
  143. package/tests/performance/BatchOperations.perf.test.ts +0 -403
  144. package/tests/performance/logging.perf.test.ts +0 -336
  145. package/tests/sdk.test.ts +0 -43
  146. package/tests/security/bitcoin-penetration-tests.test.ts +0 -622
  147. package/tests/setup.bun.ts +0 -69
  148. package/tests/setup.jest.ts +0 -23
  149. package/tests/stress/batch-operations-stress.test.ts +0 -571
  150. package/tests/unit/adapters/FeeOracleMock.test.ts +0 -40
  151. package/tests/unit/bitcoin/BitcoinManager.test.ts +0 -293
  152. package/tests/unit/bitcoin/BroadcastClient.test.ts +0 -52
  153. package/tests/unit/bitcoin/OrdNodeProvider.test.ts +0 -53
  154. package/tests/unit/bitcoin/OrdinalsClient.test.ts +0 -381
  155. package/tests/unit/bitcoin/OrdinalsClientProvider.test.ts +0 -102
  156. package/tests/unit/bitcoin/PSBTBuilder.test.ts +0 -84
  157. package/tests/unit/bitcoin/fee-calculation.test.ts +0 -261
  158. package/tests/unit/bitcoin/transactions/commit.test.ts +0 -649
  159. package/tests/unit/bitcoin/transfer.test.ts +0 -31
  160. package/tests/unit/bitcoin/utxo-selection-new.test.ts +0 -502
  161. package/tests/unit/bitcoin/utxo.more.test.ts +0 -39
  162. package/tests/unit/bitcoin/utxo.selection.test.ts +0 -38
  163. package/tests/unit/core/OriginalsSDK.test.ts +0 -152
  164. package/tests/unit/crypto/Multikey.test.ts +0 -206
  165. package/tests/unit/crypto/Signer.test.ts +0 -408
  166. package/tests/unit/did/BtcoDidResolver.test.ts +0 -611
  167. package/tests/unit/did/DIDManager.more.test.ts +0 -43
  168. package/tests/unit/did/DIDManager.test.ts +0 -185
  169. package/tests/unit/did/Ed25519Verifier.test.ts +0 -160
  170. package/tests/unit/did/KeyManager.test.ts +0 -452
  171. package/tests/unit/did/OrdinalsClientProviderAdapter.test.ts +0 -45
  172. package/tests/unit/did/WebVHManager.test.ts +0 -435
  173. package/tests/unit/did/createBtcoDidDocument.test.ts +0 -67
  174. package/tests/unit/did/providers/OrdinalsClientProviderAdapter.test.ts +0 -159
  175. package/tests/unit/events/EventEmitter.test.ts +0 -407
  176. package/tests/unit/kinds/KindRegistry.test.ts +0 -329
  177. package/tests/unit/kinds/types.test.ts +0 -409
  178. package/tests/unit/kinds/validators.test.ts +0 -651
  179. package/tests/unit/lifecycle/BatchOperations.test.ts +0 -527
  180. package/tests/unit/lifecycle/LifecycleManager.cleanapi.test.ts +0 -441
  181. package/tests/unit/lifecycle/LifecycleManager.keymanagement.test.ts +0 -312
  182. package/tests/unit/lifecycle/LifecycleManager.prov.test.ts +0 -18
  183. package/tests/unit/lifecycle/LifecycleManager.test.ts +0 -213
  184. package/tests/unit/lifecycle/LifecycleManager.transfer.unit.test.ts +0 -30
  185. package/tests/unit/lifecycle/OriginalsAsset.test.ts +0 -176
  186. package/tests/unit/lifecycle/ProvenanceQuery.test.ts +0 -577
  187. package/tests/unit/lifecycle/ResourceVersioning.test.ts +0 -651
  188. package/tests/unit/resources/ResourceManager.test.ts +0 -740
  189. package/tests/unit/storage/MemoryStorageAdapter.test.ts +0 -93
  190. package/tests/unit/types/network.test.ts +0 -255
  191. package/tests/unit/utils/EventIntegration.test.ts +0 -384
  192. package/tests/unit/utils/Logger.test.ts +0 -473
  193. package/tests/unit/utils/MetricsCollector.test.ts +0 -358
  194. package/tests/unit/utils/bitcoin-address.test.ts +0 -250
  195. package/tests/unit/utils/cbor.test.ts +0 -35
  196. package/tests/unit/utils/encoding.test.ts +0 -318
  197. package/tests/unit/utils/hash.test.ts +0 -12
  198. package/tests/unit/utils/retry.test.ts +0 -100
  199. package/tests/unit/utils/satoshi-validation.test.ts +0 -354
  200. package/tests/unit/utils/serialization.test.ts +0 -124
  201. package/tests/unit/utils/telemetry.test.ts +0 -52
  202. package/tests/unit/utils/validation.test.ts +0 -141
  203. package/tests/unit/vc/CredentialManager.helpers.test.ts +0 -527
  204. package/tests/unit/vc/CredentialManager.test.ts +0 -487
  205. package/tests/unit/vc/Issuer.test.ts +0 -107
  206. package/tests/unit/vc/Verifier.test.ts +0 -525
  207. package/tests/unit/vc/bbs.test.ts +0 -282
  208. package/tests/unit/vc/cryptosuites/eddsa.test.ts +0 -398
  209. package/tests/unit/vc/documentLoader.test.ts +0 -121
  210. package/tests/unit/vc/proofs/data-integrity.test.ts +0 -24
  211. package/tsconfig.json +0 -31
  212. package/tsconfig.test.json +0 -15
@@ -1,403 +0,0 @@
1
- /**
2
- * Performance tests for Batch Operations
3
- *
4
- * Validates that batch operations scale linearly and achieve the required
5
- * cost savings (30%+) for batch inscriptions
6
- */
7
-
8
- import { describe, test, expect, beforeEach } from 'bun:test';
9
- import { OriginalsSDK } from '../../src/core/OriginalsSDK';
10
- import { OriginalsAsset } from '../../src/lifecycle/OriginalsAsset';
11
- import { AssetResource, OriginalsConfig } from '../../src/types';
12
- import { MemoryStorageAdapter } from '../../src/storage/MemoryStorageAdapter';
13
- import { FeeOracleMock } from '../../src/adapters/FeeOracleMock';
14
- import { OrdMockProvider } from '../../src/adapters/providers/OrdMockProvider';
15
- import { StorageAdapter as ConfigStorageAdapter } from '../../src/adapters/types';
16
- import { MockKeyStore } from '../mocks/MockKeyStore';
17
-
18
- function makeHash(prefix: string): string {
19
- const hexOnly = prefix.split('').map(c => {
20
- if (/[0-9a-f]/i.test(c)) return c;
21
- return c.charCodeAt(0).toString(16).slice(-1);
22
- }).join('');
23
- return hexOnly.padEnd(64, '0');
24
- }
25
-
26
- class StorageAdapterBridge implements ConfigStorageAdapter {
27
- constructor(private memoryAdapter: MemoryStorageAdapter) {}
28
-
29
- async put(objectKey: string, data: Buffer | string, options?: { contentType?: string }): Promise<string> {
30
- const firstSlash = objectKey.indexOf('/');
31
- const domain = firstSlash >= 0 ? objectKey.substring(0, firstSlash) : objectKey;
32
- const path = firstSlash >= 0 ? objectKey.substring(firstSlash + 1) : '';
33
- const content = typeof data === 'string' ? Buffer.from(data) : data;
34
- return await this.memoryAdapter.putObject(domain, path, new Uint8Array(content));
35
- }
36
-
37
- async get(objectKey: string): Promise<{ content: Buffer; contentType: string } | null> {
38
- const firstSlash = objectKey.indexOf('/');
39
- const domain = firstSlash >= 0 ? objectKey.substring(0, firstSlash) : objectKey;
40
- const path = firstSlash >= 0 ? objectKey.substring(firstSlash + 1) : '';
41
- const result = await this.memoryAdapter.getObject(domain, path);
42
- if (!result) return null;
43
- return {
44
- content: Buffer.from(result.content),
45
- contentType: result.contentType || 'application/octet-stream'
46
- };
47
- }
48
-
49
- async delete(objectKey: string): Promise<boolean> {
50
- const firstSlash = objectKey.indexOf('/');
51
- const domain = firstSlash >= 0 ? objectKey.substring(0, firstSlash) : objectKey;
52
- const path = firstSlash >= 0 ? objectKey.substring(firstSlash + 1) : '';
53
- return await this.memoryAdapter.deleteObject(domain, path);
54
- }
55
- }
56
-
57
- describe('Batch Operations Performance', () => {
58
- let sdk: OriginalsSDK;
59
-
60
- beforeEach(() => {
61
- const memoryStorage = new MemoryStorageAdapter();
62
- const storageAdapter = new StorageAdapterBridge(memoryStorage);
63
- const feeOracle = new FeeOracleMock(10);
64
- const ordinalsProvider = new OrdMockProvider();
65
- const keyStore = new MockKeyStore();
66
-
67
- const config: OriginalsConfig = {
68
- network: 'regtest',
69
- defaultKeyType: 'ES256K',
70
- enableLogging: false,
71
- storageAdapter,
72
- feeOracle,
73
- ordinalsProvider
74
- };
75
-
76
- sdk = new OriginalsSDK(config, keyStore);
77
- });
78
-
79
- describe('Linear Scaling', () => {
80
- test('batch creation should scale linearly', async () => {
81
- const sizes = [10, 50, 100];
82
- const timings: Array<{ size: number; duration: number; perItem: number }> = [];
83
-
84
- for (const size of sizes) {
85
- const resourcesList = Array.from({ length: size }, (_, i) => [
86
- { id: `res${i}`, type: 'text', contentType: 'text/plain', hash: makeHash(`txt${i}`), content: `text${i}` }
87
- ]);
88
-
89
- const startTime = Date.now();
90
- const result = await sdk.lifecycle.batchCreateAssets(resourcesList, {
91
- maxConcurrent: 5
92
- });
93
- const duration = Date.now() - startTime;
94
-
95
- expect(result.successful).toHaveLength(size);
96
-
97
- timings.push({
98
- size,
99
- duration,
100
- perItem: duration / size
101
- });
102
- }
103
-
104
- // Print performance report
105
- console.log('\nBatch Creation Performance:');
106
- console.log('Size\tDuration\tPer Item');
107
- for (const timing of timings) {
108
- console.log(`${timing.size}\t${timing.duration}ms\t\t${timing.perItem.toFixed(2)}ms`);
109
- }
110
-
111
- // Verify roughly linear scaling (per-item time should be relatively constant)
112
- const perItemTimes = timings.map(t => t.perItem);
113
- const avgPerItem = perItemTimes.reduce((sum, t) => sum + t, 0) / perItemTimes.length;
114
-
115
- // All per-item times should be within 3x of average (allowing for overhead)
116
- for (const perItemTime of perItemTimes) {
117
- expect(perItemTime).toBeLessThan(avgPerItem * 3);
118
- }
119
- });
120
-
121
- test('batch inscription should scale linearly', async () => {
122
- const sizes = [5, 10, 20];
123
- const timings: Array<{ size: number; duration: number; perItem: number }> = [];
124
-
125
- for (const size of sizes) {
126
- // Create assets
127
- const assets: OriginalsAsset[] = [];
128
- for (let i = 0; i < size; i++) {
129
- const asset = await sdk.lifecycle.createAsset([
130
- { id: `res${i}`, type: 'text', contentType: 'text/plain', hash: makeHash(`txt${i}`), content: `text${i}` }
131
- ]);
132
- assets.push(asset);
133
- }
134
-
135
- // Batch inscribe with individual transactions
136
- const startTime = Date.now();
137
- const result = await sdk.lifecycle.batchInscribeOnBitcoin(assets, {
138
- singleTransaction: false,
139
- feeRate: 10,
140
- maxConcurrent: 3
141
- });
142
- const duration = Date.now() - startTime;
143
-
144
- expect(result.successful).toHaveLength(size);
145
-
146
- timings.push({
147
- size,
148
- duration,
149
- perItem: duration / size
150
- });
151
- }
152
-
153
- // Print performance report
154
- console.log('\nBatch Inscription Performance (Individual Transactions):');
155
- console.log('Size\tDuration\tPer Item');
156
- for (const timing of timings) {
157
- console.log(`${timing.size}\t${timing.duration}ms\t\t${timing.perItem.toFixed(2)}ms`);
158
- }
159
- });
160
- });
161
-
162
- describe('Memory Usage', () => {
163
- test('should handle large batches without memory issues', async () => {
164
- const size = 200;
165
- const resourcesList = Array.from({ length: size }, (_, i) => [
166
- { id: `res${i}`, type: 'text', contentType: 'text/plain', hash: makeHash(`txt${i}`), content: `text${i}` }
167
- ]);
168
-
169
- // Monitor memory usage (if available)
170
- const memBefore = process.memoryUsage ? process.memoryUsage().heapUsed : 0;
171
-
172
- const result = await sdk.lifecycle.batchCreateAssets(resourcesList, {
173
- maxConcurrent: 10
174
- });
175
-
176
- const memAfter = process.memoryUsage ? process.memoryUsage().heapUsed : 0;
177
- const memIncreaseMB = (memAfter - memBefore) / 1024 / 1024;
178
-
179
- expect(result.successful).toHaveLength(size);
180
-
181
- // Memory increase should be reasonable (less than 100MB for 200 assets)
182
- console.log(`\nMemory increase for 200 assets: ${memIncreaseMB.toFixed(2)} MB`);
183
- expect(memIncreaseMB).toBeLessThan(100);
184
- });
185
-
186
- test('should process very large batches with chunking', async () => {
187
- const size = 500;
188
- const resourcesList = Array.from({ length: size }, (_, i) => [
189
- { id: `res${i}`, type: 'text', contentType: 'text/plain', hash: makeHash(`txt${i}`), content: `text${i}` }
190
- ]);
191
-
192
- const startTime = Date.now();
193
- const result = await sdk.lifecycle.batchCreateAssets(resourcesList, {
194
- maxConcurrent: 20
195
- });
196
- const duration = Date.now() - startTime;
197
-
198
- expect(result.successful).toHaveLength(size);
199
- console.log(`\nProcessed ${size} assets in ${duration}ms (${(duration / size).toFixed(2)}ms per item)`);
200
-
201
- // Should complete in reasonable time even for large batches
202
- expect(duration).toBeLessThan(60000); // 60 seconds
203
- });
204
- });
205
-
206
- describe('Cost Savings', () => {
207
- test('single transaction batch should save 30%+ on fees', async () => {
208
- const size = 10;
209
- const assets: OriginalsAsset[] = [];
210
-
211
- for (let i = 0; i < size; i++) {
212
- const asset = await sdk.lifecycle.createAsset([
213
- { id: `res${i}`, type: 'text', contentType: 'text/plain', hash: makeHash(`txt${i}`), content: `text${i}` }
214
- ]);
215
- assets.push(asset);
216
- }
217
-
218
- // Track cost savings from batch events
219
- let costSavings: any = null;
220
- sdk.lifecycle.on('batch:completed', (event) => {
221
- if (event.results.costSavings) {
222
- costSavings = event.results.costSavings;
223
- }
224
- });
225
-
226
- await sdk.lifecycle.batchInscribeOnBitcoin(assets, {
227
- singleTransaction: true,
228
- feeRate: 10
229
- });
230
-
231
- expect(costSavings).toBeDefined();
232
- expect(costSavings.percentage).toBeGreaterThanOrEqual(30);
233
-
234
- console.log('\nCost Savings Analysis:');
235
- console.log(`Batch Fee: ${costSavings.amount} sats`);
236
- console.log(`Individual Fees Total: ${costSavings.amount + costSavings.amount} sats`);
237
- console.log(`Savings: ${costSavings.amount} sats (${costSavings.percentage.toFixed(2)}%)`);
238
- });
239
-
240
- test.skip('cost savings should increase with batch size', async () => {
241
- const sizes = [5, 10, 20];
242
- const savingsResults: Array<{ size: number; percentage: number; amount: number }> = [];
243
-
244
- for (const size of sizes) {
245
- const assets: OriginalsAsset[] = [];
246
- for (let i = 0; i < size; i++) {
247
- const asset = await sdk.lifecycle.createAsset([
248
- { id: `res${i}`, type: 'text', contentType: 'text/plain', hash: makeHash(`txt${i}`), content: `text${i}` }
249
- ]);
250
- assets.push(asset);
251
- }
252
-
253
- let costSavings: any = null;
254
- const unsubscribe = sdk.lifecycle.on('batch:completed', (event) => {
255
- if (event.results.costSavings) {
256
- costSavings = event.results.costSavings;
257
- }
258
- });
259
-
260
- await sdk.lifecycle.batchInscribeOnBitcoin(assets, {
261
- singleTransaction: true,
262
- feeRate: 10
263
- });
264
-
265
- unsubscribe();
266
-
267
- savingsResults.push({
268
- size,
269
- percentage: costSavings.percentage,
270
- amount: costSavings.amount
271
- });
272
- }
273
-
274
- console.log('\nCost Savings by Batch Size:');
275
- console.log('Size\tSavings %\tSavings (sats)');
276
- for (const result of savingsResults) {
277
- console.log(`${result.size}\t${result.percentage.toFixed(2)}%\t\t${result.amount}`);
278
- }
279
-
280
- // Verify all meet 30% threshold
281
- for (const result of savingsResults) {
282
- expect(result.percentage).toBeGreaterThanOrEqual(30);
283
- }
284
-
285
- // Larger batches should generally save more (in absolute terms)
286
- expect(savingsResults[2].amount).toBeGreaterThan(savingsResults[0].amount);
287
- });
288
- });
289
-
290
- describe('Concurrency Performance', () => {
291
- test.skip('concurrent processing should be faster than sequential', async () => {
292
- const size = 20;
293
- const resourcesList = Array.from({ length: size }, (_, i) => [
294
- { id: `res${i}`, type: 'text', contentType: 'text/plain', hash: makeHash(`txt${i}`), content: `text${i}` }
295
- ]);
296
-
297
- // Sequential processing
298
- const startSeq = Date.now();
299
- const resultSeq = await sdk.lifecycle.batchCreateAssets(resourcesList, {
300
- maxConcurrent: 1
301
- });
302
- const durationSeq = Date.now() - startSeq;
303
-
304
- // Create new assets for concurrent test
305
- const resourcesList2 = Array.from({ length: size }, (_, i) => [
306
- { id: `res2-${i}`, type: 'text', contentType: 'text/plain', hash: makeHash(`txt2-${i}`), content: `text${i}` }
307
- ]);
308
-
309
- // Concurrent processing
310
- const startConc = Date.now();
311
- const resultConc = await sdk.lifecycle.batchCreateAssets(resourcesList2, {
312
- maxConcurrent: 10
313
- });
314
- const durationConc = Date.now() - startConc;
315
-
316
- console.log('\nConcurrency Performance:');
317
- console.log(`Sequential (maxConcurrent=1): ${durationSeq}ms`);
318
- console.log(`Concurrent (maxConcurrent=10): ${durationConc}ms`);
319
- console.log(`Speedup: ${(durationSeq / durationConc).toFixed(2)}x`);
320
-
321
- expect(resultSeq.successful).toHaveLength(size);
322
- expect(resultConc.successful).toHaveLength(size);
323
-
324
- // Concurrent should be faster (allowing some variance for system load)
325
- // We expect at least some speedup, though not necessarily 10x due to overhead
326
- expect(durationConc).toBeLessThanOrEqual(durationSeq);
327
- });
328
- });
329
-
330
- describe('Stress Tests', () => {
331
- test('should handle rapid successive batch operations', async () => {
332
- const batches = 5;
333
- const batchSize = 10;
334
-
335
- const results = [];
336
- for (let b = 0; b < batches; b++) {
337
- const resourcesList = Array.from({ length: batchSize }, (_, i) => [
338
- { id: `batch${b}-res${i}`, type: 'text', contentType: 'text/plain', hash: makeHash(`b${b}txt${i}`), content: `text${i}` }
339
- ]);
340
-
341
- const result = await sdk.lifecycle.batchCreateAssets(resourcesList, {
342
- maxConcurrent: 5
343
- });
344
- results.push(result);
345
- }
346
-
347
- // All batches should succeed
348
- for (const result of results) {
349
- expect(result.successful).toHaveLength(batchSize);
350
- expect(result.failed).toHaveLength(0);
351
- }
352
-
353
- console.log(`\nSuccessfully processed ${batches} batches of ${batchSize} assets each`);
354
- });
355
-
356
- test('should maintain performance with mixed operations', async () => {
357
- const size = 10;
358
-
359
- // Create assets
360
- const resourcesList = Array.from({ length: size }, (_, i) => [
361
- { id: `res${i}`, type: 'text', contentType: 'text/plain', hash: makeHash(`txt${i}`), content: `text${i}` }
362
- ]);
363
-
364
- const startTime = Date.now();
365
-
366
- // Phase 1: Create
367
- const createResult = await sdk.lifecycle.batchCreateAssets(resourcesList, {
368
- maxConcurrent: 5
369
- });
370
- const createTime = Date.now() - startTime;
371
-
372
- // Phase 2: Publish
373
- const publishStart = Date.now();
374
- const publishResult = await sdk.lifecycle.batchPublishToWeb(
375
- createResult.successful.map(s => s.result),
376
- 'perf.test',
377
- { maxConcurrent: 5 }
378
- );
379
- const publishTime = Date.now() - publishStart;
380
-
381
- // Phase 3: Inscribe
382
- const inscribeStart = Date.now();
383
- const inscribeResult = await sdk.lifecycle.batchInscribeOnBitcoin(
384
- publishResult.successful.map(s => s.result),
385
- { singleTransaction: true, feeRate: 10 }
386
- );
387
- const inscribeTime = Date.now() - inscribeStart;
388
-
389
- const totalTime = Date.now() - startTime;
390
-
391
- console.log('\nMixed Operations Performance:');
392
- console.log(`Create: ${createTime}ms`);
393
- console.log(`Publish: ${publishTime}ms`);
394
- console.log(`Inscribe: ${inscribeTime}ms`);
395
- console.log(`Total: ${totalTime}ms`);
396
- console.log(`Average per asset: ${(totalTime / size).toFixed(2)}ms`);
397
-
398
- expect(createResult.successful).toHaveLength(size);
399
- expect(publishResult.successful).toHaveLength(size);
400
- expect(inscribeResult.successful).toHaveLength(size);
401
- });
402
- });
403
- });