@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,42 +0,0 @@
1
- /** Canonical test aggregator created by combine-tests script. */
2
-
3
- /** Inlined from CredentialManager.integration.part.ts */
4
- import { describe, test, expect, beforeEach, afterEach } from 'bun:test';
5
- import { OriginalsSDK } from '../../src';
6
- import * as ed25519 from '@noble/ed25519';
7
- import { multikey } from '../../src/crypto/Multikey';
8
- import { registerVerificationMethod, verificationMethodRegistry } from '../../src/vc/documentLoader';
9
-
10
- describe('Integration: CredentialManager issue/verify roundtrip', () => {
11
- const sdk = OriginalsSDK.create({ defaultKeyType: 'Ed25519' });
12
-
13
- beforeEach(() => {
14
- verificationMethodRegistry.clear();
15
- });
16
-
17
- afterEach(() => {
18
- verificationMethodRegistry.clear();
19
- });
20
-
21
- test('issue and verify using Issuer/Verifier wiring', async () => {
22
- const did = 'did:peer:issuer1';
23
- const sk = ed25519.utils.randomPrivateKey();
24
- const pk = await (ed25519 as any).getPublicKeyAsync(sk);
25
- const secretKeyMultibase = multikey.encodePrivateKey(sk, 'Ed25519');
26
- const publicKeyMultibase = multikey.encodePublicKey(pk, 'Ed25519');
27
- const vm = `${did}#keys-1`;
28
- registerVerificationMethod({ id: vm, controller: did, type: 'Multikey', publicKeyMultibase });
29
-
30
- const base = {
31
- type: ['VerifiableCredential', 'Test'],
32
- issuer: did,
33
- issuanceDate: new Date().toISOString(),
34
- credentialSubject: { id: 'did:peer:subject1' }
35
- } as any;
36
-
37
- const signed = await sdk.credentials.signCredential(base, secretKeyMultibase, vm);
38
- expect(signed.proof).toBeDefined();
39
- const verified = await sdk.credentials.verifyCredential(signed);
40
- expect(verified).toBe(true);
41
- });
42
- });
@@ -1,41 +0,0 @@
1
- /** Canonical test aggregator created by combine-tests script. */
2
-
3
- /** Inlined from DIDManager.btco.integration.part.ts */
4
- import { describe, test, expect, afterEach, spyOn } from 'bun:test';
5
- import { OriginalsSDK } from '../../src';
6
-
7
- describe('Integration: DIDManager btco resolve via OrdinalsClient adapter', () => {
8
- const sdk = OriginalsSDK.create({ network: 'mainnet', bitcoinRpcUrl: 'http://ord' });
9
-
10
- test('resolves did:btco using adapter with mocked fetch', async () => {
11
- const sat = '123456';
12
- const did = `did:btco:${sat}`;
13
-
14
- const fetchMock = spyOn(global as any, 'fetch').mockImplementation(async (url: any) => {
15
- if (url === 'http://ord/sat/' + sat) {
16
- return new Response(JSON.stringify({ inscription_ids: ['i1', 'i2'] }), { status: 200 });
17
- }
18
- if (url === 'http://ord/inscription/i1') {
19
- return new Response(JSON.stringify({ inscription_id: 'i1', content_type: 'text/plain', content_url: 'http://c/i1', sat }), { status: 200 });
20
- }
21
- if (url === 'http://ord/inscription/i2') {
22
- return new Response(JSON.stringify({ inscription_id: 'i2', content_type: 'text/plain', content_url: 'http://c/i2', sat }), { status: 200 });
23
- }
24
- if (url === 'http://c/i1') {
25
- return new Response(`BTCO DID: ${did}`, { status: 200 });
26
- }
27
- if (url === 'http://c/i2') {
28
- return new Response('not a did doc', { status: 200 });
29
- }
30
- if (url === 'http://ord/r/metadata/i1') {
31
- // Return DID Document JSON encoded as hex CBOR; for test simplicity return plain JSON string, adapter tolerates null metadata
32
- return new Response('7b7d', { status: 200 });
33
- }
34
- return new Response('', { status: 404 });
35
- });
36
-
37
- const doc = await sdk.did.resolveDID(did);
38
- expect(doc === null || typeof doc === 'object').toBe(true);
39
- fetchMock.mockRestore();
40
- });
41
- });
@@ -1,351 +0,0 @@
1
- import { describe, test, expect, beforeAll } from 'bun:test';
2
- import { OriginalsSDK } from '../../src';
3
- import { AssetResource } from '../../src/types';
4
- import { MockKeyStore } from '../mocks/MockKeyStore';
5
- import { KeyManager } from '../../src/did/KeyManager';
6
- import * as fs from 'fs';
7
- import * as path from 'path';
8
- import { tmpdir } from 'os';
9
-
10
- describe('DID Peer to WebVH Publication Flow', () => {
11
- const keyStore = new MockKeyStore();
12
- const sdk = OriginalsSDK.create({
13
- network: 'regtest',
14
- keyStore,
15
- defaultKeyType: 'Ed25519', // Use Ed25519 for did:webvh compatibility
16
- enableLogging: true
17
- });
18
- const domain = 'localhost:5000';
19
- const tempDir = path.join(tmpdir(), 'originals-test-webvh');
20
-
21
- beforeAll(async () => {
22
- // Ensure temp directory exists
23
- await fs.promises.mkdir(tempDir, { recursive: true });
24
-
25
- // Set up publisher DID keys for tests
26
- const keyManager = new KeyManager();
27
- const publisherKey = await keyManager.generateKeyPair('Ed25519');
28
- await keyStore.setPrivateKey('did:webvh:localhost%3A5000:user#key-0', publisherKey.privateKey);
29
- });
30
-
31
- test('complete flow: createDIDPeer -> publishToWeb -> resolve resource URL', async () => {
32
- // Step 1: Create a DID peer with resources
33
- const resources: AssetResource[] = [
34
- {
35
- id: 'resource-1',
36
- type: 'data',
37
- contentType: 'text/plain',
38
- hash: 'abc123def456',
39
- content: 'Hello, World! This is test content.'
40
- },
41
- {
42
- id: 'resource-2',
43
- type: 'metadata',
44
- contentType: 'application/json',
45
- hash: 'aea789ab',
46
- content: JSON.stringify({ title: 'Test Asset', version: '1.0' })
47
- }
48
- ];
49
-
50
- console.log('\n🔧 Step 1: Creating DID peer...');
51
- const { didDocument: peerDoc, keyPair } = await sdk.did.createDIDPeer(resources, true);
52
-
53
- // Verify DID peer was created
54
- expect(peerDoc).toBeDefined();
55
- expect(peerDoc.id).toMatch(/^did:peer:/);
56
- expect(keyPair).toBeDefined();
57
- expect(keyPair.publicKey).toBeTruthy();
58
- expect(keyPair.privateKey).toBeTruthy();
59
-
60
- console.log(`✅ DID Peer created: ${peerDoc.id}`);
61
- console.log(` Public Key: ${keyPair.publicKey.substring(0, 20)}...`);
62
-
63
- // Step 2: Create an asset using the DID peer
64
- console.log('\n🔧 Step 2: Creating asset with DID peer...');
65
- const asset = await sdk.lifecycle.createAsset(resources);
66
-
67
- expect(asset).toBeDefined();
68
- expect(asset.id).toMatch(/^did:peer:/);
69
- expect(asset.currentLayer).toBe('did:peer');
70
- expect(asset.resources).toHaveLength(2);
71
-
72
- console.log(`✅ Asset created: ${asset.id}`);
73
- console.log(` Current Layer: ${asset.currentLayer}`);
74
- console.log(` Resources: ${asset.resources.length}`);
75
-
76
- // Step 3: Publish to web (migrate to did:webvh)
77
- console.log('\n🔧 Step 3: Publishing to web (did:peer -> did:webvh)...');
78
- const publishedAsset = await sdk.lifecycle.publishToWeb(asset, domain);
79
-
80
- expect(publishedAsset).toBeDefined();
81
- expect(publishedAsset.currentLayer).toBe('did:webvh');
82
-
83
- // Get the webvh DID from bindings
84
- const bindings = (publishedAsset as any).bindings;
85
- expect(bindings).toBeDefined();
86
- expect(bindings['did:webvh']).toBeDefined();
87
- expect(bindings['did:webvh']).toMatch(new RegExp(`^did:webvh:${domain.replace(':', '%3A')}:`));
88
-
89
- const webvhDid = bindings['did:webvh'];
90
- console.log(`✅ Asset published to web!`);
91
- console.log(` Original DID (peer): ${asset.id}`);
92
- console.log(` New DID (webvh): ${webvhDid}`);
93
- console.log(` Current Layer: ${publishedAsset.currentLayer}`);
94
-
95
- // Step 4: Verify resources have URLs
96
- console.log('\n🔧 Step 4: Verifying resource URLs...');
97
- expect(publishedAsset.resources).toHaveLength(2);
98
-
99
- for (const resource of publishedAsset.resources) {
100
- expect(resource.url).toBeDefined();
101
- expect(typeof resource.url).toBe('string');
102
- expect((resource.url as string).includes('did:webvh:')).toBe(true);
103
- expect((resource.url as string).includes('/resources/')).toBe(true);
104
-
105
- console.log(`✅ Resource ${resource.id}:`);
106
- console.log(` URL: ${resource.url}`);
107
- console.log(` Content-Type: ${resource.contentType}`);
108
- console.log(` Hash: ${resource.hash}`);
109
- }
110
-
111
- // Step 5: Verify provenance includes migration event
112
- console.log('\n🔧 Step 5: Verifying provenance...');
113
- const provenance = (publishedAsset as any).provenance;
114
- expect(provenance).toBeDefined();
115
- expect(provenance.migrations).toBeDefined();
116
- expect(Array.isArray(provenance.migrations)).toBe(true);
117
-
118
- const webvhMigration = provenance.migrations.find((m: any) => m.to === 'did:webvh');
119
- expect(webvhMigration).toBeDefined();
120
- expect(webvhMigration.from).toBe('did:peer');
121
- expect(webvhMigration.to).toBe('did:webvh');
122
- expect(webvhMigration.timestamp).toBeDefined();
123
-
124
- console.log(`✅ Provenance verified:`);
125
- console.log(` Migration from: ${webvhMigration.from}`);
126
- console.log(` Migration to: ${webvhMigration.to}`);
127
- console.log(` Timestamp: ${webvhMigration.timestamp}`);
128
-
129
- // Step 6: Test DID resolution (if the webvh DID was created with proper log)
130
- console.log('\n🔧 Step 6: Testing DID resolution...');
131
- try {
132
- const resolved = await sdk.did.resolveDID(webvhDid);
133
- expect(resolved).toBeDefined();
134
- expect(resolved?.id).toBe(webvhDid);
135
-
136
- console.log(`✅ DID resolved successfully:`);
137
- console.log(` Resolved ID: ${resolved?.id}`);
138
- console.log(` Context: ${JSON.stringify(resolved?.['@context'])}`);
139
- if (resolved?.verificationMethod) {
140
- console.log(` Verification Methods: ${resolved.verificationMethod.length}`);
141
- }
142
- } catch (error) {
143
- console.log(`⚠️ DID resolution skipped (expected for test environment)`);
144
- console.log(` Reason: ${error instanceof Error ? error.message : String(error)}`);
145
- }
146
-
147
- // Step 7: Verify credentials were issued
148
- console.log('\n🔧 Step 7: Verifying credentials...');
149
- const credentials = (publishedAsset as any).credentials;
150
- expect(Array.isArray(credentials)).toBe(true);
151
- expect(credentials.length).toBeGreaterThan(0);
152
-
153
- const hasPublicationCredential = credentials.some((c: any) =>
154
- Array.isArray(c.type) &&
155
- (c.type.includes('ResourceMigrated') ||
156
- c.type.includes('ResourcePublished') ||
157
- c.type.includes('ResourceCreated'))
158
- );
159
- expect(hasPublicationCredential).toBe(true);
160
-
161
- console.log(`✅ Credentials verified:`);
162
- console.log(` Total credentials: ${credentials.length}`);
163
- console.log(` Has publication credential: ${hasPublicationCredential}`);
164
- credentials.forEach((cred: any, idx: number) => {
165
- console.log(` Credential ${idx + 1}: ${cred.type?.join(', ') || 'Unknown'}`);
166
- });
167
-
168
- // Final summary
169
- console.log('\n' + '='.repeat(70));
170
- console.log('✨ FLOW VERIFICATION COMPLETE ✨');
171
- console.log('='.repeat(70));
172
- console.log(`📋 Summary:`);
173
- console.log(` ✓ DID Peer created successfully`);
174
- console.log(` ✓ Asset created with resources`);
175
- console.log(` ✓ Published to web (did:peer -> did:webvh)`);
176
- console.log(` ✓ Resource URLs generated and accessible`);
177
- console.log(` ✓ Provenance tracking verified`);
178
- console.log(` ✓ Credentials issued`);
179
- console.log(` ✓ DID bindings established`);
180
- console.log('='.repeat(70) + '\n');
181
- });
182
-
183
- test('verify resource URL format and structure', async () => {
184
- const resources: AssetResource[] = [
185
- {
186
- id: 'res-format-test',
187
- type: 'data',
188
- contentType: 'application/octet-stream',
189
- hash: 'e5a1234560',
190
- content: 'test data for URL format verification'
191
- }
192
- ];
193
-
194
- const asset = await sdk.lifecycle.createAsset(resources);
195
- const published = await sdk.lifecycle.publishToWeb(asset, domain);
196
-
197
- // Verify resource URL structure
198
- const resource = published.resources[0];
199
- const url = resource.url as string;
200
-
201
- expect(url).toBeDefined();
202
- expect(url).toContain('did:webvh:');
203
- expect(url).toContain('/resources/');
204
-
205
- // URL should be in format: did:webvh:domain:path/resources/hash
206
- expect(url).toMatch(/^did:webvh:[^\/]+\/resources\//);
207
-
208
- // URL should end with a multibase-encoded hash
209
- expect(url.split('/').pop()).toMatch(/^[A-Za-z0-9_-]+$/);
210
-
211
- console.log(`\n✅ Resource URL format verified:`);
212
- console.log(` Full URL: ${url}`);
213
- console.log(` Format: DID-based URL`);
214
- console.log(` Contains resources path: true`);
215
- console.log(` Hash encoded: ${url.split('/').pop()}`);
216
- });
217
-
218
- test('verify bindings are preserved through migration', async () => {
219
- const resources: AssetResource[] = [
220
- {
221
- id: 'binding-test',
222
- type: 'data',
223
- contentType: 'text/plain',
224
- hash: 'b1d1234560',
225
- content: 'binding test content'
226
- }
227
- ];
228
-
229
- const asset = await sdk.lifecycle.createAsset(resources);
230
- const originalId = asset.id;
231
-
232
- const published = await sdk.lifecycle.publishToWeb(asset, domain);
233
- const bindings = (published as any).bindings;
234
-
235
- // Should have both peer and webvh bindings
236
- expect(bindings['did:peer']).toBeDefined();
237
- expect(bindings['did:webvh']).toBeDefined();
238
-
239
- // Peer binding should match original asset ID
240
- expect(bindings['did:peer']).toBe(originalId);
241
-
242
- // WebVH binding should be a valid did:webvh
243
- expect(bindings['did:webvh']).toMatch(/^did:webvh:/);
244
-
245
- console.log(`\n✅ Bindings verified:`);
246
- console.log(` did:peer: ${bindings['did:peer']}`);
247
- console.log(` did:webvh: ${bindings['did:webvh']}`);
248
- console.log(` Previous DID: ${(published as any).previousDid}`);
249
- });
250
-
251
- test('verify multiple resources all get URLs', async () => {
252
- const resources: AssetResource[] = [
253
- {
254
- id: 'multi-1',
255
- type: 'data',
256
- contentType: 'text/plain',
257
- hash: 'a51001',
258
- content: 'content 1'
259
- },
260
- {
261
- id: 'multi-2',
262
- type: 'data',
263
- contentType: 'application/json',
264
- hash: 'a51002',
265
- content: '{"key": "value"}'
266
- },
267
- {
268
- id: 'multi-3',
269
- type: 'metadata',
270
- contentType: 'text/html',
271
- hash: 'a51003',
272
- content: '<html><body>test</body></html>'
273
- },
274
- {
275
- id: 'multi-4',
276
- type: 'data',
277
- contentType: 'image/svg+xml',
278
- hash: 'a51004',
279
- content: '<svg></svg>'
280
- }
281
- ];
282
-
283
- const asset = await sdk.lifecycle.createAsset(resources);
284
- const published = await sdk.lifecycle.publishToWeb(asset, domain);
285
-
286
- // All resources should have URLs
287
- expect(published.resources).toHaveLength(4);
288
-
289
- for (let i = 0; i < published.resources.length; i++) {
290
- const resource = published.resources[i];
291
- expect(resource.url).toBeDefined();
292
- expect(typeof resource.url).toBe('string');
293
- expect((resource.url as string).length).toBeGreaterThan(0);
294
- expect((resource.url as string).includes('did:webvh:')).toBe(true);
295
- expect((resource.url as string).includes('/resources/')).toBe(true);
296
-
297
- console.log(`✅ Resource ${i + 1} (${resource.id}):`);
298
- console.log(` URL: ${resource.url}`);
299
- }
300
- });
301
-
302
- test('verify published asset maintains all original data', async () => {
303
- const resources: AssetResource[] = [
304
- {
305
- id: 'preserve-test',
306
- type: 'data',
307
- contentType: 'text/markdown',
308
- hash: 'e5e1ea00',
309
- content: '# Test Document\nThis should be preserved.'
310
- }
311
- ];
312
-
313
- const asset = await sdk.lifecycle.createAsset(resources);
314
-
315
- // Capture original data
316
- const originalId = asset.id;
317
- const originalResources = asset.resources.map(r => ({ ...r }));
318
- const originalLayer = asset.currentLayer;
319
-
320
- const published = await sdk.lifecycle.publishToWeb(asset, domain);
321
-
322
- // Verify resources are preserved (with added URL)
323
- expect(published.resources).toHaveLength(originalResources.length);
324
-
325
- for (let i = 0; i < published.resources.length; i++) {
326
- const original = originalResources[i];
327
- const current = published.resources[i];
328
-
329
- expect(current.id).toBe(original.id);
330
- expect(current.type).toBe(original.type);
331
- expect(current.contentType).toBe(original.contentType);
332
- expect(current.hash).toBe(original.hash);
333
- expect(current.content).toBe(original.content);
334
- expect(current.url).toBeDefined(); // New field added
335
- }
336
-
337
- // Verify layer changed
338
- expect(published.currentLayer).toBe('did:webvh');
339
- expect(originalLayer).toBe('did:peer');
340
-
341
- // Verify bindings preserve original ID
342
- const bindings = (published as any).bindings;
343
- expect(bindings['did:peer']).toBe(originalId);
344
-
345
- console.log(`\n✅ Data preservation verified:`);
346
- console.log(` All resource fields preserved: true`);
347
- console.log(` URLs added: true`);
348
- console.log(` Layer updated: ${originalLayer} -> ${published.currentLayer}`);
349
- console.log(` Original ID preserved in bindings: true`);
350
- });
351
- });