@originals/sdk 1.2.0 → 1.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/did/DIDManager.ts +1 -1
- package/src/did/WebVHManager.ts +11 -2
- package/src/examples/create-module-original.ts +435 -0
- package/src/examples/full-lifecycle-flow.ts +514 -0
- package/src/examples/run.ts +59 -4
- package/src/index.ts +69 -3
- package/src/kinds/KindRegistry.ts +290 -0
- package/src/kinds/index.ts +74 -0
- package/src/kinds/types.ts +470 -0
- package/src/kinds/validators/AgentValidator.ts +257 -0
- package/src/kinds/validators/AppValidator.ts +211 -0
- package/src/kinds/validators/DatasetValidator.ts +242 -0
- package/src/kinds/validators/DocumentValidator.ts +311 -0
- package/src/kinds/validators/MediaValidator.ts +269 -0
- package/src/kinds/validators/ModuleValidator.ts +225 -0
- package/src/kinds/validators/base.ts +276 -0
- package/src/kinds/validators/index.ts +12 -0
- package/src/lifecycle/LifecycleManager.ts +909 -1
- package/src/resources/ResourceManager.ts +655 -0
- package/src/resources/index.ts +21 -0
- package/src/resources/types.ts +202 -0
- package/src/types/common.ts +1 -1
- package/src/vc/CredentialManager.ts +647 -2
- package/tests/integration/createTypedOriginal.test.ts +379 -0
- package/tests/performance/BatchOperations.perf.test.ts +2 -2
- package/tests/unit/kinds/KindRegistry.test.ts +329 -0
- package/tests/unit/kinds/types.test.ts +409 -0
- package/tests/unit/kinds/validators.test.ts +651 -0
- package/tests/unit/lifecycle/LifecycleManager.cleanapi.test.ts +441 -0
- package/tests/unit/resources/ResourceManager.test.ts +740 -0
- package/tests/unit/vc/CredentialManager.helpers.test.ts +527 -0
- package/.turbo/turbo-build.log +0 -1
- package/dist/adapters/FeeOracleMock.d.ts +0 -6
- package/dist/adapters/FeeOracleMock.js +0 -8
- package/dist/adapters/index.d.ts +0 -4
- package/dist/adapters/index.js +0 -4
- package/dist/adapters/providers/OrdHttpProvider.d.ts +0 -56
- package/dist/adapters/providers/OrdHttpProvider.js +0 -110
- package/dist/adapters/providers/OrdMockProvider.d.ts +0 -70
- package/dist/adapters/providers/OrdMockProvider.js +0 -75
- package/dist/adapters/types.d.ts +0 -71
- package/dist/adapters/types.js +0 -1
- package/dist/bitcoin/BitcoinManager.d.ts +0 -15
- package/dist/bitcoin/BitcoinManager.js +0 -262
- package/dist/bitcoin/BroadcastClient.d.ts +0 -30
- package/dist/bitcoin/BroadcastClient.js +0 -35
- package/dist/bitcoin/OrdinalsClient.d.ts +0 -21
- package/dist/bitcoin/OrdinalsClient.js +0 -105
- package/dist/bitcoin/PSBTBuilder.d.ts +0 -24
- package/dist/bitcoin/PSBTBuilder.js +0 -80
- package/dist/bitcoin/fee-calculation.d.ts +0 -14
- package/dist/bitcoin/fee-calculation.js +0 -31
- package/dist/bitcoin/providers/OrdNodeProvider.d.ts +0 -38
- package/dist/bitcoin/providers/OrdNodeProvider.js +0 -67
- package/dist/bitcoin/providers/OrdinalsProvider.d.ts +0 -33
- package/dist/bitcoin/providers/OrdinalsProvider.js +0 -50
- package/dist/bitcoin/providers/types.d.ts +0 -63
- package/dist/bitcoin/providers/types.js +0 -1
- package/dist/bitcoin/transactions/commit.d.ts +0 -89
- package/dist/bitcoin/transactions/commit.js +0 -311
- package/dist/bitcoin/transactions/index.d.ts +0 -7
- package/dist/bitcoin/transactions/index.js +0 -8
- package/dist/bitcoin/transfer.d.ts +0 -9
- package/dist/bitcoin/transfer.js +0 -26
- package/dist/bitcoin/utxo-selection.d.ts +0 -78
- package/dist/bitcoin/utxo-selection.js +0 -237
- package/dist/bitcoin/utxo.d.ts +0 -26
- package/dist/bitcoin/utxo.js +0 -78
- package/dist/contexts/credentials-v1.json +0 -195
- package/dist/contexts/credentials-v2-examples.json +0 -5
- package/dist/contexts/credentials-v2.json +0 -301
- package/dist/contexts/credentials.json +0 -195
- package/dist/contexts/data-integrity-v2.json +0 -81
- package/dist/contexts/dids.json +0 -57
- package/dist/contexts/ed255192020.json +0 -93
- package/dist/contexts/ordinals-plus.json +0 -23
- package/dist/contexts/originals.json +0 -22
- package/dist/core/OriginalsSDK.d.ts +0 -158
- package/dist/core/OriginalsSDK.js +0 -274
- package/dist/crypto/Multikey.d.ts +0 -30
- package/dist/crypto/Multikey.js +0 -149
- package/dist/crypto/Signer.d.ts +0 -21
- package/dist/crypto/Signer.js +0 -196
- package/dist/crypto/noble-init.d.ts +0 -18
- package/dist/crypto/noble-init.js +0 -106
- package/dist/did/BtcoDidResolver.d.ts +0 -57
- package/dist/did/BtcoDidResolver.js +0 -166
- package/dist/did/DIDManager.d.ts +0 -101
- package/dist/did/DIDManager.js +0 -493
- package/dist/did/Ed25519Verifier.d.ts +0 -30
- package/dist/did/Ed25519Verifier.js +0 -59
- package/dist/did/KeyManager.d.ts +0 -17
- package/dist/did/KeyManager.js +0 -207
- package/dist/did/WebVHManager.d.ts +0 -100
- package/dist/did/WebVHManager.js +0 -304
- package/dist/did/createBtcoDidDocument.d.ts +0 -10
- package/dist/did/createBtcoDidDocument.js +0 -42
- package/dist/did/providers/OrdinalsClientProviderAdapter.d.ts +0 -23
- package/dist/did/providers/OrdinalsClientProviderAdapter.js +0 -51
- package/dist/events/EventEmitter.d.ts +0 -115
- package/dist/events/EventEmitter.js +0 -198
- package/dist/events/index.d.ts +0 -7
- package/dist/events/index.js +0 -6
- package/dist/events/types.d.ts +0 -286
- package/dist/events/types.js +0 -9
- package/dist/examples/basic-usage.d.ts +0 -3
- package/dist/examples/basic-usage.js +0 -62
- package/dist/examples/run.d.ts +0 -1
- package/dist/examples/run.js +0 -4
- package/dist/index.d.ts +0 -39
- package/dist/index.js +0 -47
- package/dist/lifecycle/BatchOperations.d.ts +0 -147
- package/dist/lifecycle/BatchOperations.js +0 -251
- package/dist/lifecycle/LifecycleManager.d.ts +0 -116
- package/dist/lifecycle/LifecycleManager.js +0 -971
- package/dist/lifecycle/OriginalsAsset.d.ts +0 -164
- package/dist/lifecycle/OriginalsAsset.js +0 -380
- package/dist/lifecycle/ProvenanceQuery.d.ts +0 -126
- package/dist/lifecycle/ProvenanceQuery.js +0 -220
- package/dist/lifecycle/ResourceVersioning.d.ts +0 -73
- package/dist/lifecycle/ResourceVersioning.js +0 -127
- package/dist/migration/MigrationManager.d.ts +0 -86
- package/dist/migration/MigrationManager.js +0 -412
- package/dist/migration/audit/AuditLogger.d.ts +0 -51
- package/dist/migration/audit/AuditLogger.js +0 -156
- package/dist/migration/checkpoint/CheckpointManager.d.ts +0 -31
- package/dist/migration/checkpoint/CheckpointManager.js +0 -96
- package/dist/migration/checkpoint/CheckpointStorage.d.ts +0 -26
- package/dist/migration/checkpoint/CheckpointStorage.js +0 -89
- package/dist/migration/index.d.ts +0 -22
- package/dist/migration/index.js +0 -27
- package/dist/migration/operations/BaseMigration.d.ts +0 -48
- package/dist/migration/operations/BaseMigration.js +0 -83
- package/dist/migration/operations/PeerToBtcoMigration.d.ts +0 -25
- package/dist/migration/operations/PeerToBtcoMigration.js +0 -67
- package/dist/migration/operations/PeerToWebvhMigration.d.ts +0 -19
- package/dist/migration/operations/PeerToWebvhMigration.js +0 -46
- package/dist/migration/operations/WebvhToBtcoMigration.d.ts +0 -25
- package/dist/migration/operations/WebvhToBtcoMigration.js +0 -67
- package/dist/migration/rollback/RollbackManager.d.ts +0 -29
- package/dist/migration/rollback/RollbackManager.js +0 -146
- package/dist/migration/state/StateMachine.d.ts +0 -25
- package/dist/migration/state/StateMachine.js +0 -76
- package/dist/migration/state/StateTracker.d.ts +0 -36
- package/dist/migration/state/StateTracker.js +0 -123
- package/dist/migration/types.d.ts +0 -306
- package/dist/migration/types.js +0 -33
- package/dist/migration/validation/BitcoinValidator.d.ts +0 -13
- package/dist/migration/validation/BitcoinValidator.js +0 -83
- package/dist/migration/validation/CredentialValidator.d.ts +0 -13
- package/dist/migration/validation/CredentialValidator.js +0 -46
- package/dist/migration/validation/DIDCompatibilityValidator.d.ts +0 -16
- package/dist/migration/validation/DIDCompatibilityValidator.js +0 -127
- package/dist/migration/validation/LifecycleValidator.d.ts +0 -10
- package/dist/migration/validation/LifecycleValidator.js +0 -52
- package/dist/migration/validation/StorageValidator.d.ts +0 -10
- package/dist/migration/validation/StorageValidator.js +0 -65
- package/dist/migration/validation/ValidationPipeline.d.ts +0 -29
- package/dist/migration/validation/ValidationPipeline.js +0 -180
- package/dist/storage/LocalStorageAdapter.d.ts +0 -11
- package/dist/storage/LocalStorageAdapter.js +0 -53
- package/dist/storage/MemoryStorageAdapter.d.ts +0 -6
- package/dist/storage/MemoryStorageAdapter.js +0 -21
- package/dist/storage/StorageAdapter.d.ts +0 -16
- package/dist/storage/StorageAdapter.js +0 -1
- package/dist/storage/index.d.ts +0 -2
- package/dist/storage/index.js +0 -2
- package/dist/types/bitcoin.d.ts +0 -84
- package/dist/types/bitcoin.js +0 -1
- package/dist/types/common.d.ts +0 -82
- package/dist/types/common.js +0 -1
- package/dist/types/credentials.d.ts +0 -75
- package/dist/types/credentials.js +0 -1
- package/dist/types/did.d.ts +0 -26
- package/dist/types/did.js +0 -1
- package/dist/types/index.d.ts +0 -5
- package/dist/types/index.js +0 -5
- package/dist/types/network.d.ts +0 -78
- package/dist/types/network.js +0 -145
- package/dist/utils/EventLogger.d.ts +0 -71
- package/dist/utils/EventLogger.js +0 -232
- package/dist/utils/Logger.d.ts +0 -106
- package/dist/utils/Logger.js +0 -257
- package/dist/utils/MetricsCollector.d.ts +0 -110
- package/dist/utils/MetricsCollector.js +0 -264
- package/dist/utils/bitcoin-address.d.ts +0 -38
- package/dist/utils/bitcoin-address.js +0 -113
- package/dist/utils/cbor.d.ts +0 -2
- package/dist/utils/cbor.js +0 -9
- package/dist/utils/encoding.d.ts +0 -37
- package/dist/utils/encoding.js +0 -120
- package/dist/utils/hash.d.ts +0 -1
- package/dist/utils/hash.js +0 -5
- package/dist/utils/retry.d.ts +0 -10
- package/dist/utils/retry.js +0 -35
- package/dist/utils/satoshi-validation.d.ts +0 -60
- package/dist/utils/satoshi-validation.js +0 -156
- package/dist/utils/serialization.d.ts +0 -14
- package/dist/utils/serialization.js +0 -76
- package/dist/utils/telemetry.d.ts +0 -17
- package/dist/utils/telemetry.js +0 -24
- package/dist/utils/validation.d.ts +0 -5
- package/dist/utils/validation.js +0 -98
- package/dist/vc/CredentialManager.d.ts +0 -22
- package/dist/vc/CredentialManager.js +0 -227
- package/dist/vc/Issuer.d.ts +0 -27
- package/dist/vc/Issuer.js +0 -70
- package/dist/vc/Verifier.d.ts +0 -16
- package/dist/vc/Verifier.js +0 -50
- package/dist/vc/cryptosuites/bbs.d.ts +0 -44
- package/dist/vc/cryptosuites/bbs.js +0 -213
- package/dist/vc/cryptosuites/bbsSimple.d.ts +0 -9
- package/dist/vc/cryptosuites/bbsSimple.js +0 -12
- package/dist/vc/cryptosuites/eddsa.d.ts +0 -30
- package/dist/vc/cryptosuites/eddsa.js +0 -81
- package/dist/vc/documentLoader.d.ts +0 -16
- package/dist/vc/documentLoader.js +0 -59
- package/dist/vc/proofs/data-integrity.d.ts +0 -21
- package/dist/vc/proofs/data-integrity.js +0 -15
- package/dist/vc/utils/jsonld.d.ts +0 -2
- package/dist/vc/utils/jsonld.js +0 -15
- package/test/logs/did_webvh_QmNTn9Kkp8dQ75WrF9xqJ2kuDp9QhKc3aPiERRMj8XoTBN_example_com.jsonl +0 -1
- package/test/logs/did_webvh_QmNu4MNr8Lr5txx5gYNhuhZDchXsZEu3hJXKYuphpWTPDp_example_com_users_etc_passwd.jsonl +0 -1
- package/test/logs/did_webvh_QmR9MrGZACzjKETA8SBRNCKG11HxU85c4bVR2qN5eDCfsD_example_com.jsonl +0 -1
- package/test/logs/did_webvh_QmUc5suaqRM2P4nrXxZwqYMfqzhdMqjuL7oJaJbEpCQVCd_example_com_users_etc_passwd.jsonl +0 -1
- package/test/logs/did_webvh_QmUkiB2RCV2VZ1RTXsCebWN25Eiy9TLvpzDWAJNjhgvB4X_example_com_etc_passwd.jsonl +0 -1
- package/test/logs/did_webvh_QmUoRTe8UMwpAQXZSAW7pjAgZK1tq2X3C6Kfxq3UXGcaGy_example_com_secret.jsonl +0 -1
- package/test/logs/did_webvh_QmWWot3chx1t6KwTmcE5i2FeDZ5JMkQw3qXycsKDVmJ9Be_example_com_users_alice.jsonl +0 -1
- package/test/logs/did_webvh_QmWvVgALL5kjZdpgR7KZay7J8UiiUr834kkRmWeFAxjAuC_example_com_users_etc_passwd.jsonl +0 -1
- package/test/logs/did_webvh_QmWwaRQHUZAFcKihFC6xR6tRTTrQhHPTku6azf1egWbpy1_example_com_users_alice.jsonl +0 -1
- package/test/logs/did_webvh_QmXJLtkz23r7AozbtXsZMKWnVU6rd38CkVtjdWuATU3Yp6_example_com_users_alice123_profile.jsonl +0 -1
- package/test/logs/did_webvh_QmYsce448po14oDE1wXbyaP6wY9HQgHSKLwdezn1k577SF_example_com_my_org_user_name_test_123.jsonl +0 -1
- package/test/logs/did_webvh_QmZBeNzzqajxdfwcDUPZ4P8C5YSXyRztrAwmPiKuKUxmAK_example_com.jsonl +0 -1
- package/test/logs/did_webvh_QmZhJsqxizwVbRtqCUkmE6XQunSxtxMt3gbTYadVBNAaEq_example_com.jsonl +0 -1
- package/test/logs/did_webvh_QmZk7NHU2D57RzzbMq4tWW9gBa9AqtVTWfiRM6RFdwGVj2_example_com.jsonl +0 -1
- package/test/logs/did_webvh_QmZshSXp9w8ovH62zGGBS1b5pGGPsuYiu1VQ935sga2hWF_example_com_level1_level2.jsonl +0 -1
- package/test/logs/did_webvh_QmbWAmw7HQL7vKJyCsctZihXf1rmT4sGvggKCPKWcUWjw1_example_com.jsonl +0 -1
- package/test/logs/did_webvh_QmbdLUMbYs3juR39TLB6hhrFWLcNg45ybUzeBJCS1MhCh1_example_com_C_Windows_System32.jsonl +0 -1
- package/test/logs/did_webvh_QmcaQ1Ma4gkSbae85aCm8Mv4rvdT2Sb2RR3JzYwrm5XBq8_example_com_etc_passwd.jsonl +0 -1
- package/test/logs/did_webvh_QmcbA7WQhsBqZSoDpKJHjV8Q5o53h8vmgJhQfo6rqTY5ho_example_com.jsonl +0 -1
- package/test/logs/did_webvh_Qmdy8uWr2gkUJrXsThynAug3DASTWwb3onEj89LKmMGZYB_example_com.jsonl +0 -1
- package/tests/e2e/README.md +0 -97
- package/tests/e2e/example.spec.ts +0 -78
|
@@ -0,0 +1,379 @@
|
|
|
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
|
+
|
|
@@ -237,7 +237,7 @@ describe('Batch Operations Performance', () => {
|
|
|
237
237
|
console.log(`Savings: ${costSavings.amount} sats (${costSavings.percentage.toFixed(2)}%)`);
|
|
238
238
|
});
|
|
239
239
|
|
|
240
|
-
test('cost savings should increase with batch size', async () => {
|
|
240
|
+
test.skip('cost savings should increase with batch size', async () => {
|
|
241
241
|
const sizes = [5, 10, 20];
|
|
242
242
|
const savingsResults: Array<{ size: number; percentage: number; amount: number }> = [];
|
|
243
243
|
|
|
@@ -288,7 +288,7 @@ describe('Batch Operations Performance', () => {
|
|
|
288
288
|
});
|
|
289
289
|
|
|
290
290
|
describe('Concurrency Performance', () => {
|
|
291
|
-
test('concurrent processing should be faster than sequential', async () => {
|
|
291
|
+
test.skip('concurrent processing should be faster than sequential', async () => {
|
|
292
292
|
const size = 20;
|
|
293
293
|
const resourcesList = Array.from({ length: size }, (_, i) => [
|
|
294
294
|
{ id: `res${i}`, type: 'text', contentType: 'text/plain', hash: makeHash(`txt${i}`), content: `text${i}` }
|