@originals/sdk 1.5.0 → 1.6.1
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/dist/adapters/FeeOracleMock.js +2 -2
- package/dist/bitcoin/OrdinalsClient.d.ts +1 -1
- package/dist/bitcoin/OrdinalsClient.js +10 -8
- package/dist/bitcoin/PSBTBuilder.js +1 -1
- package/dist/bitcoin/utxo-selection.js +2 -2
- package/dist/cel/ExternalReferenceManager.d.ts +57 -0
- package/dist/cel/ExternalReferenceManager.js +73 -0
- package/dist/cel/OriginalsCel.d.ts +245 -0
- package/dist/cel/OriginalsCel.js +349 -0
- package/dist/cel/algorithms/createEventLog.d.ts +32 -0
- package/dist/cel/algorithms/createEventLog.js +56 -0
- package/dist/cel/algorithms/deactivateEventLog.d.ts +35 -0
- package/dist/cel/algorithms/deactivateEventLog.js +91 -0
- package/dist/cel/algorithms/index.d.ts +10 -0
- package/dist/cel/algorithms/index.js +10 -0
- package/dist/cel/algorithms/updateEventLog.d.ts +34 -0
- package/dist/cel/algorithms/updateEventLog.js +82 -0
- package/dist/cel/algorithms/verifyEventLog.d.ts +45 -0
- package/dist/cel/algorithms/verifyEventLog.js +255 -0
- package/dist/cel/algorithms/witnessEvent.d.ts +29 -0
- package/dist/cel/algorithms/witnessEvent.js +75 -0
- package/dist/cel/cli/create.d.ts +36 -0
- package/dist/cel/cli/create.js +282 -0
- package/dist/cel/cli/index.d.ts +11 -0
- package/dist/cel/cli/index.js +351 -0
- package/dist/cel/cli/inspect.d.ts +30 -0
- package/dist/cel/cli/inspect.js +475 -0
- package/dist/cel/cli/migrate.d.ts +41 -0
- package/dist/cel/cli/migrate.js +405 -0
- package/dist/cel/cli/verify.d.ts +31 -0
- package/dist/cel/cli/verify.js +205 -0
- package/dist/cel/hash.d.ts +46 -0
- package/dist/cel/hash.js +66 -0
- package/dist/cel/index.d.ts +15 -0
- package/dist/cel/index.js +15 -0
- package/dist/cel/layers/BtcoCelManager.d.ts +121 -0
- package/dist/cel/layers/BtcoCelManager.js +329 -0
- package/dist/cel/layers/PeerCelManager.d.ts +151 -0
- package/dist/cel/layers/PeerCelManager.js +299 -0
- package/dist/cel/layers/WebVHCelManager.d.ts +122 -0
- package/dist/cel/layers/WebVHCelManager.js +291 -0
- package/dist/cel/layers/index.d.ts +13 -0
- package/dist/cel/layers/index.js +16 -0
- package/dist/cel/serialization/cbor.d.ts +42 -0
- package/dist/cel/serialization/cbor.js +163 -0
- package/dist/cel/serialization/index.d.ts +9 -0
- package/dist/cel/serialization/index.js +9 -0
- package/dist/cel/serialization/json.d.ts +41 -0
- package/dist/cel/serialization/json.js +180 -0
- package/dist/cel/types.d.ts +149 -0
- package/dist/cel/types.js +7 -0
- package/dist/cel/witnesses/BitcoinWitness.d.ts +83 -0
- package/dist/cel/witnesses/BitcoinWitness.js +116 -0
- package/dist/cel/witnesses/HttpWitness.d.ts +79 -0
- package/dist/cel/witnesses/HttpWitness.js +163 -0
- package/dist/cel/witnesses/WitnessService.d.ts +49 -0
- package/dist/cel/witnesses/WitnessService.js +10 -0
- package/dist/cel/witnesses/index.d.ts +10 -0
- package/dist/cel/witnesses/index.js +7 -0
- package/dist/core/OriginalsSDK.js +5 -1
- package/dist/crypto/Signer.js +14 -6
- package/dist/crypto/noble-init.js +20 -1
- package/dist/did/BtcoDidResolver.d.ts +2 -2
- package/dist/did/BtcoDidResolver.js +12 -8
- package/dist/did/DIDManager.js +6 -4
- package/dist/did/KeyManager.d.ts +1 -1
- package/dist/did/KeyManager.js +7 -4
- package/dist/did/WebVHManager.js +1 -1
- package/dist/did/createBtcoDidDocument.js +2 -1
- package/dist/events/types.d.ts +4 -1
- package/dist/examples/create-module-original.js +1 -1
- package/dist/examples/full-lifecycle-flow.js +2 -2
- package/dist/index.d.ts +13 -0
- package/dist/index.js +12 -0
- package/dist/kinds/KindRegistry.js +59 -29
- package/dist/lifecycle/BatchOperations.d.ts +5 -3
- package/dist/lifecycle/BatchOperations.js +11 -5
- package/dist/lifecycle/LifecycleManager.d.ts +1 -1
- package/dist/lifecycle/LifecycleManager.js +42 -33
- package/dist/lifecycle/OriginalsAsset.js +2 -2
- package/dist/migration/MigrationManager.js +67 -3
- package/dist/storage/LocalStorageAdapter.js +4 -1
- package/dist/storage/MemoryStorageAdapter.js +7 -7
- package/dist/types/network.js +6 -3
- package/dist/utils/Logger.d.ts +6 -6
- package/dist/utils/Logger.js +5 -3
- package/dist/utils/MetricsCollector.js +1 -1
- package/dist/utils/bitcoin-address.js +4 -2
- package/dist/utils/cbor.js +16 -3
- package/dist/utils/encoding.d.ts +4 -4
- package/dist/utils/encoding.js +7 -6
- package/dist/utils/hash.js +6 -1
- package/dist/utils/serialization.d.ts +2 -2
- package/dist/utils/serialization.js +7 -5
- package/dist/utils/telemetry.js +6 -2
- package/dist/utils/validation.js +8 -4
- package/dist/vc/CredentialManager.d.ts +8 -8
- package/dist/vc/CredentialManager.js +46 -33
- package/dist/vc/Issuer.d.ts +2 -2
- package/dist/vc/Issuer.js +5 -1
- package/dist/vc/Verifier.d.ts +2 -2
- package/dist/vc/Verifier.js +12 -6
- package/dist/vc/documentLoader.d.ts +5 -3
- package/dist/vc/documentLoader.js +5 -4
- package/package.json +4 -1
|
@@ -2,7 +2,7 @@ export class FeeOracleMock {
|
|
|
2
2
|
constructor(feeRate = 7) {
|
|
3
3
|
this.feeRate = feeRate;
|
|
4
4
|
}
|
|
5
|
-
|
|
6
|
-
return Math.max(1, this.feeRate - (targetBlocks - 1));
|
|
5
|
+
estimateFeeRate(targetBlocks = 1) {
|
|
6
|
+
return Promise.resolve(Math.max(1, this.feeRate - (targetBlocks - 1)));
|
|
7
7
|
}
|
|
8
8
|
}
|
|
@@ -6,7 +6,7 @@ export declare class OrdinalsClient {
|
|
|
6
6
|
getInscriptionById(id: string): Promise<OrdinalsInscription | null>;
|
|
7
7
|
getInscriptionsBySatoshi(satoshi: string): Promise<OrdinalsInscription[]>;
|
|
8
8
|
broadcastTransaction(tx: BitcoinTransaction): Promise<string>;
|
|
9
|
-
getTransactionStatus(
|
|
9
|
+
getTransactionStatus(_txid: string): Promise<{
|
|
10
10
|
confirmed: boolean;
|
|
11
11
|
blockHeight?: number;
|
|
12
12
|
confirmations?: number;
|
|
@@ -17,14 +17,14 @@ export class OrdinalsClient {
|
|
|
17
17
|
const inscriptions = await Promise.all(info.inscription_ids.map(id => this.resolveInscription(id)));
|
|
18
18
|
return inscriptions.filter((x) => x !== null);
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
return tx.txid || 'txid';
|
|
20
|
+
broadcastTransaction(tx) {
|
|
21
|
+
return Promise.resolve(tx.txid || 'txid');
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
return { confirmed: false };
|
|
23
|
+
getTransactionStatus(_txid) {
|
|
24
|
+
return Promise.resolve({ confirmed: false });
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
return Math.max(1, blocks) * 10;
|
|
26
|
+
estimateFee(blocks = 1) {
|
|
27
|
+
return Promise.resolve(Math.max(1, blocks) * 10);
|
|
28
28
|
}
|
|
29
29
|
// Added provider-like helper methods commonly expected by higher-level resolvers
|
|
30
30
|
// Minimal placeholder implementations suitable for unit testing
|
|
@@ -44,7 +44,7 @@ export class OrdinalsClient {
|
|
|
44
44
|
return null;
|
|
45
45
|
// Fetch content bytes
|
|
46
46
|
const contentUrl = info.content_url || `${this.rpcUrl}/content/${identifier}`;
|
|
47
|
-
const contentRes = await fetch(contentUrl);
|
|
47
|
+
const contentRes = await fetch(String(contentUrl));
|
|
48
48
|
if (!contentRes.ok)
|
|
49
49
|
throw new Error(`Failed to fetch inscription content: ${contentRes.status}`);
|
|
50
50
|
const contentArrayBuf = await contentRes.arrayBuffer();
|
|
@@ -83,7 +83,9 @@ export class OrdinalsClient {
|
|
|
83
83
|
try {
|
|
84
84
|
text = JSON.parse(text);
|
|
85
85
|
}
|
|
86
|
-
catch (_) {
|
|
86
|
+
catch (_) {
|
|
87
|
+
// Keep original text if parsing fails
|
|
88
|
+
}
|
|
87
89
|
}
|
|
88
90
|
try {
|
|
89
91
|
const bytes = hexToBytes(text);
|
|
@@ -68,7 +68,7 @@ export class PSBTBuilder {
|
|
|
68
68
|
const json = JSON.stringify(payload);
|
|
69
69
|
let psbtBase64;
|
|
70
70
|
try {
|
|
71
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
|
72
72
|
const B = global.Buffer;
|
|
73
73
|
psbtBase64 = B ? B.from(json, 'utf8').toString('base64') : global.btoa(json);
|
|
74
74
|
}
|
|
@@ -70,7 +70,7 @@ export function selectUtxos(utxos, options) {
|
|
|
70
70
|
throw new Error(`Invalid target amount: ${targetAmount}`);
|
|
71
71
|
}
|
|
72
72
|
// Sort UTXOs based on selected strategy
|
|
73
|
-
|
|
73
|
+
const sortedUtxos = [...utxos];
|
|
74
74
|
if (strategy === 'minimize_inputs') {
|
|
75
75
|
// Sort by value descending to use fewest inputs
|
|
76
76
|
sortedUtxos.sort((a, b) => b.value - a.value);
|
|
@@ -129,7 +129,7 @@ export function selectResourceUtxos(availableUtxos, options) {
|
|
|
129
129
|
// Convert requiredAmount to bigint for compatibility with fee calculations
|
|
130
130
|
const requiredAmountBigInt = BigInt(requiredAmount);
|
|
131
131
|
// Filter out UTXOs to avoid and those with resources if not allowed
|
|
132
|
-
|
|
132
|
+
const eligibleUtxos = availableUtxos.filter(utxo => {
|
|
133
133
|
const utxoId = `${utxo.txid}:${utxo.vout}`;
|
|
134
134
|
const shouldAvoid = avoidUtxoIds.includes(utxoId);
|
|
135
135
|
const containsResource = utxo.hasResource === true;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External Reference Manager
|
|
3
|
+
*
|
|
4
|
+
* Creates and verifies external resource references as specified in the CEL specification.
|
|
5
|
+
* External references point to data outside the event log (e.g., large media files)
|
|
6
|
+
* and include a cryptographic hash for content verification.
|
|
7
|
+
*
|
|
8
|
+
* @see https://w3c-ccg.github.io/cel-spec/
|
|
9
|
+
*/
|
|
10
|
+
import type { ExternalReference } from './types';
|
|
11
|
+
/**
|
|
12
|
+
* Creates an external reference for content.
|
|
13
|
+
*
|
|
14
|
+
* Computes a CEL-compliant digestMultibase hash from the content bytes
|
|
15
|
+
* and creates an ExternalReference with the provided metadata.
|
|
16
|
+
*
|
|
17
|
+
* @param content - The raw bytes of the content to reference
|
|
18
|
+
* @param mediaType - The MIME type of the content (e.g., "image/png")
|
|
19
|
+
* @param urls - Optional array of URLs where the content can be retrieved
|
|
20
|
+
* @returns An ExternalReference object with the computed digest
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const imageBytes = await fs.readFile('./image.png');
|
|
25
|
+
* const ref = createExternalReference(
|
|
26
|
+
* imageBytes,
|
|
27
|
+
* 'image/png',
|
|
28
|
+
* ['https://example.com/image.png']
|
|
29
|
+
* );
|
|
30
|
+
* // Returns: { digestMultibase: "uLCA...", mediaType: "image/png", url: ["https://example.com/image.png"] }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function createExternalReference(content: Uint8Array, mediaType: string, urls?: string[]): ExternalReference;
|
|
34
|
+
/**
|
|
35
|
+
* Verifies that content matches an external reference.
|
|
36
|
+
*
|
|
37
|
+
* Computes the hash of the provided content and compares it
|
|
38
|
+
* against the digestMultibase in the reference.
|
|
39
|
+
*
|
|
40
|
+
* @param ref - The external reference to verify against
|
|
41
|
+
* @param content - The raw bytes of the content to verify
|
|
42
|
+
* @returns True if the content hash matches the reference digest, false otherwise
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const imageBytes = await fs.readFile('./image.png');
|
|
47
|
+
* const ref = createExternalReference(imageBytes, 'image/png');
|
|
48
|
+
*
|
|
49
|
+
* // Verify the content
|
|
50
|
+
* const isValid = verifyExternalReference(ref, imageBytes); // true
|
|
51
|
+
*
|
|
52
|
+
* // Modified content will fail verification
|
|
53
|
+
* const modified = new Uint8Array([...imageBytes, 0]);
|
|
54
|
+
* const isValid2 = verifyExternalReference(ref, modified); // false
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function verifyExternalReference(ref: ExternalReference, content: Uint8Array): boolean;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External Reference Manager
|
|
3
|
+
*
|
|
4
|
+
* Creates and verifies external resource references as specified in the CEL specification.
|
|
5
|
+
* External references point to data outside the event log (e.g., large media files)
|
|
6
|
+
* and include a cryptographic hash for content verification.
|
|
7
|
+
*
|
|
8
|
+
* @see https://w3c-ccg.github.io/cel-spec/
|
|
9
|
+
*/
|
|
10
|
+
import { computeDigestMultibase, verifyDigestMultibase } from './hash';
|
|
11
|
+
/**
|
|
12
|
+
* Creates an external reference for content.
|
|
13
|
+
*
|
|
14
|
+
* Computes a CEL-compliant digestMultibase hash from the content bytes
|
|
15
|
+
* and creates an ExternalReference with the provided metadata.
|
|
16
|
+
*
|
|
17
|
+
* @param content - The raw bytes of the content to reference
|
|
18
|
+
* @param mediaType - The MIME type of the content (e.g., "image/png")
|
|
19
|
+
* @param urls - Optional array of URLs where the content can be retrieved
|
|
20
|
+
* @returns An ExternalReference object with the computed digest
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const imageBytes = await fs.readFile('./image.png');
|
|
25
|
+
* const ref = createExternalReference(
|
|
26
|
+
* imageBytes,
|
|
27
|
+
* 'image/png',
|
|
28
|
+
* ['https://example.com/image.png']
|
|
29
|
+
* );
|
|
30
|
+
* // Returns: { digestMultibase: "uLCA...", mediaType: "image/png", url: ["https://example.com/image.png"] }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export function createExternalReference(content, mediaType, urls) {
|
|
34
|
+
// Compute the CEL-compliant hash of the content
|
|
35
|
+
const digestMultibase = computeDigestMultibase(content);
|
|
36
|
+
// Build the reference object
|
|
37
|
+
const ref = {
|
|
38
|
+
digestMultibase,
|
|
39
|
+
mediaType,
|
|
40
|
+
};
|
|
41
|
+
// Only include urls if provided and non-empty
|
|
42
|
+
if (urls && urls.length > 0) {
|
|
43
|
+
ref.url = urls;
|
|
44
|
+
}
|
|
45
|
+
return ref;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Verifies that content matches an external reference.
|
|
49
|
+
*
|
|
50
|
+
* Computes the hash of the provided content and compares it
|
|
51
|
+
* against the digestMultibase in the reference.
|
|
52
|
+
*
|
|
53
|
+
* @param ref - The external reference to verify against
|
|
54
|
+
* @param content - The raw bytes of the content to verify
|
|
55
|
+
* @returns True if the content hash matches the reference digest, false otherwise
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* const imageBytes = await fs.readFile('./image.png');
|
|
60
|
+
* const ref = createExternalReference(imageBytes, 'image/png');
|
|
61
|
+
*
|
|
62
|
+
* // Verify the content
|
|
63
|
+
* const isValid = verifyExternalReference(ref, imageBytes); // true
|
|
64
|
+
*
|
|
65
|
+
* // Modified content will fail verification
|
|
66
|
+
* const modified = new Uint8Array([...imageBytes, 0]);
|
|
67
|
+
* const isValid2 = verifyExternalReference(ref, modified); // false
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export function verifyExternalReference(ref, content) {
|
|
71
|
+
// Use the hash verification function to check content against digest
|
|
72
|
+
return verifyDigestMultibase(content, ref.digestMultibase);
|
|
73
|
+
}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OriginalsCel - Unified SDK Entry Point for CEL Operations
|
|
3
|
+
*
|
|
4
|
+
* Provides a single, simplified interface for all Cryptographic Event Log
|
|
5
|
+
* operations across all layers (peer, webvh, btco).
|
|
6
|
+
*
|
|
7
|
+
* This class delegates to the appropriate layer manager based on
|
|
8
|
+
* the configured layer and the current state of the event log.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* // Create a peer-layer asset
|
|
13
|
+
* const cel = new OriginalsCel({
|
|
14
|
+
* layer: 'peer',
|
|
15
|
+
* signer: async (data) => createEdDsaProof(data, privateKey),
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* const log = await cel.create('My Asset', [
|
|
19
|
+
* { digestMultibase: 'uXYZ...', mediaType: 'image/png' }
|
|
20
|
+
* ]);
|
|
21
|
+
*
|
|
22
|
+
* // Update the asset
|
|
23
|
+
* const updated = await cel.update(log, { description: 'Updated' });
|
|
24
|
+
*
|
|
25
|
+
* // Verify the log
|
|
26
|
+
* const result = await cel.verify(updated);
|
|
27
|
+
*
|
|
28
|
+
* // Migrate to webvh layer
|
|
29
|
+
* const migrated = await cel.migrate(updated, 'webvh');
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
import type { EventLog, ExternalReference, VerificationResult, VerifyOptions, AssetState } from './types';
|
|
33
|
+
import { type PeerCelConfig, type CelSigner } from './layers/PeerCelManager';
|
|
34
|
+
import { type WebVHCelConfig } from './layers/WebVHCelManager';
|
|
35
|
+
import { type BtcoCelConfig } from './layers/BtcoCelManager';
|
|
36
|
+
import type { WitnessService } from './witnesses/WitnessService';
|
|
37
|
+
import type { BitcoinManager } from '../bitcoin/BitcoinManager';
|
|
38
|
+
/**
|
|
39
|
+
* Supported layer types
|
|
40
|
+
*/
|
|
41
|
+
export type CelLayer = 'peer' | 'webvh' | 'btco';
|
|
42
|
+
export type { CelSigner };
|
|
43
|
+
/**
|
|
44
|
+
* Configuration options for OriginalsCel
|
|
45
|
+
*/
|
|
46
|
+
export interface OriginalsCelConfig {
|
|
47
|
+
/** Configuration for peer layer operations */
|
|
48
|
+
peer?: PeerCelConfig;
|
|
49
|
+
/** Configuration for webvh layer operations */
|
|
50
|
+
webvh?: {
|
|
51
|
+
/** The domain for the did:webvh DID (required for webvh operations) */
|
|
52
|
+
domain?: string;
|
|
53
|
+
/** Optional witness services for HTTP attestations */
|
|
54
|
+
witnesses?: WitnessService[];
|
|
55
|
+
} & WebVHCelConfig;
|
|
56
|
+
/** Configuration for btco layer operations */
|
|
57
|
+
btco?: {
|
|
58
|
+
/** BitcoinManager instance (required for btco operations) */
|
|
59
|
+
bitcoinManager?: BitcoinManager;
|
|
60
|
+
} & BtcoCelConfig;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Options for creating an OriginalsCel instance
|
|
64
|
+
*/
|
|
65
|
+
export interface OriginalsCelOptions {
|
|
66
|
+
/** The target layer for operations */
|
|
67
|
+
layer: CelLayer;
|
|
68
|
+
/** Signer function that produces DataIntegrityProofs */
|
|
69
|
+
signer: CelSigner;
|
|
70
|
+
/** Optional layer-specific configuration */
|
|
71
|
+
config?: OriginalsCelConfig;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* OriginalsCel - Unified SDK for Cryptographic Event Log operations
|
|
75
|
+
*
|
|
76
|
+
* Provides a consistent API for creating, updating, verifying, and migrating
|
|
77
|
+
* assets across all supported layers (peer, webvh, btco).
|
|
78
|
+
*/
|
|
79
|
+
export declare class OriginalsCel {
|
|
80
|
+
private layer;
|
|
81
|
+
private signer;
|
|
82
|
+
private config;
|
|
83
|
+
private _peerManager?;
|
|
84
|
+
private _webvhManager?;
|
|
85
|
+
private _btcoManager?;
|
|
86
|
+
/**
|
|
87
|
+
* Creates a new OriginalsCel instance
|
|
88
|
+
*
|
|
89
|
+
* @param options - Configuration options
|
|
90
|
+
* @param options.layer - The target layer for operations (peer, webvh, btco)
|
|
91
|
+
* @param options.signer - Function that signs data and returns a DataIntegrityProof
|
|
92
|
+
* @param options.config - Optional layer-specific configuration
|
|
93
|
+
*
|
|
94
|
+
* @throws Error if signer is not a function
|
|
95
|
+
* @throws Error if layer is invalid
|
|
96
|
+
*/
|
|
97
|
+
constructor(options: OriginalsCelOptions);
|
|
98
|
+
/**
|
|
99
|
+
* Gets or creates the PeerCelManager instance
|
|
100
|
+
*/
|
|
101
|
+
private get peerManager();
|
|
102
|
+
/**
|
|
103
|
+
* Gets or creates the WebVHCelManager instance
|
|
104
|
+
*
|
|
105
|
+
* @throws Error if domain is not configured for webvh operations
|
|
106
|
+
*/
|
|
107
|
+
private getWebVHManager;
|
|
108
|
+
/**
|
|
109
|
+
* Gets or creates the BtcoCelManager instance
|
|
110
|
+
*
|
|
111
|
+
* @throws Error if BitcoinManager is not configured for btco operations
|
|
112
|
+
*/
|
|
113
|
+
private get btcoManager();
|
|
114
|
+
/**
|
|
115
|
+
* Creates a new asset with a CEL event log
|
|
116
|
+
*
|
|
117
|
+
* This method creates an asset at the configured layer. Note that
|
|
118
|
+
* new assets can only be created at the peer layer - for other layers,
|
|
119
|
+
* create at peer first and then migrate.
|
|
120
|
+
*
|
|
121
|
+
* @param name - Human-readable name for the asset
|
|
122
|
+
* @param resources - External resources associated with the asset
|
|
123
|
+
* @returns Promise resolving to an EventLog with the create event
|
|
124
|
+
*
|
|
125
|
+
* @throws Error if signer produces invalid proof
|
|
126
|
+
* @throws Error if trying to create at non-peer layer
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* const log = await cel.create('My Asset', [
|
|
131
|
+
* createExternalReference(imageData, 'image/png')
|
|
132
|
+
* ]);
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
create(name: string, resources: ExternalReference[]): Promise<EventLog>;
|
|
136
|
+
/**
|
|
137
|
+
* Updates an existing event log by appending an update event
|
|
138
|
+
*
|
|
139
|
+
* The new event is cryptographically linked to the previous event
|
|
140
|
+
* via a hash chain (previousEvent field).
|
|
141
|
+
*
|
|
142
|
+
* @param log - The existing event log to update
|
|
143
|
+
* @param data - The update data (new metadata, resources, etc.)
|
|
144
|
+
* @returns Promise resolving to a new EventLog with the update event appended
|
|
145
|
+
*
|
|
146
|
+
* @throws Error if the log is empty or deactivated
|
|
147
|
+
* @throws Error if signer produces invalid proof
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* const updated = await cel.update(log, {
|
|
152
|
+
* description: 'Updated description',
|
|
153
|
+
* tags: ['art', 'digital']
|
|
154
|
+
* });
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
update(log: EventLog, data: unknown): Promise<EventLog>;
|
|
158
|
+
/**
|
|
159
|
+
* Verifies all proofs and hash chain integrity in an event log
|
|
160
|
+
*
|
|
161
|
+
* This method verifies:
|
|
162
|
+
* - Each event has at least one proof
|
|
163
|
+
* - Each proof is structurally valid
|
|
164
|
+
* - The hash chain is intact (each event links to previous)
|
|
165
|
+
*
|
|
166
|
+
* @param log - The event log to verify
|
|
167
|
+
* @param options - Optional verification options
|
|
168
|
+
* @returns Promise resolving to VerificationResult with detailed status
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```typescript
|
|
172
|
+
* const result = await cel.verify(log);
|
|
173
|
+
* if (result.verified) {
|
|
174
|
+
* console.log('Log is valid!');
|
|
175
|
+
* } else {
|
|
176
|
+
* console.error('Verification failed:', result.errors);
|
|
177
|
+
* }
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
verify(log: EventLog, options?: VerifyOptions): Promise<VerificationResult>;
|
|
181
|
+
/**
|
|
182
|
+
* Migrates an event log to a target layer
|
|
183
|
+
*
|
|
184
|
+
* Migration adds an update event with migration data and (optionally)
|
|
185
|
+
* witness proofs. The valid migration paths are:
|
|
186
|
+
* - peer → webvh
|
|
187
|
+
* - webvh → btco
|
|
188
|
+
* - peer → btco (requires intermediate webvh migration)
|
|
189
|
+
*
|
|
190
|
+
* @param log - The event log to migrate
|
|
191
|
+
* @param targetLayer - The layer to migrate to
|
|
192
|
+
* @param options - Optional migration options (e.g., domain for webvh)
|
|
193
|
+
* @returns Promise resolving to the migrated EventLog
|
|
194
|
+
*
|
|
195
|
+
* @throws Error if migration path is invalid
|
|
196
|
+
* @throws Error if required config is missing for target layer
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* // Migrate peer to webvh
|
|
201
|
+
* const webvhLog = await cel.migrate(peerLog, 'webvh', {
|
|
202
|
+
* domain: 'example.com'
|
|
203
|
+
* });
|
|
204
|
+
*
|
|
205
|
+
* // Migrate webvh to btco
|
|
206
|
+
* const btcoLog = await cel.migrate(webvhLog, 'btco');
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
migrate(log: EventLog, targetLayer: CelLayer, options?: {
|
|
210
|
+
domain?: string;
|
|
211
|
+
}): Promise<EventLog>;
|
|
212
|
+
/**
|
|
213
|
+
* Derives the current asset state by replaying all events in the log
|
|
214
|
+
*
|
|
215
|
+
* @param log - The event log to derive state from
|
|
216
|
+
* @returns The current AssetState
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```typescript
|
|
220
|
+
* const state = cel.getCurrentState(log);
|
|
221
|
+
* console.log(state.name); // Asset name
|
|
222
|
+
* console.log(state.layer); // Current layer
|
|
223
|
+
* console.log(state.deactivated); // Whether deactivated
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
getCurrentState(log: EventLog): AssetState;
|
|
227
|
+
/**
|
|
228
|
+
* Determines the current layer of an event log by examining its events
|
|
229
|
+
*
|
|
230
|
+
* @param log - The event log to examine
|
|
231
|
+
* @returns The current layer of the log
|
|
232
|
+
*/
|
|
233
|
+
private getCurrentLayer;
|
|
234
|
+
/**
|
|
235
|
+
* Extracts the domain from a webvh log's migration event
|
|
236
|
+
*
|
|
237
|
+
* @param log - The event log to examine
|
|
238
|
+
* @returns The domain if found, undefined otherwise
|
|
239
|
+
*/
|
|
240
|
+
private extractDomainFromLog;
|
|
241
|
+
/**
|
|
242
|
+
* Gets the configured layer for this instance
|
|
243
|
+
*/
|
|
244
|
+
get currentLayer(): CelLayer;
|
|
245
|
+
}
|