@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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@originals/sdk",
|
|
3
|
-
"version": "1.2
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"description": "TypeScript SDK for the Originals Protocol - creating, discovering, and transferring digital assets with cryptographically verifiable provenance",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
package/src/did/DIDManager.ts
CHANGED
|
@@ -289,7 +289,7 @@ export class DIDManager {
|
|
|
289
289
|
let verificationMethods: WebVHVerificationMethod[];
|
|
290
290
|
let updateKeys: string[];
|
|
291
291
|
|
|
292
|
-
// Use external signer if provided (e.g.,
|
|
292
|
+
// Use external signer if provided (e.g., Turnkey integration)
|
|
293
293
|
if (externalSigner) {
|
|
294
294
|
if (!providedVerificationMethods || providedVerificationMethods.length === 0) {
|
|
295
295
|
throw new Error('verificationMethods are required when using externalSigner');
|
package/src/did/WebVHManager.ts
CHANGED
|
@@ -120,7 +120,7 @@ export interface CreateWebVHOptions {
|
|
|
120
120
|
paths?: string[];
|
|
121
121
|
portable?: boolean;
|
|
122
122
|
outputDir?: string; // Directory to save the DID log (did.jsonl)
|
|
123
|
-
externalSigner?: ExternalSigner; // External signer (e.g.,
|
|
123
|
+
externalSigner?: ExternalSigner; // External signer (e.g., Turnkey integration)
|
|
124
124
|
externalVerifier?: ExternalVerifier; // External verifier
|
|
125
125
|
verificationMethods?: VerificationMethod[]; // Pre-configured verification methods
|
|
126
126
|
updateKeys?: string[]; // Pre-configured update keys (e.g., ["did:key:z6Mk..."])
|
|
@@ -162,6 +162,15 @@ export class WebVHManager {
|
|
|
162
162
|
updateKeys: providedUpdateKeys
|
|
163
163
|
} = options;
|
|
164
164
|
|
|
165
|
+
// Validate path segments before creating DID to prevent directory traversal
|
|
166
|
+
if (paths && paths.length > 0) {
|
|
167
|
+
for (const segment of paths) {
|
|
168
|
+
if (!this.isValidPathSegment(segment)) {
|
|
169
|
+
throw new Error(`Invalid path segment in DID: "${segment}". Path segments cannot contain '.', '..', path separators, or be absolute paths.`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
165
174
|
// Dynamically import didwebvh-ts to avoid module resolution issues
|
|
166
175
|
const mod = await import('didwebvh-ts') as unknown as {
|
|
167
176
|
createDID: (options: Record<string, unknown>) => Promise<{
|
|
@@ -187,7 +196,7 @@ export class WebVHManager {
|
|
|
187
196
|
let verificationMethods: VerificationMethod[];
|
|
188
197
|
let updateKeys: string[];
|
|
189
198
|
|
|
190
|
-
// Use external signer if provided (e.g.,
|
|
199
|
+
// Use external signer if provided (e.g., Turnkey integration)
|
|
191
200
|
if (externalSigner) {
|
|
192
201
|
if (!providedVerificationMethods || providedVerificationMethods.length === 0) {
|
|
193
202
|
throw new Error('verificationMethods are required when using externalSigner');
|
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example: Creating a Module Original
|
|
3
|
+
*
|
|
4
|
+
* This example demonstrates how to create a typed Module Original using
|
|
5
|
+
* the Originals SDK's Kind system. Module Originals are reusable code
|
|
6
|
+
* packages with explicit exports, dependencies, and metadata.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
OriginalsSDK,
|
|
11
|
+
OriginalKind,
|
|
12
|
+
OrdMockProvider,
|
|
13
|
+
KindRegistry,
|
|
14
|
+
type OriginalManifest
|
|
15
|
+
} from '../index';
|
|
16
|
+
import { sha256 } from '@noble/hashes/sha2.js';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Helper to compute content hash
|
|
20
|
+
*/
|
|
21
|
+
function computeHash(content: string): string {
|
|
22
|
+
return Buffer.from(sha256(Buffer.from(content))).toString('hex');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Create a simple Module Original
|
|
27
|
+
*/
|
|
28
|
+
async function createSimpleModule(): Promise<void> {
|
|
29
|
+
console.log('=== Creating a Simple Module Original ===\n');
|
|
30
|
+
|
|
31
|
+
// Initialize SDK
|
|
32
|
+
const sdk = OriginalsSDK.create({
|
|
33
|
+
network: 'regtest',
|
|
34
|
+
defaultKeyType: 'Ed25519',
|
|
35
|
+
webvhNetwork: 'magby',
|
|
36
|
+
ordinalsProvider: new OrdMockProvider(),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Define module source code
|
|
40
|
+
const moduleCode = `
|
|
41
|
+
/**
|
|
42
|
+
* A simple greeting utility module
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Generate a personalized greeting
|
|
47
|
+
* @param name - The name to greet
|
|
48
|
+
* @returns A friendly greeting string
|
|
49
|
+
*/
|
|
50
|
+
export function greet(name) {
|
|
51
|
+
return \`Hello, \${name}! Welcome to Originals.\`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Generate a farewell message
|
|
56
|
+
* @param name - The name to say goodbye to
|
|
57
|
+
* @returns A farewell string
|
|
58
|
+
*/
|
|
59
|
+
export function farewell(name) {
|
|
60
|
+
return \`Goodbye, \${name}! See you soon.\`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Get a random greeting from a list
|
|
65
|
+
* @returns A random greeting string
|
|
66
|
+
*/
|
|
67
|
+
export function randomGreeting() {
|
|
68
|
+
const greetings = ['Hey!', 'Hi there!', 'Howdy!', 'Welcome!', 'Greetings!'];
|
|
69
|
+
return greetings[Math.floor(Math.random() * greetings.length)];
|
|
70
|
+
}
|
|
71
|
+
`.trim();
|
|
72
|
+
|
|
73
|
+
// Define TypeScript type definitions
|
|
74
|
+
const typeDefs = `
|
|
75
|
+
/**
|
|
76
|
+
* Type definitions for greeting-utils module
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Generate a personalized greeting
|
|
81
|
+
*/
|
|
82
|
+
export declare function greet(name: string): string;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Generate a farewell message
|
|
86
|
+
*/
|
|
87
|
+
export declare function farewell(name: string): string;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Get a random greeting from a list
|
|
91
|
+
*/
|
|
92
|
+
export declare function randomGreeting(): string;
|
|
93
|
+
`.trim();
|
|
94
|
+
|
|
95
|
+
// Create resources
|
|
96
|
+
const resources = [
|
|
97
|
+
{
|
|
98
|
+
id: 'index.js',
|
|
99
|
+
type: 'code',
|
|
100
|
+
content: moduleCode,
|
|
101
|
+
contentType: 'application/javascript',
|
|
102
|
+
hash: computeHash(moduleCode),
|
|
103
|
+
size: moduleCode.length,
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
id: 'index.d.ts',
|
|
107
|
+
type: 'code',
|
|
108
|
+
content: typeDefs,
|
|
109
|
+
contentType: 'application/typescript',
|
|
110
|
+
hash: computeHash(typeDefs),
|
|
111
|
+
size: typeDefs.length,
|
|
112
|
+
},
|
|
113
|
+
];
|
|
114
|
+
|
|
115
|
+
// Create typed Module Original
|
|
116
|
+
const moduleAsset = await sdk.lifecycle.createTypedOriginal(
|
|
117
|
+
OriginalKind.Module,
|
|
118
|
+
{
|
|
119
|
+
kind: OriginalKind.Module,
|
|
120
|
+
name: 'greeting-utils',
|
|
121
|
+
version: '1.0.0',
|
|
122
|
+
description: 'A simple greeting utility module for generating personalized messages',
|
|
123
|
+
resources,
|
|
124
|
+
tags: ['utility', 'greeting', 'message', 'text'],
|
|
125
|
+
author: {
|
|
126
|
+
name: 'Originals Developer',
|
|
127
|
+
email: 'dev@originals.example',
|
|
128
|
+
},
|
|
129
|
+
license: 'MIT',
|
|
130
|
+
homepage: 'https://github.com/originals/greeting-utils',
|
|
131
|
+
metadata: {
|
|
132
|
+
format: 'esm',
|
|
133
|
+
main: 'index.js',
|
|
134
|
+
types: 'index.d.ts',
|
|
135
|
+
exports: {
|
|
136
|
+
'.': {
|
|
137
|
+
import: './index.js',
|
|
138
|
+
types: './index.d.ts',
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
sideEffects: false,
|
|
142
|
+
},
|
|
143
|
+
}
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
console.log('Created Module Original:');
|
|
147
|
+
console.log(` ID: ${moduleAsset.id}`);
|
|
148
|
+
console.log(` Layer: ${moduleAsset.currentLayer}`);
|
|
149
|
+
console.log(` Resources: ${moduleAsset.resources.length}`);
|
|
150
|
+
console.log('');
|
|
151
|
+
|
|
152
|
+
// Get the manifest back
|
|
153
|
+
const manifest = sdk.lifecycle.getManifest(moduleAsset);
|
|
154
|
+
if (manifest && manifest.metadata) {
|
|
155
|
+
const meta = manifest.metadata as { format?: string; main?: string };
|
|
156
|
+
console.log('Manifest details:');
|
|
157
|
+
console.log(` Name: ${manifest.name}`);
|
|
158
|
+
console.log(` Version: ${manifest.version}`);
|
|
159
|
+
console.log(` Format: ${meta.format}`);
|
|
160
|
+
console.log(` Main: ${meta.main}`);
|
|
161
|
+
}
|
|
162
|
+
console.log('');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Create a Module Original with dependencies
|
|
167
|
+
*/
|
|
168
|
+
async function createModuleWithDependencies(): Promise<void> {
|
|
169
|
+
console.log('=== Creating Module with Dependencies ===\n');
|
|
170
|
+
|
|
171
|
+
const sdk = OriginalsSDK.create({
|
|
172
|
+
network: 'regtest',
|
|
173
|
+
defaultKeyType: 'Ed25519',
|
|
174
|
+
ordinalsProvider: new OrdMockProvider(),
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
// Define module code that depends on another module
|
|
178
|
+
const moduleCode = `
|
|
179
|
+
/**
|
|
180
|
+
* Advanced formatter module that extends greeting-utils
|
|
181
|
+
*/
|
|
182
|
+
import { greet, farewell } from 'greeting-utils';
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Format a message with a timestamp
|
|
186
|
+
* @param message - The message to format
|
|
187
|
+
* @returns Formatted message with timestamp
|
|
188
|
+
*/
|
|
189
|
+
export function withTimestamp(message) {
|
|
190
|
+
const now = new Date().toISOString();
|
|
191
|
+
return \`[\${now}] \${message}\`;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Create a welcome message with timestamp
|
|
196
|
+
* @param name - The name to welcome
|
|
197
|
+
* @returns Timestamped welcome message
|
|
198
|
+
*/
|
|
199
|
+
export function timedGreeting(name) {
|
|
200
|
+
return withTimestamp(greet(name));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Create a farewell message with timestamp
|
|
205
|
+
* @param name - The name to say goodbye to
|
|
206
|
+
* @returns Timestamped farewell message
|
|
207
|
+
*/
|
|
208
|
+
export function timedFarewell(name) {
|
|
209
|
+
return withTimestamp(farewell(name));
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Format text with various styles
|
|
214
|
+
* @param text - Text to format
|
|
215
|
+
* @param style - Style option: 'upper' | 'lower' | 'title'
|
|
216
|
+
*/
|
|
217
|
+
export function formatText(text, style = 'title') {
|
|
218
|
+
switch (style) {
|
|
219
|
+
case 'upper': return text.toUpperCase();
|
|
220
|
+
case 'lower': return text.toLowerCase();
|
|
221
|
+
case 'title': return text.split(' ').map(w => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()).join(' ');
|
|
222
|
+
default: return text;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
`.trim();
|
|
226
|
+
|
|
227
|
+
const moduleAsset = await sdk.lifecycle.createTypedOriginal(
|
|
228
|
+
OriginalKind.Module,
|
|
229
|
+
{
|
|
230
|
+
kind: OriginalKind.Module,
|
|
231
|
+
name: 'advanced-formatter',
|
|
232
|
+
version: '1.0.0',
|
|
233
|
+
description: 'Advanced text formatting utilities',
|
|
234
|
+
resources: [{
|
|
235
|
+
id: 'index.js',
|
|
236
|
+
type: 'code',
|
|
237
|
+
content: moduleCode,
|
|
238
|
+
contentType: 'application/javascript',
|
|
239
|
+
hash: computeHash(moduleCode),
|
|
240
|
+
size: moduleCode.length,
|
|
241
|
+
}],
|
|
242
|
+
// Declare dependency on greeting-utils
|
|
243
|
+
dependencies: [{
|
|
244
|
+
did: 'did:peer:example-greeting-utils-did',
|
|
245
|
+
name: 'greeting-utils',
|
|
246
|
+
version: '^1.0.0',
|
|
247
|
+
}],
|
|
248
|
+
tags: ['formatter', 'text', 'utility'],
|
|
249
|
+
license: 'MIT',
|
|
250
|
+
metadata: {
|
|
251
|
+
format: 'esm',
|
|
252
|
+
main: 'index.js',
|
|
253
|
+
peerDependencies: {
|
|
254
|
+
'greeting-utils': '^1.0.0',
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
}
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
console.log('Created Module with dependencies:');
|
|
261
|
+
console.log(` ID: ${moduleAsset.id}`);
|
|
262
|
+
console.log(` Dependencies: ${moduleAsset.resources.length > 0 ? 'greeting-utils ^1.0.0' : 'none'}`);
|
|
263
|
+
console.log('');
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Validate a module manifest before creation
|
|
268
|
+
*/
|
|
269
|
+
function validateModuleManifest(): void {
|
|
270
|
+
console.log('=== Validating Module Manifest ===\n');
|
|
271
|
+
|
|
272
|
+
const registry = KindRegistry.getInstance();
|
|
273
|
+
|
|
274
|
+
// Valid manifest
|
|
275
|
+
const validManifest = {
|
|
276
|
+
kind: OriginalKind.Module,
|
|
277
|
+
name: 'my-module',
|
|
278
|
+
version: '1.0.0',
|
|
279
|
+
resources: [{
|
|
280
|
+
id: 'index.js',
|
|
281
|
+
type: 'code',
|
|
282
|
+
contentType: 'application/javascript',
|
|
283
|
+
hash: 'abc123',
|
|
284
|
+
}],
|
|
285
|
+
metadata: {
|
|
286
|
+
format: 'esm' as const,
|
|
287
|
+
main: 'index.js',
|
|
288
|
+
},
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
const validResult = registry.validate(validManifest);
|
|
292
|
+
console.log('Valid manifest result:', validResult.isValid ? 'VALID' : 'INVALID');
|
|
293
|
+
if (validResult.warnings.length > 0) {
|
|
294
|
+
console.log('Warnings:', validResult.warnings.map(w => w.message).join(', '));
|
|
295
|
+
}
|
|
296
|
+
console.log('');
|
|
297
|
+
|
|
298
|
+
// Invalid manifest (missing required field)
|
|
299
|
+
const invalidManifest = {
|
|
300
|
+
kind: OriginalKind.Module,
|
|
301
|
+
name: 'bad-module',
|
|
302
|
+
version: '1.0.0',
|
|
303
|
+
resources: [],
|
|
304
|
+
metadata: {
|
|
305
|
+
format: 'esm' as const,
|
|
306
|
+
// Missing 'main' field!
|
|
307
|
+
},
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
// Cast through unknown since this is intentionally invalid for testing validation
|
|
311
|
+
const invalidResult = registry.validate(invalidManifest as unknown as OriginalManifest<OriginalKind.Module>);
|
|
312
|
+
console.log('Invalid manifest result:', invalidResult.isValid ? 'VALID' : 'INVALID');
|
|
313
|
+
if (!invalidResult.isValid) {
|
|
314
|
+
console.log('Errors:');
|
|
315
|
+
invalidResult.errors.forEach(e => {
|
|
316
|
+
console.log(` - [${e.code}] ${e.message}`);
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
console.log('');
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Estimate costs for module inscription
|
|
324
|
+
*/
|
|
325
|
+
async function estimateModuleCosts(): Promise<void> {
|
|
326
|
+
console.log('=== Estimating Module Inscription Costs ===\n');
|
|
327
|
+
|
|
328
|
+
const sdk = OriginalsSDK.create({
|
|
329
|
+
network: 'regtest',
|
|
330
|
+
defaultKeyType: 'Ed25519',
|
|
331
|
+
ordinalsProvider: new OrdMockProvider(),
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
const moduleCode = `export const VERSION = '1.0.0';`;
|
|
335
|
+
|
|
336
|
+
const moduleAsset = await sdk.lifecycle.createTypedOriginal(
|
|
337
|
+
OriginalKind.Module,
|
|
338
|
+
{
|
|
339
|
+
kind: OriginalKind.Module,
|
|
340
|
+
name: 'tiny-module',
|
|
341
|
+
version: '1.0.0',
|
|
342
|
+
resources: [{
|
|
343
|
+
id: 'index.js',
|
|
344
|
+
type: 'code',
|
|
345
|
+
content: moduleCode,
|
|
346
|
+
contentType: 'application/javascript',
|
|
347
|
+
hash: computeHash(moduleCode),
|
|
348
|
+
size: moduleCode.length,
|
|
349
|
+
}],
|
|
350
|
+
metadata: {
|
|
351
|
+
format: 'esm',
|
|
352
|
+
main: 'index.js',
|
|
353
|
+
},
|
|
354
|
+
}
|
|
355
|
+
);
|
|
356
|
+
|
|
357
|
+
// Estimate costs at different fee rates
|
|
358
|
+
const feeRates = [1, 5, 10, 20, 50];
|
|
359
|
+
|
|
360
|
+
console.log('Cost estimates by fee rate:');
|
|
361
|
+
for (const feeRate of feeRates) {
|
|
362
|
+
const cost = await sdk.lifecycle.estimateCost(moduleAsset, 'did:btco', feeRate);
|
|
363
|
+
console.log(` ${feeRate} sat/vB: ${cost.totalSats} sats (~${(cost.totalSats / 100000000).toFixed(8)} BTC)`);
|
|
364
|
+
}
|
|
365
|
+
console.log('');
|
|
366
|
+
|
|
367
|
+
// Validate migration before attempting
|
|
368
|
+
const validation = await sdk.lifecycle.validateMigration(moduleAsset, 'did:btco');
|
|
369
|
+
console.log('Migration validation:');
|
|
370
|
+
console.log(` Valid: ${validation.valid}`);
|
|
371
|
+
console.log(` Checks:`);
|
|
372
|
+
Object.entries(validation.checks).forEach(([check, passed]) => {
|
|
373
|
+
console.log(` - ${check}: ${passed ? '✓' : '✗'}`);
|
|
374
|
+
});
|
|
375
|
+
console.log('');
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Create templates using KindRegistry
|
|
380
|
+
*/
|
|
381
|
+
function useModuleTemplates(): void {
|
|
382
|
+
console.log('=== Using Module Templates ===\n');
|
|
383
|
+
|
|
384
|
+
// Create a template for a Module
|
|
385
|
+
const template = KindRegistry.createTemplate(OriginalKind.Module, 'my-new-module', '0.1.0');
|
|
386
|
+
|
|
387
|
+
console.log('Module template:');
|
|
388
|
+
console.log(JSON.stringify(template, null, 2));
|
|
389
|
+
console.log('');
|
|
390
|
+
|
|
391
|
+
// Parse kind from string
|
|
392
|
+
const kindFromShort = KindRegistry.parseKind('module');
|
|
393
|
+
const kindFromFull = KindRegistry.parseKind('originals:kind:module');
|
|
394
|
+
|
|
395
|
+
console.log('Kind parsing:');
|
|
396
|
+
console.log(` 'module' -> ${kindFromShort}`);
|
|
397
|
+
console.log(` 'originals:kind:module' -> ${kindFromFull}`);
|
|
398
|
+
console.log(` Display name: ${KindRegistry.getDisplayName(OriginalKind.Module)}`);
|
|
399
|
+
console.log(` Short name: ${KindRegistry.getShortName(OriginalKind.Module)}`);
|
|
400
|
+
console.log('');
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Main execution
|
|
405
|
+
*/
|
|
406
|
+
async function main(): Promise<void> {
|
|
407
|
+
try {
|
|
408
|
+
await createSimpleModule();
|
|
409
|
+
await createModuleWithDependencies();
|
|
410
|
+
validateModuleManifest();
|
|
411
|
+
await estimateModuleCosts();
|
|
412
|
+
useModuleTemplates();
|
|
413
|
+
|
|
414
|
+
console.log('=== All Module Examples Completed ===');
|
|
415
|
+
} catch (error) {
|
|
416
|
+
console.error('Error:', error);
|
|
417
|
+
process.exit(1);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// Export for use as module
|
|
422
|
+
export {
|
|
423
|
+
createSimpleModule,
|
|
424
|
+
createModuleWithDependencies,
|
|
425
|
+
validateModuleManifest,
|
|
426
|
+
estimateModuleCosts,
|
|
427
|
+
useModuleTemplates,
|
|
428
|
+
main
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
// Run if executed directly
|
|
432
|
+
if (require.main === module) {
|
|
433
|
+
void main();
|
|
434
|
+
}
|
|
435
|
+
|