@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,358 +0,0 @@
1
- import { describe, test, expect, beforeEach } from 'bun:test';
2
- import { MetricsCollector } from '../../../src/utils/MetricsCollector';
3
-
4
- describe('MetricsCollector', () => {
5
- let metrics: MetricsCollector;
6
-
7
- beforeEach(() => {
8
- metrics = new MetricsCollector();
9
- });
10
-
11
- describe('operation recording', () => {
12
- test('should record operation with duration and success', () => {
13
- metrics.recordOperation('testOp', 100, true);
14
-
15
- const opMetrics = metrics.getOperationMetrics('testOp');
16
-
17
- expect(opMetrics).not.toBeNull();
18
- expect(opMetrics!.count).toBe(1);
19
- expect(opMetrics!.totalTime).toBe(100);
20
- expect(opMetrics!.avgTime).toBe(100);
21
- expect(opMetrics!.minTime).toBe(100);
22
- expect(opMetrics!.maxTime).toBe(100);
23
- expect(opMetrics!.errorCount).toBe(0);
24
- });
25
-
26
- test('should record multiple operations and calculate statistics', () => {
27
- metrics.recordOperation('testOp', 50, true);
28
- metrics.recordOperation('testOp', 100, true);
29
- metrics.recordOperation('testOp', 150, true);
30
-
31
- const opMetrics = metrics.getOperationMetrics('testOp');
32
-
33
- expect(opMetrics!.count).toBe(3);
34
- expect(opMetrics!.totalTime).toBe(300);
35
- expect(opMetrics!.avgTime).toBe(100);
36
- expect(opMetrics!.minTime).toBe(50);
37
- expect(opMetrics!.maxTime).toBe(150);
38
- });
39
-
40
- test('should track errors in operations', () => {
41
- metrics.recordOperation('testOp', 50, true);
42
- metrics.recordOperation('testOp', 100, false);
43
- metrics.recordOperation('testOp', 75, false);
44
-
45
- const opMetrics = metrics.getOperationMetrics('testOp');
46
-
47
- expect(opMetrics!.count).toBe(3);
48
- expect(opMetrics!.errorCount).toBe(2);
49
- });
50
-
51
- test('should return null for non-existent operation', () => {
52
- const opMetrics = metrics.getOperationMetrics('nonExistent');
53
-
54
- expect(opMetrics).toBeNull();
55
- });
56
- });
57
-
58
- describe('startOperation helper', () => {
59
- test('should track operation duration automatically', () => {
60
- const complete = metrics.startOperation('autoOp');
61
-
62
- // Simulate work
63
- const start = Date.now();
64
- while (Date.now() - start < 10) {
65
- // Wait 10ms
66
- }
67
-
68
- complete(true);
69
-
70
- const opMetrics = metrics.getOperationMetrics('autoOp');
71
-
72
- expect(opMetrics!.count).toBe(1);
73
- expect(opMetrics!.totalTime).toBeGreaterThanOrEqual(9);
74
- });
75
-
76
- test('should record success or failure', () => {
77
- const complete1 = metrics.startOperation('op1');
78
- complete1(true);
79
-
80
- const complete2 = metrics.startOperation('op1');
81
- complete2(false);
82
-
83
- const opMetrics = metrics.getOperationMetrics('op1');
84
-
85
- expect(opMetrics!.count).toBe(2);
86
- expect(opMetrics!.errorCount).toBe(1);
87
- });
88
- });
89
-
90
- describe('asset lifecycle metrics', () => {
91
- test('should record asset creations', () => {
92
- metrics.recordAssetCreated();
93
- metrics.recordAssetCreated();
94
- metrics.recordAssetCreated();
95
-
96
- const allMetrics = metrics.getMetrics();
97
-
98
- expect(allMetrics.assetsCreated).toBe(3);
99
- });
100
-
101
- test('should record migrations by layer transition', () => {
102
- metrics.recordMigration('did:peer', 'did:webvh');
103
- metrics.recordMigration('did:peer', 'did:webvh');
104
- metrics.recordMigration('did:webvh', 'did:btco');
105
-
106
- const allMetrics = metrics.getMetrics();
107
-
108
- expect(allMetrics.assetsMigrated['peer→webvh']).toBe(2);
109
- expect(allMetrics.assetsMigrated['webvh→btco']).toBe(1);
110
- });
111
-
112
- test('should record asset transfers', () => {
113
- metrics.recordTransfer();
114
- metrics.recordTransfer();
115
-
116
- const allMetrics = metrics.getMetrics();
117
-
118
- expect(allMetrics.assetsTransferred).toBe(2);
119
- });
120
- });
121
-
122
- describe('error tracking', () => {
123
- test('should track errors by code', () => {
124
- metrics.recordError('ERR_001');
125
- metrics.recordError('ERR_001');
126
- metrics.recordError('ERR_002');
127
-
128
- const allMetrics = metrics.getMetrics();
129
-
130
- expect(allMetrics.errors['ERR_001']).toBe(2);
131
- expect(allMetrics.errors['ERR_002']).toBe(1);
132
- });
133
-
134
- test('should increment operation error count when operation is provided', () => {
135
- // First create some operations
136
- metrics.recordOperation('testOp', 100, true);
137
-
138
- // Then record errors for that operation
139
- metrics.recordError('ERR_001', 'testOp');
140
- metrics.recordError('ERR_002', 'testOp');
141
-
142
- const opMetrics = metrics.getOperationMetrics('testOp');
143
-
144
- expect(opMetrics!.errorCount).toBe(2);
145
- });
146
- });
147
-
148
- describe('cache statistics', () => {
149
- test('should track cache hits and misses', () => {
150
- metrics.recordCacheHit();
151
- metrics.recordCacheHit();
152
- metrics.recordCacheMiss();
153
-
154
- const allMetrics = metrics.getMetrics();
155
-
156
- expect(allMetrics.cacheStats).toBeDefined();
157
- expect(allMetrics.cacheStats!.hits).toBe(2);
158
- expect(allMetrics.cacheStats!.misses).toBe(1);
159
- expect(allMetrics.cacheStats!.hitRate).toBeCloseTo(2 / 3);
160
- });
161
-
162
- test('should return undefined cache stats when no cache operations', () => {
163
- const allMetrics = metrics.getMetrics();
164
-
165
- expect(allMetrics.cacheStats).toBeUndefined();
166
- });
167
-
168
- test('should calculate hit rate correctly', () => {
169
- // 80% hit rate
170
- for (let i = 0; i < 8; i++) {
171
- metrics.recordCacheHit();
172
- }
173
- for (let i = 0; i < 2; i++) {
174
- metrics.recordCacheMiss();
175
- }
176
-
177
- const allMetrics = metrics.getMetrics();
178
-
179
- expect(allMetrics.cacheStats!.hitRate).toBe(0.8);
180
- });
181
- });
182
-
183
- describe('system metrics', () => {
184
- test('should track start time', () => {
185
- const allMetrics = metrics.getMetrics();
186
-
187
- expect(allMetrics.startTime).toBeDefined();
188
- expect(new Date(allMetrics.startTime).getTime()).toBeLessThanOrEqual(Date.now());
189
- });
190
-
191
- test('should track uptime', async () => {
192
- await new Promise(resolve => setTimeout(resolve, 10));
193
-
194
- const allMetrics = metrics.getMetrics();
195
-
196
- expect(allMetrics.uptime).toBeGreaterThanOrEqual(9);
197
- });
198
- });
199
-
200
- describe('reset functionality', () => {
201
- test('should reset all metrics', () => {
202
- // Record various metrics
203
- metrics.recordAssetCreated();
204
- metrics.recordMigration('did:peer', 'did:webvh');
205
- metrics.recordTransfer();
206
- metrics.recordOperation('testOp', 100, true);
207
- metrics.recordError('ERR_001');
208
- metrics.recordCacheHit();
209
- metrics.recordCacheMiss();
210
-
211
- // Reset
212
- metrics.reset();
213
-
214
- const allMetrics = metrics.getMetrics();
215
-
216
- expect(allMetrics.assetsCreated).toBe(0);
217
- expect(Object.keys(allMetrics.assetsMigrated).length).toBe(0);
218
- expect(allMetrics.assetsTransferred).toBe(0);
219
- expect(Object.keys(allMetrics.operationTimes).length).toBe(0);
220
- expect(Object.keys(allMetrics.errors).length).toBe(0);
221
- expect(allMetrics.cacheStats).toBeUndefined();
222
- });
223
- });
224
-
225
- describe('export formats', () => {
226
- beforeEach(() => {
227
- // Set up some test metrics
228
- metrics.recordAssetCreated();
229
- metrics.recordAssetCreated();
230
- metrics.recordMigration('did:peer', 'did:webvh');
231
- metrics.recordTransfer();
232
- metrics.recordOperation('createAsset', 150, true);
233
- metrics.recordOperation('createAsset', 200, true);
234
- metrics.recordOperation('createAsset', 250, false);
235
- metrics.recordError('ERR_001');
236
- metrics.recordCacheHit();
237
- metrics.recordCacheMiss();
238
- });
239
-
240
- test('should export as JSON', () => {
241
- const json = metrics.export('json');
242
-
243
- expect(() => JSON.parse(json)).not.toThrow();
244
-
245
- const parsed = JSON.parse(json);
246
- expect(parsed.assetsCreated).toBe(2);
247
- expect(parsed.assetsMigrated['peer→webvh']).toBe(1);
248
- expect(parsed.assetsTransferred).toBe(1);
249
- });
250
-
251
- test('should export as Prometheus format', () => {
252
- const prometheus = metrics.export('prometheus');
253
-
254
- // Check for expected Prometheus metrics
255
- expect(prometheus).toContain('originals_assets_created_total');
256
- expect(prometheus).toContain('originals_assets_transferred_total');
257
- expect(prometheus).toContain('originals_assets_migrated_total');
258
- expect(prometheus).toContain('originals_operation_createAsset_total');
259
- expect(prometheus).toContain('originals_operation_createAsset_duration_milliseconds');
260
- expect(prometheus).toContain('originals_errors_total');
261
- expect(prometheus).toContain('originals_cache_hits_total');
262
- expect(prometheus).toContain('originals_uptime_milliseconds');
263
- });
264
-
265
- test('should format Prometheus metrics correctly', () => {
266
- const prometheus = metrics.export('prometheus');
267
-
268
- // Check specific values
269
- expect(prometheus).toContain('originals_assets_created_total 2');
270
- expect(prometheus).toContain('originals_assets_transferred_total 1');
271
- expect(prometheus).toContain('originals_assets_migrated_total{from="peer",to="webvh"} 1');
272
- });
273
-
274
- test('should include operation statistics in Prometheus format', () => {
275
- const prometheus = metrics.export('prometheus');
276
-
277
- // Check for operation metrics
278
- expect(prometheus).toContain('originals_operation_createAsset_total 3');
279
- expect(prometheus).toContain('originals_operation_createAsset_errors_total 1');
280
-
281
- // Check for duration quantiles
282
- expect(prometheus).toContain('originals_operation_createAsset_duration_milliseconds{quantile="0.0"}');
283
- expect(prometheus).toContain('originals_operation_createAsset_duration_milliseconds{quantile="0.5"}');
284
- expect(prometheus).toContain('originals_operation_createAsset_duration_milliseconds{quantile="1.0"}');
285
- });
286
-
287
- test('should throw error for unsupported format', () => {
288
- expect(() => metrics.export('xml' as any)).toThrow('Unsupported export format');
289
- });
290
- });
291
-
292
- describe('comprehensive metrics snapshot', () => {
293
- test('should provide complete metrics snapshot', () => {
294
- // Set up comprehensive metrics
295
- metrics.recordAssetCreated();
296
- metrics.recordMigration('did:peer', 'did:webvh');
297
- metrics.recordMigration('did:webvh', 'did:btco');
298
- metrics.recordTransfer();
299
- metrics.recordOperation('op1', 100, true);
300
- metrics.recordOperation('op2', 200, false);
301
- metrics.recordError('ERR_001');
302
- metrics.recordCacheHit();
303
-
304
- const allMetrics = metrics.getMetrics();
305
-
306
- // Verify structure
307
- expect(allMetrics).toHaveProperty('assetsCreated');
308
- expect(allMetrics).toHaveProperty('assetsMigrated');
309
- expect(allMetrics).toHaveProperty('assetsTransferred');
310
- expect(allMetrics).toHaveProperty('operationTimes');
311
- expect(allMetrics).toHaveProperty('errors');
312
- expect(allMetrics).toHaveProperty('cacheStats');
313
- expect(allMetrics).toHaveProperty('startTime');
314
- expect(allMetrics).toHaveProperty('uptime');
315
-
316
- // Verify values
317
- expect(allMetrics.assetsCreated).toBe(1);
318
- expect(allMetrics.assetsMigrated['peer→webvh']).toBe(1);
319
- expect(allMetrics.assetsMigrated['webvh→btco']).toBe(1);
320
- expect(allMetrics.assetsTransferred).toBe(1);
321
- expect(allMetrics.operationTimes['op1']).toBeDefined();
322
- expect(allMetrics.operationTimes['op2']).toBeDefined();
323
- expect(allMetrics.errors['ERR_001']).toBe(1);
324
- });
325
- });
326
-
327
- describe('memory efficiency', () => {
328
- test('should not leak memory with many operations', () => {
329
- // Record a large number of operations
330
- for (let i = 0; i < 10000; i++) {
331
- metrics.recordOperation(`op${i % 10}`, Math.random() * 100, Math.random() > 0.1);
332
- }
333
-
334
- // Should only have 10 unique operations
335
- const allMetrics = metrics.getMetrics();
336
- expect(Object.keys(allMetrics.operationTimes).length).toBe(10);
337
-
338
- // Each operation should have correct count
339
- expect(allMetrics.operationTimes['op0'].count).toBe(1000);
340
- });
341
-
342
- test('should handle many error codes efficiently', () => {
343
- // Record many different error codes
344
- for (let i = 0; i < 1000; i++) {
345
- metrics.recordError(`ERR_${i % 50}`);
346
- }
347
-
348
- const allMetrics = metrics.getMetrics();
349
-
350
- // Should have 50 unique error codes
351
- expect(Object.keys(allMetrics.errors).length).toBe(50);
352
-
353
- // Each error code should appear 20 times
354
- expect(allMetrics.errors['ERR_0']).toBe(20);
355
- });
356
- });
357
- });
358
-
@@ -1,250 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { describe, test, expect } from 'bun:test';
3
- import { validateBitcoinAddress, isValidBitcoinAddress } from '../../../src/utils/bitcoin-address';
4
- import * as bitcoin from 'bitcoinjs-lib';
5
-
6
- describe('bitcoin-address validation', () => {
7
- describe('validateBitcoinAddress', () => {
8
- describe('mainnet addresses', () => {
9
- test('accepts valid mainnet bech32 (bc1) address', () => {
10
- // Valid P2WPKH mainnet address
11
- expect(() => validateBitcoinAddress('bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq', 'mainnet')).not.toThrow();
12
- });
13
-
14
- test('legacy address formats are not supported in bitcoinjs-lib v6', () => {
15
- // bitcoinjs-lib v6 primarily supports bech32 addresses
16
- // Legacy P2PKH (1...) and P2SH (3...) formats require additional libraries
17
- // For the purposes of this SDK focused on modern Bitcoin, we'll primarily validate bech32
18
- expect(true).toBe(true);
19
- });
20
-
21
- test('accepts valid mainnet P2WSH (bc1...) address', () => {
22
- // Valid P2WSH address (longer than P2WPKH)
23
- expect(() => validateBitcoinAddress('bc1qeklep85ntjz4605drds6aww9u0qr46qzrv5xswd35uhjuj8ahfcqgf6hak', 'mainnet')).not.toThrow();
24
- });
25
-
26
- test('rejects mainnet address with invalid checksum', () => {
27
- // Modified last character to break checksum
28
- expect(() => validateBitcoinAddress('bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdd', 'mainnet'))
29
- .toThrow(/Invalid Bitcoin address/i);
30
- });
31
-
32
- test('rejects regtest address on mainnet network', () => {
33
- // Regtest/testnet address should fail on mainnet
34
- expect(() => validateBitcoinAddress('tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx', 'mainnet'))
35
- .toThrow(/Invalid/i);
36
- });
37
- });
38
-
39
- describe('regtest addresses', () => {
40
- test('accepts valid regtest/testnet bech32 addresses', () => {
41
- // Regtest accepts both bcrt1 and tb1 addresses (testnet format is commonly used)
42
- // Using testnet bech32 address which is valid for regtest
43
- expect(() => validateBitcoinAddress('tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx', 'regtest')).not.toThrow();
44
- expect(() => validateBitcoinAddress('tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sl5k7', 'regtest')).not.toThrow();
45
- });
46
-
47
- test('rejects mainnet address on regtest network', () => {
48
- expect(() => validateBitcoinAddress('bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq', 'regtest'))
49
- .toThrow(/Invalid/i);
50
- });
51
- });
52
-
53
- describe('signet addresses', () => {
54
- test('accepts valid signet bech32 (tb1) address', () => {
55
- // Signet uses tb1 prefix like testnet
56
- expect(() => validateBitcoinAddress('tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx', 'signet')).not.toThrow();
57
- });
58
-
59
- test('accepts valid signet legacy addresses', () => {
60
- // Signet uses same formats as testnet
61
- expect(() => validateBitcoinAddress('mipcBbFg9gMiCh81Kj8tqqdgoZub1ZJRfn', 'signet')).not.toThrow();
62
- });
63
-
64
- test('rejects mainnet address on signet network', () => {
65
- expect(() => validateBitcoinAddress('bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq', 'signet'))
66
- .toThrow(/Invalid/i);
67
- });
68
- });
69
-
70
- describe('invalid addresses', () => {
71
- test('rejects empty string', () => {
72
- expect(() => validateBitcoinAddress('', 'mainnet'))
73
- .toThrow(/empty/i);
74
- });
75
-
76
- test('rejects whitespace-only string', () => {
77
- expect(() => validateBitcoinAddress(' ', 'mainnet'))
78
- .toThrow(/empty/i);
79
- });
80
-
81
- test('rejects null or undefined', () => {
82
- expect(() => validateBitcoinAddress(null as any, 'mainnet'))
83
- .toThrow(/non-empty string/i);
84
- expect(() => validateBitcoinAddress(undefined as any, 'mainnet'))
85
- .toThrow(/non-empty string/i);
86
- });
87
-
88
- test('rejects non-string values', () => {
89
- expect(() => validateBitcoinAddress(123 as any, 'mainnet'))
90
- .toThrow(/non-empty string/i);
91
- expect(() => validateBitcoinAddress({} as any, 'mainnet'))
92
- .toThrow(/non-empty string/i);
93
- });
94
-
95
- test('rejects address that is too short', () => {
96
- expect(() => validateBitcoinAddress('bc1qar0sr', 'mainnet'))
97
- .toThrow(/length/i);
98
- });
99
-
100
- test('rejects address that is too long', () => {
101
- const tooLong = 'bc1' + 'q'.repeat(100);
102
- expect(() => validateBitcoinAddress(tooLong, 'mainnet'))
103
- .toThrow(/length/i);
104
- });
105
-
106
- test('rejects completely malformed address', () => {
107
- expect(() => validateBitcoinAddress('not-a-bitcoin-address-at-all-really-long', 'mainnet'))
108
- .toThrow(/Invalid/i);
109
- });
110
-
111
- test('rejects address with invalid characters', () => {
112
- expect(() => validateBitcoinAddress('bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5md@', 'mainnet'))
113
- .toThrow(/Invalid/i);
114
- });
115
-
116
- test('rejects mock addresses', () => {
117
- expect(() => validateBitcoinAddress('mock-address', 'mainnet'))
118
- .toThrow(/Mock or test addresses/i);
119
- expect(() => validateBitcoinAddress('test-address', 'testnet'))
120
- .toThrow(/Mock or test addresses/i);
121
- expect(() => validateBitcoinAddress('MOCK-ADDRESS', 'mainnet'))
122
- .toThrow(/Mock or test addresses/i);
123
- expect(() => validateBitcoinAddress('TEST-ADDRESS', 'regtest'))
124
- .toThrow(/Mock or test addresses/i);
125
- });
126
-
127
- test('rejects address with wrong network prefix', () => {
128
- // Using testnet prefix on mainnet
129
- expect(() => validateBitcoinAddress('tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx', 'mainnet'))
130
- .toThrow(/Invalid/i);
131
-
132
- // Using mainnet prefix on regtest
133
- expect(() => validateBitcoinAddress('bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq', 'regtest'))
134
- .toThrow(/Invalid/i);
135
- });
136
- });
137
-
138
- describe('edge cases', () => {
139
- test('trims whitespace before validation', () => {
140
- expect(() => validateBitcoinAddress(' bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq ', 'mainnet')).not.toThrow();
141
- });
142
-
143
- test('returns true for valid addresses', () => {
144
- const result = validateBitcoinAddress('bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq', 'mainnet');
145
- expect(result).toBe(true);
146
- });
147
-
148
- test('provides descriptive error messages', () => {
149
- // Invalid bech32 address
150
- expect(() => validateBitcoinAddress('bc1qinvalidaddresswithinvalidchecksum', 'mainnet'))
151
- .toThrow(/Invalid/);
152
-
153
- // Mock address
154
- expect(() => validateBitcoinAddress('mock-address', 'mainnet'))
155
- .toThrow(/Mock or test addresses are not valid/);
156
-
157
- // Empty
158
- expect(() => validateBitcoinAddress('', 'mainnet'))
159
- .toThrow(/non-empty string/);
160
- });
161
- });
162
-
163
- describe('real-world address examples', () => {
164
- test('accepts various valid mainnet bech32 addresses', () => {
165
- const validAddresses = [
166
- 'bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh', // P2WPKH
167
- 'bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq', // P2WPKH
168
- 'bc1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3qccfmv3', // P2WSH
169
- 'bc1qeklep85ntjz4605drds6aww9u0qr46qzrv5xswd35uhjuj8ahfcqgf6hak', // P2WSH
170
- ];
171
-
172
- validAddresses.forEach(address => {
173
- expect(() => validateBitcoinAddress(address, 'mainnet')).not.toThrow();
174
- });
175
- });
176
-
177
- test('accepts various valid regtest bech32 addresses', () => {
178
- const validAddresses = [
179
- 'tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sl5k7',
180
- 'tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx',
181
- ];
182
-
183
- validAddresses.forEach(address => {
184
- expect(() => validateBitcoinAddress(address, 'regtest')).not.toThrow();
185
- });
186
- });
187
- });
188
- });
189
-
190
- describe('isValidBitcoinAddress', () => {
191
- test('returns true for valid addresses', () => {
192
- expect(isValidBitcoinAddress('bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq', 'mainnet')).toBe(true);
193
- expect(isValidBitcoinAddress('tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx', 'regtest')).toBe(true);
194
- expect(isValidBitcoinAddress('tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx', 'signet')).toBe(true);
195
- });
196
-
197
- test('returns false for invalid addresses', () => {
198
- expect(isValidBitcoinAddress('mock-address', 'mainnet')).toBe(false);
199
- expect(isValidBitcoinAddress('', 'mainnet')).toBe(false);
200
- expect(isValidBitcoinAddress('invalid', 'mainnet')).toBe(false);
201
- expect(isValidBitcoinAddress('bc1qinvalidaddresswith', 'mainnet')).toBe(false);
202
- });
203
-
204
- test('returns false for wrong network', () => {
205
- expect(isValidBitcoinAddress('bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq', 'testnet')).toBe(false);
206
- expect(isValidBitcoinAddress('tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx', 'mainnet')).toBe(false);
207
- });
208
-
209
- test('does not throw for any input', () => {
210
- expect(() => isValidBitcoinAddress('', 'mainnet')).not.toThrow();
211
- expect(() => isValidBitcoinAddress(null as any, 'mainnet')).not.toThrow();
212
- expect(() => isValidBitcoinAddress(undefined as any, 'mainnet')).not.toThrow();
213
- });
214
- });
215
-
216
- describe('integration with bitcoinjs-lib', () => {
217
- test('validates addresses that bitcoinjs-lib can decode', () => {
218
- const validMainnetAddresses = [
219
- 'bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq',
220
- 'bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh',
221
- ];
222
-
223
- validMainnetAddresses.forEach(address => {
224
- // Should not throw with our validator
225
- expect(() => validateBitcoinAddress(address, 'mainnet')).not.toThrow();
226
-
227
- // Should also not throw with bitcoinjs-lib directly
228
- expect(() => bitcoin.address.toOutputScript(address, bitcoin.networks.bitcoin)).not.toThrow();
229
- });
230
- });
231
-
232
- test('rejects addresses that bitcoinjs-lib rejects', () => {
233
- const invalidAddresses = [
234
- 'bc1qinvalid',
235
- '1InvalidBase58',
236
- 'not-an-address',
237
- ];
238
-
239
- invalidAddresses.forEach(address => {
240
- // Should throw with our validator (if long enough)
241
- if (address.length >= 26) {
242
- expect(() => validateBitcoinAddress(address, 'mainnet')).toThrow();
243
- }
244
-
245
- // Should also throw with bitcoinjs-lib directly
246
- expect(() => bitcoin.address.toOutputScript(address, bitcoin.networks.bitcoin)).toThrow();
247
- });
248
- });
249
- });
250
- });
@@ -1,35 +0,0 @@
1
- import { describe, test, expect } from 'bun:test';
2
- import { encode, decode } from '../../../src/utils/cbor';
3
-
4
- describe('utils/cbor', () => {
5
- test('encode returns Uint8Array', () => {
6
- const input = { a: 1, b: 'two' };
7
- const out = encode(input);
8
- expect(out).toBeInstanceOf(Uint8Array);
9
- expect(out.length).toBeGreaterThan(0);
10
- });
11
-
12
- test('decode roundtrips object', () => {
13
- const input = { a: 1, b: 'two', nested: { ok: true } };
14
- const encoded = encode(input);
15
- const decoded = decode<typeof input>(encoded);
16
- expect(decoded).toEqual(input);
17
- });
18
-
19
- test('decode accepts Buffer', () => {
20
- const input = [1, 2, 3];
21
- const encoded = encode(input);
22
- const buf = Buffer.from(encoded);
23
- const decoded = decode<number[]>(buf);
24
- expect(decoded).toEqual(input);
25
- });
26
-
27
- test('decode accepts ArrayBuffer', () => {
28
- const input = { hello: 'world' };
29
- const encoded = encode(input);
30
- const ab = encoded.buffer.slice(encoded.byteOffset, encoded.byteOffset + encoded.byteLength) as ArrayBuffer;
31
- const decoded = decode<typeof input>(ab as ArrayBuffer);
32
- expect(decoded).toEqual(input);
33
- });
34
- });
35
-