@originals/sdk 1.8.2 → 1.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/package.json +5 -6
  2. package/src/adapters/FeeOracleMock.ts +0 -9
  3. package/src/adapters/index.ts +0 -5
  4. package/src/adapters/providers/OrdHttpProvider.ts +0 -126
  5. package/src/adapters/providers/OrdMockProvider.ts +0 -101
  6. package/src/adapters/types.ts +0 -66
  7. package/src/bitcoin/BitcoinManager.ts +0 -329
  8. package/src/bitcoin/BroadcastClient.ts +0 -54
  9. package/src/bitcoin/OrdinalsClient.ts +0 -120
  10. package/src/bitcoin/PSBTBuilder.ts +0 -106
  11. package/src/bitcoin/fee-calculation.ts +0 -38
  12. package/src/bitcoin/providers/OrdNodeProvider.ts +0 -92
  13. package/src/bitcoin/providers/OrdinalsProvider.ts +0 -56
  14. package/src/bitcoin/providers/types.ts +0 -59
  15. package/src/bitcoin/transactions/commit.ts +0 -465
  16. package/src/bitcoin/transactions/index.ts +0 -13
  17. package/src/bitcoin/transfer.ts +0 -43
  18. package/src/bitcoin/utxo-selection.ts +0 -322
  19. package/src/bitcoin/utxo.ts +0 -113
  20. package/src/cel/ExternalReferenceManager.ts +0 -87
  21. package/src/cel/OriginalsCel.ts +0 -460
  22. package/src/cel/algorithms/createEventLog.ts +0 -68
  23. package/src/cel/algorithms/deactivateEventLog.ts +0 -109
  24. package/src/cel/algorithms/index.ts +0 -11
  25. package/src/cel/algorithms/updateEventLog.ts +0 -99
  26. package/src/cel/algorithms/verifyEventLog.ts +0 -306
  27. package/src/cel/algorithms/witnessEvent.ts +0 -87
  28. package/src/cel/cli/create.ts +0 -330
  29. package/src/cel/cli/index.ts +0 -383
  30. package/src/cel/cli/inspect.ts +0 -549
  31. package/src/cel/cli/migrate.ts +0 -473
  32. package/src/cel/cli/verify.ts +0 -249
  33. package/src/cel/hash.ts +0 -71
  34. package/src/cel/index.ts +0 -16
  35. package/src/cel/layers/BtcoCelManager.ts +0 -408
  36. package/src/cel/layers/PeerCelManager.ts +0 -371
  37. package/src/cel/layers/WebVHCelManager.ts +0 -361
  38. package/src/cel/layers/index.ts +0 -27
  39. package/src/cel/serialization/cbor.ts +0 -189
  40. package/src/cel/serialization/index.ts +0 -10
  41. package/src/cel/serialization/json.ts +0 -209
  42. package/src/cel/types.ts +0 -160
  43. package/src/cel/witnesses/BitcoinWitness.ts +0 -184
  44. package/src/cel/witnesses/HttpWitness.ts +0 -241
  45. package/src/cel/witnesses/WitnessService.ts +0 -51
  46. package/src/cel/witnesses/index.ts +0 -11
  47. package/src/contexts/credentials-v1.json +0 -237
  48. package/src/contexts/credentials-v2-examples.json +0 -5
  49. package/src/contexts/credentials-v2.json +0 -340
  50. package/src/contexts/credentials.json +0 -237
  51. package/src/contexts/data-integrity-v2.json +0 -81
  52. package/src/contexts/dids.json +0 -58
  53. package/src/contexts/ed255192020.json +0 -93
  54. package/src/contexts/ordinals-plus.json +0 -23
  55. package/src/contexts/originals.json +0 -22
  56. package/src/core/OriginalsSDK.ts +0 -420
  57. package/src/crypto/Multikey.ts +0 -194
  58. package/src/crypto/Signer.ts +0 -262
  59. package/src/crypto/noble-init.ts +0 -138
  60. package/src/did/BtcoDidResolver.ts +0 -231
  61. package/src/did/DIDManager.ts +0 -705
  62. package/src/did/Ed25519Verifier.ts +0 -68
  63. package/src/did/KeyManager.ts +0 -239
  64. package/src/did/WebVHManager.ts +0 -499
  65. package/src/did/createBtcoDidDocument.ts +0 -60
  66. package/src/did/providers/OrdinalsClientProviderAdapter.ts +0 -68
  67. package/src/events/EventEmitter.ts +0 -222
  68. package/src/events/index.ts +0 -19
  69. package/src/events/types.ts +0 -331
  70. package/src/examples/basic-usage.ts +0 -78
  71. package/src/examples/create-module-original.ts +0 -435
  72. package/src/examples/full-lifecycle-flow.ts +0 -514
  73. package/src/examples/run.ts +0 -60
  74. package/src/index.ts +0 -204
  75. package/src/kinds/KindRegistry.ts +0 -320
  76. package/src/kinds/index.ts +0 -74
  77. package/src/kinds/types.ts +0 -470
  78. package/src/kinds/validators/AgentValidator.ts +0 -257
  79. package/src/kinds/validators/AppValidator.ts +0 -211
  80. package/src/kinds/validators/DatasetValidator.ts +0 -242
  81. package/src/kinds/validators/DocumentValidator.ts +0 -311
  82. package/src/kinds/validators/MediaValidator.ts +0 -269
  83. package/src/kinds/validators/ModuleValidator.ts +0 -225
  84. package/src/kinds/validators/base.ts +0 -276
  85. package/src/kinds/validators/index.ts +0 -12
  86. package/src/lifecycle/BatchOperations.ts +0 -381
  87. package/src/lifecycle/LifecycleManager.ts +0 -2156
  88. package/src/lifecycle/OriginalsAsset.ts +0 -524
  89. package/src/lifecycle/ProvenanceQuery.ts +0 -280
  90. package/src/lifecycle/ResourceVersioning.ts +0 -163
  91. package/src/migration/MigrationManager.ts +0 -587
  92. package/src/migration/audit/AuditLogger.ts +0 -176
  93. package/src/migration/checkpoint/CheckpointManager.ts +0 -112
  94. package/src/migration/checkpoint/CheckpointStorage.ts +0 -101
  95. package/src/migration/index.ts +0 -33
  96. package/src/migration/operations/BaseMigration.ts +0 -126
  97. package/src/migration/operations/PeerToBtcoMigration.ts +0 -105
  98. package/src/migration/operations/PeerToWebvhMigration.ts +0 -62
  99. package/src/migration/operations/WebvhToBtcoMigration.ts +0 -105
  100. package/src/migration/rollback/RollbackManager.ts +0 -170
  101. package/src/migration/state/StateMachine.ts +0 -92
  102. package/src/migration/state/StateTracker.ts +0 -156
  103. package/src/migration/types.ts +0 -356
  104. package/src/migration/validation/BitcoinValidator.ts +0 -107
  105. package/src/migration/validation/CredentialValidator.ts +0 -62
  106. package/src/migration/validation/DIDCompatibilityValidator.ts +0 -151
  107. package/src/migration/validation/LifecycleValidator.ts +0 -64
  108. package/src/migration/validation/StorageValidator.ts +0 -79
  109. package/src/migration/validation/ValidationPipeline.ts +0 -213
  110. package/src/resources/ResourceManager.ts +0 -655
  111. package/src/resources/index.ts +0 -21
  112. package/src/resources/types.ts +0 -202
  113. package/src/storage/LocalStorageAdapter.ts +0 -64
  114. package/src/storage/MemoryStorageAdapter.ts +0 -29
  115. package/src/storage/StorageAdapter.ts +0 -25
  116. package/src/storage/index.ts +0 -3
  117. package/src/types/bitcoin.ts +0 -98
  118. package/src/types/common.ts +0 -92
  119. package/src/types/credentials.ts +0 -89
  120. package/src/types/did.ts +0 -31
  121. package/src/types/external-shims.d.ts +0 -53
  122. package/src/types/index.ts +0 -7
  123. package/src/types/network.ts +0 -178
  124. package/src/utils/EventLogger.ts +0 -298
  125. package/src/utils/Logger.ts +0 -324
  126. package/src/utils/MetricsCollector.ts +0 -358
  127. package/src/utils/bitcoin-address.ts +0 -132
  128. package/src/utils/cbor.ts +0 -31
  129. package/src/utils/encoding.ts +0 -135
  130. package/src/utils/hash.ts +0 -12
  131. package/src/utils/retry.ts +0 -46
  132. package/src/utils/satoshi-validation.ts +0 -196
  133. package/src/utils/serialization.ts +0 -102
  134. package/src/utils/telemetry.ts +0 -44
  135. package/src/utils/validation.ts +0 -123
  136. package/src/vc/CredentialManager.ts +0 -955
  137. package/src/vc/Issuer.ts +0 -105
  138. package/src/vc/Verifier.ts +0 -54
  139. package/src/vc/cryptosuites/bbs.ts +0 -253
  140. package/src/vc/cryptosuites/bbsSimple.ts +0 -21
  141. package/src/vc/cryptosuites/eddsa.ts +0 -99
  142. package/src/vc/documentLoader.ts +0 -81
  143. package/src/vc/proofs/data-integrity.ts +0 -33
  144. package/src/vc/utils/jsonld.ts +0 -18
@@ -1,176 +0,0 @@
1
- /**
2
- * AuditLogger - Creates and manages migration audit records
3
- */
4
-
5
- import { MigrationAuditRecord, IAuditLogger } from '../types';
6
- import { OriginalsConfig } from '../../types';
7
- import { sha256 } from '@noble/hashes/sha2.js';
8
- import { encodeBase64UrlMultibase } from '../../utils/encoding';
9
-
10
- export class AuditLogger implements IAuditLogger {
11
- private auditRecords: Map<string, MigrationAuditRecord[]>;
12
-
13
- constructor(private config: OriginalsConfig) {
14
- this.auditRecords = new Map();
15
- }
16
-
17
- /**
18
- * Log a migration audit record
19
- */
20
- async logMigration(record: MigrationAuditRecord): Promise<void> {
21
- // Sign the audit record
22
- const signature = await this.signAuditRecord(record);
23
- const signedRecord = { ...record, signature };
24
-
25
- // Store by source DID
26
- const existingRecords = this.auditRecords.get(record.sourceDid) || [];
27
- existingRecords.push(signedRecord);
28
- this.auditRecords.set(record.sourceDid, existingRecords);
29
-
30
- // Also store by target DID if available
31
- if (record.targetDid) {
32
- const targetRecords = this.auditRecords.get(record.targetDid) || [];
33
- targetRecords.push(signedRecord);
34
- this.auditRecords.set(record.targetDid, targetRecords);
35
- }
36
-
37
- // Persist to storage if available (append-only, never overwrite)
38
- await this.persistAuditRecord(signedRecord);
39
- }
40
-
41
- /**
42
- * Get migration history for a DID
43
- */
44
- async getMigrationHistory(did: string): Promise<MigrationAuditRecord[]> {
45
- return this.auditRecords.get(did) || [];
46
- }
47
-
48
- /**
49
- * Get system-wide migration logs with filters
50
- * Fixed dedupe logic: use signature to avoid timeline collapse
51
- */
52
- async getSystemMigrationLogs(filters: Partial<MigrationAuditRecord>): Promise<MigrationAuditRecord[]> {
53
- const allRecords: MigrationAuditRecord[] = [];
54
-
55
- // Collect all unique records (dedupe by signature to preserve timeline)
56
- const seen = new Set<string>();
57
- for (const records of this.auditRecords.values()) {
58
- for (const record of records) {
59
- const dedupKey = record.signature || `${record.migrationId}-${record.timestamp}-${record.finalState}`;
60
- if (!seen.has(dedupKey)) {
61
- seen.add(dedupKey);
62
- allRecords.push(record);
63
- }
64
- }
65
- }
66
-
67
- // Apply filters
68
- return allRecords.filter(record => {
69
- for (const [key, value] of Object.entries(filters)) {
70
- if (record[key as keyof MigrationAuditRecord] !== value) {
71
- return false;
72
- }
73
- }
74
- return true;
75
- });
76
- }
77
-
78
- /**
79
- * Sign an audit record for integrity
80
- *
81
- * TODO: Replace with real digital signatures (Ed25519/ECDSA)
82
- * Current implementation uses SHA256 hash for integrity verification.
83
- * In production, use config.signer.sign(bytes)/verify(bytes, signature) with:
84
- * - Ed25519 for performance
85
- * - ECDSA (secp256k1/secp256r1) for compatibility
86
- *
87
- * Example:
88
- * const signer = config.signer; // Ed25519Signer or ES256KSigner
89
- * const signature = await signer.sign(Buffer.from(canonical), privateKey);
90
- * return encodeBase64UrlMultibase(signature);
91
- */
92
- private async signAuditRecord(record: MigrationAuditRecord): Promise<string> {
93
- // Create a canonical representation of the record (without signature)
94
- const { signature, ...recordWithoutSig } = record as any;
95
- const canonical = JSON.stringify(recordWithoutSig);
96
-
97
- // Hash the canonical representation (placeholder for real signature)
98
- const hash = sha256(Buffer.from(canonical, 'utf8'));
99
-
100
- // Encode as multibase for storage
101
- return encodeBase64UrlMultibase(Buffer.from(hash));
102
- }
103
-
104
- /**
105
- * Verify an audit record signature
106
- */
107
- async verifyAuditRecord(record: MigrationAuditRecord): Promise<boolean> {
108
- if (!record.signature) {
109
- return false;
110
- }
111
-
112
- const expectedSignature = await this.signAuditRecord(record);
113
- return expectedSignature === record.signature;
114
- }
115
-
116
- /**
117
- * Persist audit record to storage (append-only, never overwrite)
118
- * Updated key design: audit/migrations/{migrationId}/{timestamp}-{finalState}.json
119
- */
120
- private async persistAuditRecord(record: MigrationAuditRecord): Promise<void> {
121
- const storageAdapter = (this.config as any).storageAdapter;
122
- if (storageAdapter && typeof storageAdapter.put === 'function') {
123
- try {
124
- const data = JSON.stringify(record);
125
- // Use unique key to prevent overwriting: migrationId/timestamp-state
126
- const key = `audit/migrations/${record.migrationId}/${record.timestamp}-${record.finalState}.json`;
127
- await storageAdapter.put(key, Buffer.from(data), { contentType: 'application/json' });
128
- } catch (error) {
129
- console.error('Failed to persist audit record:', error);
130
- // Continue - in-memory record is still available
131
- }
132
- }
133
- }
134
-
135
- /**
136
- * Load audit records from storage
137
- */
138
- async loadAuditRecords(did: string): Promise<void> {
139
- const storageAdapter = (this.config as any).storageAdapter;
140
- if (!storageAdapter || typeof storageAdapter.list !== 'function') {
141
- return;
142
- }
143
-
144
- try {
145
- // List all audit records
146
- const files = await storageAdapter.list('audit/migrations/');
147
-
148
- for (const file of files) {
149
- try {
150
- const data = await storageAdapter.get(file);
151
- if (data) {
152
- const record: MigrationAuditRecord = JSON.parse(data.toString());
153
-
154
- // Add to in-memory store if it matches the DID
155
- if (record.sourceDid === did || record.targetDid === did) {
156
- const existingRecords = this.auditRecords.get(did) || [];
157
- // Use signature for dedupe to prevent timeline collapse
158
- const dedupKey = record.signature || `${record.migrationId}-${record.timestamp}`;
159
- if (!existingRecords.find(r => {
160
- const rKey = r.signature || `${r.migrationId}-${r.timestamp}`;
161
- return rKey === dedupKey;
162
- })) {
163
- existingRecords.push(record);
164
- this.auditRecords.set(did, existingRecords);
165
- }
166
- }
167
- }
168
- } catch (error) {
169
- // Skip invalid audit records
170
- }
171
- }
172
- } catch (error) {
173
- console.error('Failed to load audit records:', error);
174
- }
175
- }
176
- }
@@ -1,112 +0,0 @@
1
- /**
2
- * CheckpointManager - Creates and manages migration checkpoints for rollback
3
- */
4
-
5
- import { v4 as uuidv4 } from 'uuid';
6
- import {
7
- MigrationOptions,
8
- MigrationCheckpoint,
9
- ICheckpointManager
10
- } from '../types';
11
- import { OriginalsConfig } from '../../types';
12
- import { DIDManager } from '../../did/DIDManager';
13
- import { CredentialManager } from '../../vc/CredentialManager';
14
- import { CheckpointStorage } from './CheckpointStorage';
15
-
16
- export class CheckpointManager implements ICheckpointManager {
17
- private storage: CheckpointStorage;
18
-
19
- constructor(
20
- private config: OriginalsConfig,
21
- private didManager: DIDManager,
22
- private credentialManager: CredentialManager
23
- ) {
24
- this.storage = new CheckpointStorage(config);
25
- }
26
-
27
- /**
28
- * Create a checkpoint before migration
29
- */
30
- async createCheckpoint(migrationId: string, options: MigrationOptions): Promise<MigrationCheckpoint> {
31
- try {
32
- const checkpointId = `chk_${uuidv4()}`;
33
-
34
- // Resolve source DID document
35
- const didDocument = await this.didManager.resolveDID(options.sourceDid);
36
- if (!didDocument) {
37
- throw new Error(`Could not resolve source DID: ${options.sourceDid}`);
38
- }
39
-
40
- // Extract source layer
41
- const sourceLayer = this.extractLayer(options.sourceDid);
42
- if (!sourceLayer) {
43
- throw new Error(`Invalid source DID format: ${options.sourceDid}`);
44
- }
45
-
46
- // Create checkpoint
47
- const checkpoint: MigrationCheckpoint = {
48
- checkpointId,
49
- migrationId,
50
- timestamp: Date.now(),
51
- sourceDid: options.sourceDid,
52
- sourceLayer,
53
- didDocument,
54
- credentials: [], // Would be populated by querying credential store
55
- storageReferences: {}, // Would be populated by querying storage adapter
56
- lifecycleState: {}, // Would be populated by querying lifecycle manager
57
- ownershipProofs: [], // Would be populated if available
58
- metadata: options.metadata || {}
59
- };
60
-
61
- // Store checkpoint
62
- await this.storage.save(checkpoint);
63
-
64
- return checkpoint;
65
- } catch (error) {
66
- throw new Error(`Failed to create checkpoint: ${error instanceof Error ? error.message : String(error)}`);
67
- }
68
- }
69
-
70
- /**
71
- * Retrieve a checkpoint by ID
72
- */
73
- async getCheckpoint(checkpointId: string): Promise<MigrationCheckpoint | null> {
74
- try {
75
- return await this.storage.get(checkpointId);
76
- } catch (error) {
77
- console.error(`Error retrieving checkpoint ${checkpointId}:`, error);
78
- return null;
79
- }
80
- }
81
-
82
- /**
83
- * Delete a checkpoint (after successful migration or cleanup)
84
- */
85
- async deleteCheckpoint(checkpointId: string): Promise<void> {
86
- try {
87
- await this.storage.delete(checkpointId);
88
- } catch (error) {
89
- console.error(`Error deleting checkpoint ${checkpointId}:`, error);
90
- // Don't throw - deletion failures shouldn't break migrations
91
- }
92
- }
93
-
94
- /**
95
- * Clean up old checkpoints (older than 24 hours for successful migrations)
96
- */
97
- async cleanupOldCheckpoints(): Promise<void> {
98
- try {
99
- const cutoffTime = Date.now() - (24 * 60 * 60 * 1000); // 24 hours
100
- await this.storage.deleteOlderThan(cutoffTime);
101
- } catch (error) {
102
- console.error('Error cleaning up old checkpoints:', error);
103
- }
104
- }
105
-
106
- private extractLayer(did: string): 'peer' | 'webvh' | 'btco' | null {
107
- if (did.startsWith('did:peer:')) return 'peer';
108
- if (did.startsWith('did:webvh:')) return 'webvh';
109
- if (did.startsWith('did:btco:')) return 'btco';
110
- return null;
111
- }
112
- }
@@ -1,101 +0,0 @@
1
- /**
2
- * CheckpointStorage - Persists checkpoints to storage
3
- */
4
-
5
- import { MigrationCheckpoint } from '../types';
6
- import { OriginalsConfig } from '../../types';
7
-
8
- export class CheckpointStorage {
9
- private checkpoints: Map<string, MigrationCheckpoint>;
10
-
11
- constructor(private config: OriginalsConfig) {
12
- this.checkpoints = new Map();
13
- }
14
-
15
- /**
16
- * Save a checkpoint
17
- */
18
- async save(checkpoint: MigrationCheckpoint): Promise<void> {
19
- if (!checkpoint.checkpointId) {
20
- throw new Error('Checkpoint must have an ID');
21
- }
22
- this.checkpoints.set(checkpoint.checkpointId, checkpoint);
23
-
24
- // Optionally persist to configured storage adapter
25
- const storageAdapter = (this.config as any).storageAdapter;
26
- if (storageAdapter && typeof storageAdapter.put === 'function') {
27
- try {
28
- const data = JSON.stringify(checkpoint);
29
- const key = `checkpoints/${checkpoint.checkpointId}.json`;
30
- await storageAdapter.put(key, Buffer.from(data), { contentType: 'application/json' });
31
- } catch (error) {
32
- console.error('Failed to persist checkpoint to storage:', error);
33
- // Continue - in-memory checkpoint is still available
34
- }
35
- }
36
- }
37
-
38
- /**
39
- * Retrieve a checkpoint
40
- */
41
- async get(checkpointId: string): Promise<MigrationCheckpoint | null> {
42
- // Try in-memory first
43
- const memoryCheckpoint = this.checkpoints.get(checkpointId);
44
- if (memoryCheckpoint) {
45
- return memoryCheckpoint;
46
- }
47
-
48
- // Try loading from storage adapter
49
- const storageAdapter = (this.config as any).storageAdapter;
50
- if (storageAdapter && typeof storageAdapter.get === 'function') {
51
- try {
52
- const key = `checkpoints/${checkpointId}.json`;
53
- const data = await storageAdapter.get(key);
54
- if (data) {
55
- const checkpoint = JSON.parse(data.toString());
56
- this.checkpoints.set(checkpointId, checkpoint);
57
- return checkpoint;
58
- }
59
- } catch (error) {
60
- // Checkpoint not found in storage
61
- }
62
- }
63
-
64
- return null;
65
- }
66
-
67
- /**
68
- * Delete a checkpoint
69
- */
70
- async delete(checkpointId: string): Promise<void> {
71
- this.checkpoints.delete(checkpointId);
72
-
73
- // Also delete from storage adapter
74
- const storageAdapter = (this.config as any).storageAdapter;
75
- if (storageAdapter && typeof storageAdapter.delete === 'function') {
76
- try {
77
- const key = `checkpoints/${checkpointId}.json`;
78
- await storageAdapter.delete(key);
79
- } catch (error) {
80
- // Ignore deletion errors
81
- }
82
- }
83
- }
84
-
85
- /**
86
- * Delete checkpoints older than specified timestamp
87
- */
88
- async deleteOlderThan(cutoffTime: number): Promise<void> {
89
- const toDelete: string[] = [];
90
-
91
- for (const [id, checkpoint] of this.checkpoints.entries()) {
92
- if (checkpoint.timestamp < cutoffTime) {
93
- toDelete.push(id);
94
- }
95
- }
96
-
97
- for (const id of toDelete) {
98
- await this.delete(id);
99
- }
100
- }
101
- }
@@ -1,33 +0,0 @@
1
- /**
2
- * Migration module exports
3
- * Provides DID layer migration capabilities with validation, checkpoints, and rollbacks
4
- */
5
-
6
- export { MigrationManager } from './MigrationManager';
7
- export * from './types';
8
-
9
- // Validators
10
- export { ValidationPipeline } from './validation/ValidationPipeline';
11
- export { DIDCompatibilityValidator } from './validation/DIDCompatibilityValidator';
12
- export { CredentialValidator } from './validation/CredentialValidator';
13
- export { StorageValidator } from './validation/StorageValidator';
14
- export { LifecycleValidator } from './validation/LifecycleValidator';
15
- export { BitcoinValidator } from './validation/BitcoinValidator';
16
-
17
- // Checkpoint and Rollback
18
- export { CheckpointManager } from './checkpoint/CheckpointManager';
19
- export { CheckpointStorage } from './checkpoint/CheckpointStorage';
20
- export { RollbackManager } from './rollback/RollbackManager';
21
-
22
- // State Management
23
- export { StateTracker } from './state/StateTracker';
24
- export { StateMachine } from './state/StateMachine';
25
-
26
- // Audit
27
- export { AuditLogger } from './audit/AuditLogger';
28
-
29
- // Operations
30
- export { BaseMigration } from './operations/BaseMigration';
31
- export { PeerToWebvhMigration } from './operations/PeerToWebvhMigration';
32
- export { WebvhToBtcoMigration } from './operations/WebvhToBtcoMigration';
33
- export { PeerToBtcoMigration } from './operations/PeerToBtcoMigration';
@@ -1,126 +0,0 @@
1
- /**
2
- * BaseMigration - Base class for all migration operations
3
- */
4
-
5
- import {
6
- MigrationOptions,
7
- MigrationResult,
8
- MigrationError,
9
- MigrationErrorType,
10
- MigrationStateEnum,
11
- CostEstimate
12
- } from '../types';
13
- import { OriginalsConfig, DIDDocument } from '../../types';
14
- import { DIDManager } from '../../did/DIDManager';
15
- import { CredentialManager } from '../../vc/CredentialManager';
16
- import { StateTracker } from '../state/StateTracker';
17
- import { EventEmitter } from '../../events/EventEmitter';
18
-
19
- export abstract class BaseMigration {
20
- protected eventEmitter: EventEmitter;
21
-
22
- constructor(
23
- protected config: OriginalsConfig,
24
- protected didManager: DIDManager,
25
- protected credentialManager: CredentialManager,
26
- protected stateTracker: StateTracker
27
- ) {
28
- this.eventEmitter = new EventEmitter();
29
- }
30
-
31
- /**
32
- * Execute the migration (to be implemented by subclasses)
33
- */
34
- abstract executeMigration(
35
- options: MigrationOptions,
36
- migrationId: string
37
- ): Promise<{ targetDid: string; didDocument: DIDDocument }>;
38
-
39
- /**
40
- * Get estimated cost (to be implemented by subclasses)
41
- */
42
- abstract estimateCost(options: MigrationOptions): Promise<CostEstimate>;
43
-
44
- /**
45
- * Emit migration event
46
- */
47
- protected async emitEvent(type: string, data: any): Promise<void> {
48
- try {
49
- await this.eventEmitter.emit({
50
- type,
51
- timestamp: new Date().toISOString(),
52
- ...data
53
- });
54
- } catch (error) {
55
- console.error(`Error emitting event ${type}:`, error);
56
- }
57
- }
58
-
59
- /**
60
- * Create migration error
61
- */
62
- protected createError(
63
- type: MigrationErrorType,
64
- code: string,
65
- message: string,
66
- migrationId?: string,
67
- details?: any
68
- ): MigrationError {
69
- return {
70
- type,
71
- code,
72
- message,
73
- technicalDetails: details ? JSON.stringify(details) : undefined,
74
- migrationId,
75
- timestamp: Date.now()
76
- };
77
- }
78
-
79
- /**
80
- * Update migration state with error handling
81
- */
82
- protected async updateStateWithRetry(
83
- migrationId: string,
84
- updates: any,
85
- maxRetries: number = 3
86
- ): Promise<void> {
87
- let lastError: Error | null = null;
88
-
89
- for (let attempt = 0; attempt < maxRetries; attempt++) {
90
- try {
91
- await this.stateTracker.updateState(migrationId, updates);
92
- return;
93
- } catch (error) {
94
- lastError = error instanceof Error ? error : new Error(String(error));
95
-
96
- if (attempt < maxRetries - 1) {
97
- // Exponential backoff: 100ms, 200ms, 400ms
98
- await new Promise(resolve => setTimeout(resolve, 100 * Math.pow(2, attempt)));
99
- }
100
- }
101
- }
102
-
103
- throw lastError || new Error('Failed to update state after retries');
104
- }
105
-
106
- /**
107
- * Resolve source DID document
108
- */
109
- protected async resolveSourceDid(sourceDid: string): Promise<DIDDocument> {
110
- const didDocument = await this.didManager.resolveDID(sourceDid);
111
- if (!didDocument) {
112
- throw new Error(`Could not resolve source DID: ${sourceDid}`);
113
- }
114
- return didDocument;
115
- }
116
-
117
- /**
118
- * Extract layer from DID
119
- */
120
- protected extractLayer(did: string): 'peer' | 'webvh' | 'btco' {
121
- if (did.startsWith('did:peer:')) return 'peer';
122
- if (did.startsWith('did:webvh:')) return 'webvh';
123
- if (did.startsWith('did:btco:')) return 'btco';
124
- throw new Error(`Unsupported DID method: ${did}`);
125
- }
126
- }
@@ -1,105 +0,0 @@
1
- /**
2
- * PeerToBtcoMigration - Handles direct migration from did:peer to did:btco
3
- */
4
-
5
- import {
6
- MigrationOptions,
7
- CostEstimate,
8
- MigrationStateEnum
9
- } from '../types';
10
- import { DIDDocument, OriginalsConfig } from '../../types';
11
- import { BaseMigration } from './BaseMigration';
12
- import { BitcoinManager } from '../../bitcoin/BitcoinManager';
13
- import { DIDManager } from '../../did/DIDManager';
14
- import { CredentialManager } from '../../vc/CredentialManager';
15
- import { StateTracker } from '../state/StateTracker';
16
-
17
- export class PeerToBtcoMigration extends BaseMigration {
18
- private bitcoinManager: BitcoinManager;
19
-
20
- constructor(
21
- config: OriginalsConfig,
22
- didManager: DIDManager,
23
- credentialManager: CredentialManager,
24
- stateTracker: StateTracker,
25
- bitcoinManager: BitcoinManager
26
- ) {
27
- super(config, didManager, credentialManager, stateTracker);
28
- this.bitcoinManager = bitcoinManager;
29
- }
30
-
31
- /**
32
- * Execute peer → btco migration (direct, skipping webvh layer)
33
- */
34
- async executeMigration(
35
- options: MigrationOptions,
36
- migrationId: string
37
- ): Promise<{ targetDid: string; didDocument: DIDDocument }> {
38
- // Resolve source DID
39
- const sourceDid = await this.resolveSourceDid(options.sourceDid);
40
-
41
- await this.updateStateWithRetry(migrationId, {
42
- state: MigrationStateEnum.IN_PROGRESS,
43
- currentOperation: 'Creating Bitcoin inscription',
44
- progress: 30
45
- });
46
-
47
- // Create Bitcoin inscription with DID document
48
- const manifest = {
49
- didDocument: sourceDid,
50
- migrationId,
51
- timestamp: new Date().toISOString()
52
- };
53
- const payload = Buffer.from(JSON.stringify(manifest));
54
-
55
- await this.updateStateWithRetry(migrationId, {
56
- state: MigrationStateEnum.ANCHORING,
57
- currentOperation: 'Anchoring to Bitcoin',
58
- progress: 50
59
- });
60
-
61
- const inscription = await this.bitcoinManager.inscribeData(
62
- payload,
63
- 'application/json',
64
- options.feeRate
65
- );
66
-
67
- // Use satoshi identifier or inscription ID
68
- const satoshiId = inscription.satoshi || inscription.inscriptionId.split('i')[0];
69
-
70
- await this.updateStateWithRetry(migrationId, {
71
- currentOperation: 'Creating btco DID document',
72
- progress: 80
73
- });
74
-
75
- // Migrate DID document to btco
76
- const migratedDoc = await this.didManager.migrateToDIDBTCO(sourceDid, satoshiId);
77
-
78
- await this.updateStateWithRetry(migrationId, {
79
- currentOperation: 'Migration completed',
80
- progress: 100,
81
- targetDid: migratedDoc.id
82
- });
83
-
84
- return {
85
- targetDid: migratedDoc.id,
86
- didDocument: migratedDoc
87
- };
88
- }
89
-
90
- /**
91
- * Estimate cost for peer → btco migration
92
- */
93
- async estimateCost(options: MigrationOptions): Promise<CostEstimate> {
94
- const feeRate = options.feeRate || 10; // default 10 sat/vB
95
- const estimatedSize = 1024; // ~1KB for typical DID document
96
- const networkFees = estimatedSize * feeRate;
97
-
98
- return {
99
- storageCost: 0,
100
- networkFees,
101
- totalCost: networkFees,
102
- currency: 'sats'
103
- };
104
- }
105
- }