@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.
- package/package.json +4 -1
- package/.eslintrc.json +0 -33
- package/src/adapters/FeeOracleMock.ts +0 -9
- package/src/adapters/index.ts +0 -5
- package/src/adapters/providers/OrdHttpProvider.ts +0 -126
- package/src/adapters/providers/OrdMockProvider.ts +0 -101
- package/src/adapters/types.ts +0 -66
- package/src/bitcoin/BitcoinManager.ts +0 -330
- package/src/bitcoin/BroadcastClient.ts +0 -54
- package/src/bitcoin/OrdinalsClient.ts +0 -119
- package/src/bitcoin/PSBTBuilder.ts +0 -106
- package/src/bitcoin/fee-calculation.ts +0 -38
- package/src/bitcoin/providers/OrdNodeProvider.ts +0 -92
- package/src/bitcoin/providers/OrdinalsProvider.ts +0 -56
- package/src/bitcoin/providers/types.ts +0 -59
- package/src/bitcoin/transactions/commit.ts +0 -465
- package/src/bitcoin/transactions/index.ts +0 -13
- package/src/bitcoin/transfer.ts +0 -43
- package/src/bitcoin/utxo-selection.ts +0 -322
- package/src/bitcoin/utxo.ts +0 -113
- package/src/contexts/credentials-v1.json +0 -237
- package/src/contexts/credentials-v2-examples.json +0 -5
- package/src/contexts/credentials-v2.json +0 -340
- package/src/contexts/credentials.json +0 -237
- package/src/contexts/data-integrity-v2.json +0 -81
- package/src/contexts/dids.json +0 -58
- package/src/contexts/ed255192020.json +0 -93
- package/src/contexts/ordinals-plus.json +0 -23
- package/src/contexts/originals.json +0 -22
- package/src/core/OriginalsSDK.ts +0 -416
- package/src/crypto/Multikey.ts +0 -194
- package/src/crypto/Signer.ts +0 -254
- package/src/crypto/noble-init.ts +0 -121
- package/src/did/BtcoDidResolver.ts +0 -227
- package/src/did/DIDManager.ts +0 -694
- package/src/did/Ed25519Verifier.ts +0 -68
- package/src/did/KeyManager.ts +0 -236
- package/src/did/WebVHManager.ts +0 -498
- package/src/did/createBtcoDidDocument.ts +0 -59
- package/src/did/providers/OrdinalsClientProviderAdapter.ts +0 -68
- package/src/events/EventEmitter.ts +0 -222
- package/src/events/index.ts +0 -19
- package/src/events/types.ts +0 -331
- package/src/examples/basic-usage.ts +0 -78
- package/src/examples/create-module-original.ts +0 -435
- package/src/examples/full-lifecycle-flow.ts +0 -514
- package/src/examples/run.ts +0 -60
- package/src/index.ts +0 -150
- package/src/kinds/KindRegistry.ts +0 -290
- package/src/kinds/index.ts +0 -74
- package/src/kinds/types.ts +0 -470
- package/src/kinds/validators/AgentValidator.ts +0 -257
- package/src/kinds/validators/AppValidator.ts +0 -211
- package/src/kinds/validators/DatasetValidator.ts +0 -242
- package/src/kinds/validators/DocumentValidator.ts +0 -311
- package/src/kinds/validators/MediaValidator.ts +0 -269
- package/src/kinds/validators/ModuleValidator.ts +0 -225
- package/src/kinds/validators/base.ts +0 -276
- package/src/kinds/validators/index.ts +0 -12
- package/src/lifecycle/BatchOperations.ts +0 -373
- package/src/lifecycle/LifecycleManager.ts +0 -2126
- package/src/lifecycle/OriginalsAsset.ts +0 -524
- package/src/lifecycle/ProvenanceQuery.ts +0 -280
- package/src/lifecycle/ResourceVersioning.ts +0 -163
- package/src/migration/MigrationManager.ts +0 -527
- package/src/migration/audit/AuditLogger.ts +0 -176
- package/src/migration/checkpoint/CheckpointManager.ts +0 -112
- package/src/migration/checkpoint/CheckpointStorage.ts +0 -101
- package/src/migration/index.ts +0 -33
- package/src/migration/operations/BaseMigration.ts +0 -126
- package/src/migration/operations/PeerToBtcoMigration.ts +0 -105
- package/src/migration/operations/PeerToWebvhMigration.ts +0 -62
- package/src/migration/operations/WebvhToBtcoMigration.ts +0 -105
- package/src/migration/rollback/RollbackManager.ts +0 -170
- package/src/migration/state/StateMachine.ts +0 -92
- package/src/migration/state/StateTracker.ts +0 -156
- package/src/migration/types.ts +0 -344
- package/src/migration/validation/BitcoinValidator.ts +0 -107
- package/src/migration/validation/CredentialValidator.ts +0 -62
- package/src/migration/validation/DIDCompatibilityValidator.ts +0 -151
- package/src/migration/validation/LifecycleValidator.ts +0 -64
- package/src/migration/validation/StorageValidator.ts +0 -79
- package/src/migration/validation/ValidationPipeline.ts +0 -213
- package/src/resources/ResourceManager.ts +0 -655
- package/src/resources/index.ts +0 -21
- package/src/resources/types.ts +0 -202
- package/src/storage/LocalStorageAdapter.ts +0 -61
- package/src/storage/MemoryStorageAdapter.ts +0 -29
- package/src/storage/StorageAdapter.ts +0 -25
- package/src/storage/index.ts +0 -3
- package/src/types/bitcoin.ts +0 -98
- package/src/types/common.ts +0 -92
- package/src/types/credentials.ts +0 -88
- package/src/types/did.ts +0 -31
- package/src/types/external-shims.d.ts +0 -53
- package/src/types/index.ts +0 -7
- package/src/types/network.ts +0 -175
- package/src/utils/EventLogger.ts +0 -298
- package/src/utils/Logger.ts +0 -322
- package/src/utils/MetricsCollector.ts +0 -358
- package/src/utils/bitcoin-address.ts +0 -130
- package/src/utils/cbor.ts +0 -12
- package/src/utils/encoding.ts +0 -127
- package/src/utils/hash.ts +0 -6
- package/src/utils/retry.ts +0 -46
- package/src/utils/satoshi-validation.ts +0 -196
- package/src/utils/serialization.ts +0 -96
- package/src/utils/telemetry.ts +0 -40
- package/src/utils/validation.ts +0 -119
- package/src/vc/CredentialManager.ts +0 -918
- package/src/vc/Issuer.ts +0 -100
- package/src/vc/Verifier.ts +0 -47
- package/src/vc/cryptosuites/bbs.ts +0 -253
- package/src/vc/cryptosuites/bbsSimple.ts +0 -21
- package/src/vc/cryptosuites/eddsa.ts +0 -99
- package/src/vc/documentLoader.ts +0 -67
- package/src/vc/proofs/data-integrity.ts +0 -33
- package/src/vc/utils/jsonld.ts +0 -18
- package/tests/__mocks__/bbs-signatures.js +0 -17
- package/tests/__mocks__/mf-base58.js +0 -24
- package/tests/fixtures/did-documents.ts +0 -247
- package/tests/index.test.ts +0 -21
- package/tests/integration/BatchOperations.test.ts +0 -531
- package/tests/integration/CompleteLifecycle.e2e.test.ts +0 -735
- package/tests/integration/CredentialManager.test.ts +0 -42
- package/tests/integration/DIDManager.test.ts +0 -41
- package/tests/integration/DidPeerToWebVhFlow.test.ts +0 -351
- package/tests/integration/Events.test.ts +0 -435
- package/tests/integration/Lifecycle.transfer.btco.integration.test.ts +0 -25
- package/tests/integration/LifecycleManager.test.ts +0 -21
- package/tests/integration/MultikeyFlow.test.ts +0 -52
- package/tests/integration/TelemetryIntegration.test.ts +0 -395
- package/tests/integration/WebVhPublish.test.ts +0 -48
- package/tests/integration/createTypedOriginal.test.ts +0 -379
- package/tests/integration/migration/peer-to-webvh.test.ts +0 -172
- package/tests/manual/test-commit-creation.ts +0 -323
- package/tests/mocks/MockKeyStore.ts +0 -38
- package/tests/mocks/adapters/MemoryStorageAdapter.ts +0 -24
- package/tests/mocks/adapters/MockFeeOracle.ts +0 -11
- package/tests/mocks/adapters/MockOrdinalsProvider.ts +0 -76
- package/tests/mocks/adapters/OrdMockProvider.test.ts +0 -176
- package/tests/mocks/adapters/index.ts +0 -6
- package/tests/performance/BatchOperations.perf.test.ts +0 -403
- package/tests/performance/logging.perf.test.ts +0 -336
- package/tests/sdk.test.ts +0 -43
- package/tests/security/bitcoin-penetration-tests.test.ts +0 -622
- package/tests/setup.bun.ts +0 -69
- package/tests/setup.jest.ts +0 -23
- package/tests/stress/batch-operations-stress.test.ts +0 -571
- package/tests/unit/adapters/FeeOracleMock.test.ts +0 -40
- package/tests/unit/bitcoin/BitcoinManager.test.ts +0 -293
- package/tests/unit/bitcoin/BroadcastClient.test.ts +0 -52
- package/tests/unit/bitcoin/OrdNodeProvider.test.ts +0 -53
- package/tests/unit/bitcoin/OrdinalsClient.test.ts +0 -381
- package/tests/unit/bitcoin/OrdinalsClientProvider.test.ts +0 -102
- package/tests/unit/bitcoin/PSBTBuilder.test.ts +0 -84
- package/tests/unit/bitcoin/fee-calculation.test.ts +0 -261
- package/tests/unit/bitcoin/transactions/commit.test.ts +0 -649
- package/tests/unit/bitcoin/transfer.test.ts +0 -31
- package/tests/unit/bitcoin/utxo-selection-new.test.ts +0 -502
- package/tests/unit/bitcoin/utxo.more.test.ts +0 -39
- package/tests/unit/bitcoin/utxo.selection.test.ts +0 -38
- package/tests/unit/core/OriginalsSDK.test.ts +0 -152
- package/tests/unit/crypto/Multikey.test.ts +0 -206
- package/tests/unit/crypto/Signer.test.ts +0 -408
- package/tests/unit/did/BtcoDidResolver.test.ts +0 -611
- package/tests/unit/did/DIDManager.more.test.ts +0 -43
- package/tests/unit/did/DIDManager.test.ts +0 -185
- package/tests/unit/did/Ed25519Verifier.test.ts +0 -160
- package/tests/unit/did/KeyManager.test.ts +0 -452
- package/tests/unit/did/OrdinalsClientProviderAdapter.test.ts +0 -45
- package/tests/unit/did/WebVHManager.test.ts +0 -435
- package/tests/unit/did/createBtcoDidDocument.test.ts +0 -67
- package/tests/unit/did/providers/OrdinalsClientProviderAdapter.test.ts +0 -159
- package/tests/unit/events/EventEmitter.test.ts +0 -407
- package/tests/unit/kinds/KindRegistry.test.ts +0 -329
- package/tests/unit/kinds/types.test.ts +0 -409
- package/tests/unit/kinds/validators.test.ts +0 -651
- package/tests/unit/lifecycle/BatchOperations.test.ts +0 -527
- package/tests/unit/lifecycle/LifecycleManager.cleanapi.test.ts +0 -441
- package/tests/unit/lifecycle/LifecycleManager.keymanagement.test.ts +0 -312
- package/tests/unit/lifecycle/LifecycleManager.prov.test.ts +0 -18
- package/tests/unit/lifecycle/LifecycleManager.test.ts +0 -213
- package/tests/unit/lifecycle/LifecycleManager.transfer.unit.test.ts +0 -30
- package/tests/unit/lifecycle/OriginalsAsset.test.ts +0 -176
- package/tests/unit/lifecycle/ProvenanceQuery.test.ts +0 -577
- package/tests/unit/lifecycle/ResourceVersioning.test.ts +0 -651
- package/tests/unit/resources/ResourceManager.test.ts +0 -740
- package/tests/unit/storage/MemoryStorageAdapter.test.ts +0 -93
- package/tests/unit/types/network.test.ts +0 -255
- package/tests/unit/utils/EventIntegration.test.ts +0 -384
- package/tests/unit/utils/Logger.test.ts +0 -473
- package/tests/unit/utils/MetricsCollector.test.ts +0 -358
- package/tests/unit/utils/bitcoin-address.test.ts +0 -250
- package/tests/unit/utils/cbor.test.ts +0 -35
- package/tests/unit/utils/encoding.test.ts +0 -318
- package/tests/unit/utils/hash.test.ts +0 -12
- package/tests/unit/utils/retry.test.ts +0 -100
- package/tests/unit/utils/satoshi-validation.test.ts +0 -354
- package/tests/unit/utils/serialization.test.ts +0 -124
- package/tests/unit/utils/telemetry.test.ts +0 -52
- package/tests/unit/utils/validation.test.ts +0 -141
- package/tests/unit/vc/CredentialManager.helpers.test.ts +0 -527
- package/tests/unit/vc/CredentialManager.test.ts +0 -487
- package/tests/unit/vc/Issuer.test.ts +0 -107
- package/tests/unit/vc/Verifier.test.ts +0 -525
- package/tests/unit/vc/bbs.test.ts +0 -282
- package/tests/unit/vc/cryptosuites/eddsa.test.ts +0 -398
- package/tests/unit/vc/documentLoader.test.ts +0 -121
- package/tests/unit/vc/proofs/data-integrity.test.ts +0 -24
- package/tsconfig.json +0 -31
- package/tsconfig.test.json +0 -15
|
@@ -1,379 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Integration tests for createTypedOriginal
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { describe, expect, it, beforeEach } from 'bun:test';
|
|
6
|
-
import { OriginalsSDK } from '../../src/core/OriginalsSDK';
|
|
7
|
-
import {
|
|
8
|
-
OriginalKind,
|
|
9
|
-
type AppManifest,
|
|
10
|
-
type ModuleManifest,
|
|
11
|
-
type DatasetManifest,
|
|
12
|
-
KindRegistry,
|
|
13
|
-
} from '../../src/kinds';
|
|
14
|
-
import { hashResource } from '../../src/utils/validation';
|
|
15
|
-
|
|
16
|
-
describe('LifecycleManager.createTypedOriginal', () => {
|
|
17
|
-
let sdk: OriginalsSDK;
|
|
18
|
-
|
|
19
|
-
beforeEach(() => {
|
|
20
|
-
sdk = OriginalsSDK.create({
|
|
21
|
-
network: 'regtest',
|
|
22
|
-
defaultKeyType: 'Ed25519',
|
|
23
|
-
enableLogging: false,
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
// Helper to create a resource with valid hash
|
|
28
|
-
const createResource = (id: string, content: string, type: string, contentType: string) => {
|
|
29
|
-
const hash = hashResource(Buffer.from(content));
|
|
30
|
-
return {
|
|
31
|
-
id,
|
|
32
|
-
type,
|
|
33
|
-
contentType,
|
|
34
|
-
content,
|
|
35
|
-
hash,
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
describe('App Original creation', () => {
|
|
40
|
-
it('should create a valid App Original', async () => {
|
|
41
|
-
const manifest: AppManifest = {
|
|
42
|
-
kind: OriginalKind.App,
|
|
43
|
-
name: 'test-cli-app',
|
|
44
|
-
version: '1.0.0',
|
|
45
|
-
description: 'A test CLI application',
|
|
46
|
-
resources: [
|
|
47
|
-
createResource('index.js', 'console.log("Hello");', 'code', 'application/javascript'),
|
|
48
|
-
],
|
|
49
|
-
metadata: {
|
|
50
|
-
runtime: 'node',
|
|
51
|
-
entrypoint: 'index.js',
|
|
52
|
-
platforms: ['linux', 'darwin'],
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const asset = await sdk.lifecycle.createTypedOriginal(OriginalKind.App, manifest);
|
|
57
|
-
|
|
58
|
-
expect(asset).toBeDefined();
|
|
59
|
-
expect(asset.id).toMatch(/^did:peer:/);
|
|
60
|
-
expect(asset.currentLayer).toBe('did:peer');
|
|
61
|
-
expect(asset.resources.length).toBe(1);
|
|
62
|
-
expect(asset.resources[0].id).toBe('index.js');
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('should store manifest on the asset', async () => {
|
|
66
|
-
const manifest: AppManifest = {
|
|
67
|
-
kind: OriginalKind.App,
|
|
68
|
-
name: 'manifest-test',
|
|
69
|
-
version: '2.0.0',
|
|
70
|
-
resources: [
|
|
71
|
-
createResource('app.js', 'export default {}', 'code', 'application/javascript'),
|
|
72
|
-
],
|
|
73
|
-
metadata: {
|
|
74
|
-
runtime: 'bun',
|
|
75
|
-
entrypoint: 'app.js',
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const asset = await sdk.lifecycle.createTypedOriginal(OriginalKind.App, manifest);
|
|
80
|
-
|
|
81
|
-
// Retrieve manifest using getManifest
|
|
82
|
-
const storedManifest = sdk.lifecycle.getManifest<OriginalKind.App>(asset);
|
|
83
|
-
|
|
84
|
-
expect(storedManifest).toBeDefined();
|
|
85
|
-
expect(storedManifest?.name).toBe('manifest-test');
|
|
86
|
-
expect(storedManifest?.version).toBe('2.0.0');
|
|
87
|
-
expect(storedManifest?.metadata.runtime).toBe('bun');
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('should reject invalid App manifest', async () => {
|
|
91
|
-
const invalidManifest = {
|
|
92
|
-
kind: OriginalKind.App,
|
|
93
|
-
name: 'invalid-app',
|
|
94
|
-
version: '1.0.0',
|
|
95
|
-
resources: [
|
|
96
|
-
createResource('index.js', 'code', 'code', 'application/javascript'),
|
|
97
|
-
],
|
|
98
|
-
metadata: {
|
|
99
|
-
// Missing runtime and entrypoint
|
|
100
|
-
} as any
|
|
101
|
-
} as AppManifest;
|
|
102
|
-
|
|
103
|
-
await expect(
|
|
104
|
-
sdk.lifecycle.createTypedOriginal(OriginalKind.App, invalidManifest)
|
|
105
|
-
).rejects.toThrow(/validation failed/i);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('should reject mismatched kind', async () => {
|
|
109
|
-
const manifest: AppManifest = {
|
|
110
|
-
kind: OriginalKind.App,
|
|
111
|
-
name: 'test-app',
|
|
112
|
-
version: '1.0.0',
|
|
113
|
-
resources: [
|
|
114
|
-
createResource('index.js', 'code', 'code', 'application/javascript'),
|
|
115
|
-
],
|
|
116
|
-
metadata: {
|
|
117
|
-
runtime: 'node',
|
|
118
|
-
entrypoint: 'index.js',
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
// Try to create with wrong kind
|
|
123
|
-
await expect(
|
|
124
|
-
sdk.lifecycle.createTypedOriginal(OriginalKind.Module, manifest as any)
|
|
125
|
-
).rejects.toThrow(/does not match/);
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
describe('Module Original creation', () => {
|
|
130
|
-
it('should create a valid Module Original', async () => {
|
|
131
|
-
const manifest: ModuleManifest = {
|
|
132
|
-
kind: OriginalKind.Module,
|
|
133
|
-
name: '@myorg/utils',
|
|
134
|
-
version: '1.0.0',
|
|
135
|
-
description: 'Utility functions',
|
|
136
|
-
resources: [
|
|
137
|
-
createResource('index.mjs', 'export function add(a, b) { return a + b; }', 'code', 'application/javascript'),
|
|
138
|
-
createResource('index.d.ts', 'export function add(a: number, b: number): number;', 'code', 'application/typescript'),
|
|
139
|
-
],
|
|
140
|
-
metadata: {
|
|
141
|
-
format: 'esm',
|
|
142
|
-
main: 'index.mjs',
|
|
143
|
-
types: 'index.d.ts',
|
|
144
|
-
exports: {
|
|
145
|
-
'.': {
|
|
146
|
-
import: './index.mjs',
|
|
147
|
-
types: './index.d.ts',
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
const asset = await sdk.lifecycle.createTypedOriginal(OriginalKind.Module, manifest);
|
|
154
|
-
|
|
155
|
-
expect(asset).toBeDefined();
|
|
156
|
-
expect(asset.resources.length).toBe(2);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it('should reject module with invalid format', async () => {
|
|
160
|
-
const manifest = {
|
|
161
|
-
kind: OriginalKind.Module,
|
|
162
|
-
name: 'bad-module',
|
|
163
|
-
version: '1.0.0',
|
|
164
|
-
resources: [
|
|
165
|
-
createResource('index.js', 'module.exports = {}', 'code', 'application/javascript'),
|
|
166
|
-
],
|
|
167
|
-
metadata: {
|
|
168
|
-
format: 'invalid-format' as any,
|
|
169
|
-
main: 'index.js',
|
|
170
|
-
}
|
|
171
|
-
} as ModuleManifest;
|
|
172
|
-
|
|
173
|
-
await expect(
|
|
174
|
-
sdk.lifecycle.createTypedOriginal(OriginalKind.Module, manifest)
|
|
175
|
-
).rejects.toThrow(/validation failed/i);
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
describe('Dataset Original creation', () => {
|
|
180
|
-
it('should create a valid Dataset Original', async () => {
|
|
181
|
-
const manifest: DatasetManifest = {
|
|
182
|
-
kind: OriginalKind.Dataset,
|
|
183
|
-
name: 'user-analytics',
|
|
184
|
-
version: '1.0.0',
|
|
185
|
-
resources: [
|
|
186
|
-
createResource('data.json', '{"users": []}', 'data', 'application/json'),
|
|
187
|
-
],
|
|
188
|
-
metadata: {
|
|
189
|
-
format: 'json',
|
|
190
|
-
schema: {
|
|
191
|
-
type: 'object',
|
|
192
|
-
properties: {
|
|
193
|
-
users: { type: 'array' }
|
|
194
|
-
}
|
|
195
|
-
},
|
|
196
|
-
recordCount: 0,
|
|
197
|
-
privacy: 'internal',
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
const asset = await sdk.lifecycle.createTypedOriginal(OriginalKind.Dataset, manifest);
|
|
202
|
-
|
|
203
|
-
expect(asset).toBeDefined();
|
|
204
|
-
expect(asset.resources.length).toBe(1);
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
describe('Options handling', () => {
|
|
209
|
-
it('should skip validation when skipValidation is true', async () => {
|
|
210
|
-
// This manifest is technically invalid (missing entrypoint)
|
|
211
|
-
const invalidManifest = {
|
|
212
|
-
kind: OriginalKind.App,
|
|
213
|
-
name: 'skip-validation-test',
|
|
214
|
-
version: '1.0.0',
|
|
215
|
-
resources: [
|
|
216
|
-
createResource('index.js', 'code', 'code', 'application/javascript'),
|
|
217
|
-
],
|
|
218
|
-
metadata: {
|
|
219
|
-
runtime: 'node',
|
|
220
|
-
// Missing entrypoint - would normally fail validation
|
|
221
|
-
} as any
|
|
222
|
-
} as AppManifest;
|
|
223
|
-
|
|
224
|
-
// Should not throw when skipping validation
|
|
225
|
-
const asset = await sdk.lifecycle.createTypedOriginal(
|
|
226
|
-
OriginalKind.App,
|
|
227
|
-
invalidManifest,
|
|
228
|
-
{ skipValidation: true }
|
|
229
|
-
);
|
|
230
|
-
|
|
231
|
-
expect(asset).toBeDefined();
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
it('should fail in strict mode when there are warnings', async () => {
|
|
235
|
-
const manifest: AppManifest = {
|
|
236
|
-
kind: OriginalKind.App,
|
|
237
|
-
name: 'strict-mode-test',
|
|
238
|
-
version: '1.0.0',
|
|
239
|
-
// No description - generates warning
|
|
240
|
-
resources: [
|
|
241
|
-
createResource('index.js', 'code', 'code', 'application/javascript'),
|
|
242
|
-
],
|
|
243
|
-
metadata: {
|
|
244
|
-
runtime: 'node',
|
|
245
|
-
entrypoint: 'index.js',
|
|
246
|
-
// No runtimeVersion - generates warning
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
// Without strict mode - should pass
|
|
251
|
-
const asset = await sdk.lifecycle.createTypedOriginal(
|
|
252
|
-
OriginalKind.App,
|
|
253
|
-
manifest,
|
|
254
|
-
{ strictMode: false }
|
|
255
|
-
);
|
|
256
|
-
expect(asset).toBeDefined();
|
|
257
|
-
|
|
258
|
-
// With strict mode - should fail due to warnings
|
|
259
|
-
await expect(
|
|
260
|
-
sdk.lifecycle.createTypedOriginal(OriginalKind.App, manifest, { strictMode: true })
|
|
261
|
-
).rejects.toThrow(/validation failed/i);
|
|
262
|
-
});
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
describe('Cost estimation', () => {
|
|
266
|
-
it('should estimate cost for typed Original to did:btco', async () => {
|
|
267
|
-
const manifest: ModuleManifest = {
|
|
268
|
-
kind: OriginalKind.Module,
|
|
269
|
-
name: 'cost-test-module',
|
|
270
|
-
version: '1.0.0',
|
|
271
|
-
resources: [
|
|
272
|
-
createResource('index.js', 'export const x = 1;', 'code', 'application/javascript'),
|
|
273
|
-
],
|
|
274
|
-
metadata: {
|
|
275
|
-
format: 'esm',
|
|
276
|
-
main: 'index.js',
|
|
277
|
-
}
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
const estimate = await sdk.lifecycle.estimateTypedOriginalCost(
|
|
281
|
-
manifest,
|
|
282
|
-
'did:btco'
|
|
283
|
-
);
|
|
284
|
-
|
|
285
|
-
expect(estimate).toBeDefined();
|
|
286
|
-
expect(estimate.totalSats).toBeGreaterThan(0);
|
|
287
|
-
expect(estimate.dataSize).toBeGreaterThan(0);
|
|
288
|
-
expect(estimate.targetLayer).toBe('did:btco');
|
|
289
|
-
expect(estimate.breakdown).toBeDefined();
|
|
290
|
-
expect(estimate.breakdown.networkFee).toBeGreaterThan(0);
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
it('should return zero cost for did:webvh', async () => {
|
|
294
|
-
const manifest: ModuleManifest = {
|
|
295
|
-
kind: OriginalKind.Module,
|
|
296
|
-
name: 'webvh-cost-test',
|
|
297
|
-
version: '1.0.0',
|
|
298
|
-
resources: [
|
|
299
|
-
createResource('index.js', 'export const x = 1;', 'code', 'application/javascript'),
|
|
300
|
-
],
|
|
301
|
-
metadata: {
|
|
302
|
-
format: 'esm',
|
|
303
|
-
main: 'index.js',
|
|
304
|
-
}
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
const estimate = await sdk.lifecycle.estimateTypedOriginalCost(
|
|
308
|
-
manifest,
|
|
309
|
-
'did:webvh'
|
|
310
|
-
);
|
|
311
|
-
|
|
312
|
-
expect(estimate.totalSats).toBe(0);
|
|
313
|
-
expect(estimate.targetLayer).toBe('did:webvh');
|
|
314
|
-
});
|
|
315
|
-
});
|
|
316
|
-
|
|
317
|
-
describe('Integration with provenance', () => {
|
|
318
|
-
it('should have proper provenance after creation', async () => {
|
|
319
|
-
const manifest: AppManifest = {
|
|
320
|
-
kind: OriginalKind.App,
|
|
321
|
-
name: 'provenance-test',
|
|
322
|
-
version: '1.0.0',
|
|
323
|
-
resources: [
|
|
324
|
-
createResource('index.js', 'console.log("test");', 'code', 'application/javascript'),
|
|
325
|
-
],
|
|
326
|
-
metadata: {
|
|
327
|
-
runtime: 'node',
|
|
328
|
-
entrypoint: 'index.js',
|
|
329
|
-
}
|
|
330
|
-
};
|
|
331
|
-
|
|
332
|
-
const asset = await sdk.lifecycle.createTypedOriginal(OriginalKind.App, manifest);
|
|
333
|
-
const provenance = asset.getProvenance();
|
|
334
|
-
|
|
335
|
-
expect(provenance.createdAt).toBeDefined();
|
|
336
|
-
expect(provenance.creator).toBe(asset.id);
|
|
337
|
-
expect(provenance.migrations).toEqual([]);
|
|
338
|
-
expect(provenance.transfers).toEqual([]);
|
|
339
|
-
});
|
|
340
|
-
});
|
|
341
|
-
});
|
|
342
|
-
|
|
343
|
-
describe('KindRegistry integration', () => {
|
|
344
|
-
it('should use KindRegistry for validation in createTypedOriginal', async () => {
|
|
345
|
-
const sdk = OriginalsSDK.create({
|
|
346
|
-
network: 'regtest',
|
|
347
|
-
defaultKeyType: 'Ed25519',
|
|
348
|
-
});
|
|
349
|
-
|
|
350
|
-
const registry = KindRegistry.getInstance();
|
|
351
|
-
|
|
352
|
-
// Validate directly with registry
|
|
353
|
-
const manifest: AppManifest = {
|
|
354
|
-
kind: OriginalKind.App,
|
|
355
|
-
name: 'registry-test',
|
|
356
|
-
version: '1.0.0',
|
|
357
|
-
resources: [{
|
|
358
|
-
id: 'index.js',
|
|
359
|
-
type: 'code',
|
|
360
|
-
contentType: 'application/javascript',
|
|
361
|
-
hash: hashResource(Buffer.from('code')),
|
|
362
|
-
content: 'code',
|
|
363
|
-
}],
|
|
364
|
-
metadata: {
|
|
365
|
-
runtime: 'node',
|
|
366
|
-
entrypoint: 'index.js',
|
|
367
|
-
}
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
const registryResult = registry.validate(manifest);
|
|
371
|
-
|
|
372
|
-
// If registry validation passes, createTypedOriginal should also work
|
|
373
|
-
if (registryResult.isValid) {
|
|
374
|
-
const asset = await sdk.lifecycle.createTypedOriginal(OriginalKind.App, manifest);
|
|
375
|
-
expect(asset).toBeDefined();
|
|
376
|
-
}
|
|
377
|
-
});
|
|
378
|
-
});
|
|
379
|
-
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Integration tests for peer → webvh migration
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { describe, test, expect, beforeEach } from 'bun:test';
|
|
6
|
-
import { OriginalsSDK } from '../../../src';
|
|
7
|
-
import { MigrationManager } from '../../../src/migration';
|
|
8
|
-
import { MigrationStateEnum } from '../../../src/migration/types';
|
|
9
|
-
|
|
10
|
-
describe('Peer to WebVH Migration', () => {
|
|
11
|
-
let sdk: OriginalsSDK;
|
|
12
|
-
let migrationManager: MigrationManager;
|
|
13
|
-
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
// Reset singleton
|
|
16
|
-
MigrationManager.resetInstance();
|
|
17
|
-
|
|
18
|
-
// Create SDK instance
|
|
19
|
-
sdk = OriginalsSDK.create({
|
|
20
|
-
network: 'signet',
|
|
21
|
-
defaultKeyType: 'Ed25519'
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
// Initialize migration manager
|
|
25
|
-
migrationManager = MigrationManager.getInstance(
|
|
26
|
-
sdk['config'],
|
|
27
|
-
sdk.did,
|
|
28
|
-
sdk.credentials
|
|
29
|
-
);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test('should successfully migrate from peer to webvh', async () => {
|
|
33
|
-
// Create a peer DID
|
|
34
|
-
const resources = [
|
|
35
|
-
{
|
|
36
|
-
id: 'resource-1',
|
|
37
|
-
type: 'Image',
|
|
38
|
-
contentType: 'image/png',
|
|
39
|
-
hash: 'abc123',
|
|
40
|
-
content: 'test-content'
|
|
41
|
-
}
|
|
42
|
-
];
|
|
43
|
-
|
|
44
|
-
const peerDid = await sdk.did.createDIDPeer(resources);
|
|
45
|
-
|
|
46
|
-
// Migrate to webvh
|
|
47
|
-
const result = await migrationManager.migrate({
|
|
48
|
-
sourceDid: peerDid.id,
|
|
49
|
-
targetLayer: 'webvh',
|
|
50
|
-
domain: 'example.com'
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
// Verify migration success
|
|
54
|
-
expect(result.success).toBe(true);
|
|
55
|
-
expect(result.state).toBe(MigrationStateEnum.COMPLETED);
|
|
56
|
-
expect(result.targetDid).toBeDefined();
|
|
57
|
-
expect(result.targetDid).toContain('did:webvh:');
|
|
58
|
-
expect(result.sourceDid).toBe(peerDid.id);
|
|
59
|
-
|
|
60
|
-
// Verify audit record was created
|
|
61
|
-
expect(result.auditRecord).toBeDefined();
|
|
62
|
-
expect(result.auditRecord.finalState).toBe(MigrationStateEnum.COMPLETED);
|
|
63
|
-
expect(result.auditRecord.errors).toHaveLength(0);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
test('should fail migration with invalid domain', async () => {
|
|
67
|
-
const resources = [
|
|
68
|
-
{
|
|
69
|
-
id: 'resource-1',
|
|
70
|
-
type: 'Image',
|
|
71
|
-
contentType: 'image/png',
|
|
72
|
-
hash: 'abc123'
|
|
73
|
-
}
|
|
74
|
-
];
|
|
75
|
-
|
|
76
|
-
const peerDid = await sdk.did.createDIDPeer(resources);
|
|
77
|
-
|
|
78
|
-
// Attempt migration without domain
|
|
79
|
-
const result = await migrationManager.migrate({
|
|
80
|
-
sourceDid: peerDid.id,
|
|
81
|
-
targetLayer: 'webvh'
|
|
82
|
-
// Missing domain
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
// Verify migration failed
|
|
86
|
-
expect(result.success).toBe(false);
|
|
87
|
-
expect(result.error).toBeDefined();
|
|
88
|
-
expect(result.error?.code).toBe('VALIDATION_FAILED');
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
test('should track migration state throughout process', async () => {
|
|
92
|
-
const resources = [
|
|
93
|
-
{
|
|
94
|
-
id: 'resource-1',
|
|
95
|
-
type: 'Image',
|
|
96
|
-
contentType: 'image/png',
|
|
97
|
-
hash: 'abc123'
|
|
98
|
-
}
|
|
99
|
-
];
|
|
100
|
-
|
|
101
|
-
const peerDid = await sdk.did.createDIDPeer(resources);
|
|
102
|
-
|
|
103
|
-
// Start migration
|
|
104
|
-
const migrationPromise = migrationManager.migrate({
|
|
105
|
-
sourceDid: peerDid.id,
|
|
106
|
-
targetLayer: 'webvh',
|
|
107
|
-
domain: 'example.com'
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
const result = await migrationPromise;
|
|
111
|
-
|
|
112
|
-
// Check final state
|
|
113
|
-
const state = await migrationManager.getMigrationStatus(result.migrationId);
|
|
114
|
-
expect(state).toBeDefined();
|
|
115
|
-
expect(state.state).toBe(MigrationStateEnum.COMPLETED);
|
|
116
|
-
expect(state.progress).toBe(100);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
test('should get migration history for DID', async () => {
|
|
120
|
-
const resources = [
|
|
121
|
-
{
|
|
122
|
-
id: 'resource-1',
|
|
123
|
-
type: 'Image',
|
|
124
|
-
contentType: 'image/png',
|
|
125
|
-
hash: 'abc123'
|
|
126
|
-
}
|
|
127
|
-
];
|
|
128
|
-
|
|
129
|
-
const peerDid = await sdk.did.createDIDPeer(resources);
|
|
130
|
-
|
|
131
|
-
// Perform migration
|
|
132
|
-
await migrationManager.migrate({
|
|
133
|
-
sourceDid: peerDid.id,
|
|
134
|
-
targetLayer: 'webvh',
|
|
135
|
-
domain: 'example.com'
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
// Get migration history
|
|
139
|
-
const history = await migrationManager.getMigrationHistory(peerDid.id);
|
|
140
|
-
|
|
141
|
-
expect(history).toBeDefined();
|
|
142
|
-
expect(history.length).toBeGreaterThan(0);
|
|
143
|
-
expect(history[0].sourceDid).toBe(peerDid.id);
|
|
144
|
-
expect(history[0].targetLayer).toBe('webvh');
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
test('should estimate migration cost', async () => {
|
|
148
|
-
const resources = [
|
|
149
|
-
{
|
|
150
|
-
id: 'resource-1',
|
|
151
|
-
type: 'Image',
|
|
152
|
-
contentType: 'image/png',
|
|
153
|
-
hash: 'abc123'
|
|
154
|
-
}
|
|
155
|
-
];
|
|
156
|
-
|
|
157
|
-
const peerDid = await sdk.did.createDIDPeer(resources);
|
|
158
|
-
|
|
159
|
-
// Estimate cost
|
|
160
|
-
const cost = await migrationManager.estimateMigrationCost(
|
|
161
|
-
peerDid.id,
|
|
162
|
-
'webvh'
|
|
163
|
-
);
|
|
164
|
-
|
|
165
|
-
expect(cost).toBeDefined();
|
|
166
|
-
expect(cost.totalCost).toBeDefined();
|
|
167
|
-
expect(cost.networkFees).toBeDefined();
|
|
168
|
-
expect(cost.storageCost).toBeDefined();
|
|
169
|
-
expect(cost.totalCost).toBeDefined();
|
|
170
|
-
expect(cost.currency).toBe('sats');
|
|
171
|
-
});
|
|
172
|
-
});
|