@originals/sdk 1.4.3 → 1.4.5

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 (222) hide show
  1. package/dist/adapters/FeeOracleMock.d.ts +6 -0
  2. package/dist/adapters/FeeOracleMock.js +8 -0
  3. package/dist/adapters/index.d.ts +4 -0
  4. package/dist/adapters/index.js +4 -0
  5. package/dist/adapters/providers/OrdHttpProvider.d.ts +56 -0
  6. package/dist/adapters/providers/OrdHttpProvider.js +110 -0
  7. package/dist/adapters/providers/OrdMockProvider.d.ts +70 -0
  8. package/dist/adapters/providers/OrdMockProvider.js +75 -0
  9. package/dist/adapters/types.d.ts +71 -0
  10. package/dist/adapters/types.js +1 -0
  11. package/dist/bitcoin/BitcoinManager.d.ts +15 -0
  12. package/dist/bitcoin/BitcoinManager.js +262 -0
  13. package/dist/bitcoin/BroadcastClient.d.ts +30 -0
  14. package/dist/bitcoin/BroadcastClient.js +35 -0
  15. package/dist/bitcoin/OrdinalsClient.d.ts +21 -0
  16. package/dist/bitcoin/OrdinalsClient.js +105 -0
  17. package/dist/bitcoin/PSBTBuilder.d.ts +24 -0
  18. package/dist/bitcoin/PSBTBuilder.js +80 -0
  19. package/dist/bitcoin/fee-calculation.d.ts +14 -0
  20. package/dist/bitcoin/fee-calculation.js +31 -0
  21. package/dist/bitcoin/providers/OrdNodeProvider.d.ts +38 -0
  22. package/dist/bitcoin/providers/OrdNodeProvider.js +67 -0
  23. package/dist/bitcoin/providers/OrdinalsProvider.d.ts +33 -0
  24. package/dist/bitcoin/providers/OrdinalsProvider.js +50 -0
  25. package/dist/bitcoin/providers/types.d.ts +63 -0
  26. package/dist/bitcoin/providers/types.js +1 -0
  27. package/dist/bitcoin/transactions/commit.d.ts +89 -0
  28. package/dist/bitcoin/transactions/commit.js +311 -0
  29. package/dist/bitcoin/transactions/index.d.ts +7 -0
  30. package/dist/bitcoin/transactions/index.js +8 -0
  31. package/dist/bitcoin/transfer.d.ts +9 -0
  32. package/dist/bitcoin/transfer.js +26 -0
  33. package/dist/bitcoin/utxo-selection.d.ts +78 -0
  34. package/dist/bitcoin/utxo-selection.js +237 -0
  35. package/dist/bitcoin/utxo.d.ts +26 -0
  36. package/dist/bitcoin/utxo.js +78 -0
  37. package/dist/contexts/credentials-v1.json +195 -0
  38. package/dist/contexts/credentials-v2-examples.json +5 -0
  39. package/dist/contexts/credentials-v2.json +301 -0
  40. package/dist/contexts/credentials.json +195 -0
  41. package/dist/contexts/data-integrity-v2.json +81 -0
  42. package/dist/contexts/dids.json +57 -0
  43. package/dist/contexts/ed255192020.json +93 -0
  44. package/dist/contexts/ordinals-plus.json +23 -0
  45. package/dist/contexts/originals.json +22 -0
  46. package/dist/core/OriginalsSDK.d.ts +158 -0
  47. package/dist/core/OriginalsSDK.js +274 -0
  48. package/dist/crypto/Multikey.d.ts +30 -0
  49. package/dist/crypto/Multikey.js +149 -0
  50. package/dist/crypto/Signer.d.ts +21 -0
  51. package/dist/crypto/Signer.js +196 -0
  52. package/dist/crypto/noble-init.d.ts +18 -0
  53. package/dist/crypto/noble-init.js +106 -0
  54. package/dist/did/BtcoDidResolver.d.ts +57 -0
  55. package/dist/did/BtcoDidResolver.js +166 -0
  56. package/dist/did/DIDManager.d.ts +101 -0
  57. package/dist/did/DIDManager.js +493 -0
  58. package/dist/did/Ed25519Verifier.d.ts +30 -0
  59. package/dist/did/Ed25519Verifier.js +59 -0
  60. package/dist/did/KeyManager.d.ts +17 -0
  61. package/dist/did/KeyManager.js +207 -0
  62. package/dist/did/WebVHManager.d.ts +100 -0
  63. package/dist/did/WebVHManager.js +312 -0
  64. package/dist/did/createBtcoDidDocument.d.ts +10 -0
  65. package/dist/did/createBtcoDidDocument.js +42 -0
  66. package/dist/did/providers/OrdinalsClientProviderAdapter.d.ts +23 -0
  67. package/dist/did/providers/OrdinalsClientProviderAdapter.js +51 -0
  68. package/dist/events/EventEmitter.d.ts +115 -0
  69. package/dist/events/EventEmitter.js +198 -0
  70. package/dist/events/index.d.ts +7 -0
  71. package/dist/events/index.js +6 -0
  72. package/dist/events/types.d.ts +286 -0
  73. package/dist/events/types.js +9 -0
  74. package/dist/examples/basic-usage.d.ts +3 -0
  75. package/dist/examples/basic-usage.js +62 -0
  76. package/dist/examples/create-module-original.d.ts +32 -0
  77. package/dist/examples/create-module-original.js +376 -0
  78. package/dist/examples/full-lifecycle-flow.d.ts +56 -0
  79. package/dist/examples/full-lifecycle-flow.js +419 -0
  80. package/dist/examples/run.d.ts +12 -0
  81. package/dist/examples/run.js +51 -0
  82. package/dist/index.d.ts +43 -0
  83. package/dist/index.js +52 -0
  84. package/dist/kinds/KindRegistry.d.ts +76 -0
  85. package/dist/kinds/KindRegistry.js +216 -0
  86. package/dist/kinds/index.d.ts +33 -0
  87. package/dist/kinds/index.js +36 -0
  88. package/dist/kinds/types.d.ts +363 -0
  89. package/dist/kinds/types.js +25 -0
  90. package/dist/kinds/validators/AgentValidator.d.ts +14 -0
  91. package/dist/kinds/validators/AgentValidator.js +155 -0
  92. package/dist/kinds/validators/AppValidator.d.ts +14 -0
  93. package/dist/kinds/validators/AppValidator.js +135 -0
  94. package/dist/kinds/validators/DatasetValidator.d.ts +14 -0
  95. package/dist/kinds/validators/DatasetValidator.js +148 -0
  96. package/dist/kinds/validators/DocumentValidator.d.ts +14 -0
  97. package/dist/kinds/validators/DocumentValidator.js +180 -0
  98. package/dist/kinds/validators/MediaValidator.d.ts +14 -0
  99. package/dist/kinds/validators/MediaValidator.js +172 -0
  100. package/dist/kinds/validators/ModuleValidator.d.ts +14 -0
  101. package/dist/kinds/validators/ModuleValidator.js +140 -0
  102. package/dist/kinds/validators/base.d.ts +96 -0
  103. package/dist/kinds/validators/base.js +218 -0
  104. package/dist/kinds/validators/index.d.ts +10 -0
  105. package/dist/kinds/validators/index.js +10 -0
  106. package/dist/lifecycle/BatchOperations.d.ts +147 -0
  107. package/dist/lifecycle/BatchOperations.js +251 -0
  108. package/dist/lifecycle/LifecycleManager.d.ts +362 -0
  109. package/dist/lifecycle/LifecycleManager.js +1692 -0
  110. package/dist/lifecycle/OriginalsAsset.d.ts +164 -0
  111. package/dist/lifecycle/OriginalsAsset.js +380 -0
  112. package/dist/lifecycle/ProvenanceQuery.d.ts +126 -0
  113. package/dist/lifecycle/ProvenanceQuery.js +220 -0
  114. package/dist/lifecycle/ResourceVersioning.d.ts +73 -0
  115. package/dist/lifecycle/ResourceVersioning.js +127 -0
  116. package/dist/migration/MigrationManager.d.ts +86 -0
  117. package/dist/migration/MigrationManager.js +412 -0
  118. package/dist/migration/audit/AuditLogger.d.ts +51 -0
  119. package/dist/migration/audit/AuditLogger.js +156 -0
  120. package/dist/migration/checkpoint/CheckpointManager.d.ts +31 -0
  121. package/dist/migration/checkpoint/CheckpointManager.js +96 -0
  122. package/dist/migration/checkpoint/CheckpointStorage.d.ts +26 -0
  123. package/dist/migration/checkpoint/CheckpointStorage.js +89 -0
  124. package/dist/migration/index.d.ts +22 -0
  125. package/dist/migration/index.js +27 -0
  126. package/dist/migration/operations/BaseMigration.d.ts +48 -0
  127. package/dist/migration/operations/BaseMigration.js +83 -0
  128. package/dist/migration/operations/PeerToBtcoMigration.d.ts +25 -0
  129. package/dist/migration/operations/PeerToBtcoMigration.js +67 -0
  130. package/dist/migration/operations/PeerToWebvhMigration.d.ts +19 -0
  131. package/dist/migration/operations/PeerToWebvhMigration.js +46 -0
  132. package/dist/migration/operations/WebvhToBtcoMigration.d.ts +25 -0
  133. package/dist/migration/operations/WebvhToBtcoMigration.js +67 -0
  134. package/dist/migration/rollback/RollbackManager.d.ts +29 -0
  135. package/dist/migration/rollback/RollbackManager.js +146 -0
  136. package/dist/migration/state/StateMachine.d.ts +25 -0
  137. package/dist/migration/state/StateMachine.js +76 -0
  138. package/dist/migration/state/StateTracker.d.ts +36 -0
  139. package/dist/migration/state/StateTracker.js +123 -0
  140. package/dist/migration/types.d.ts +306 -0
  141. package/dist/migration/types.js +33 -0
  142. package/dist/migration/validation/BitcoinValidator.d.ts +13 -0
  143. package/dist/migration/validation/BitcoinValidator.js +83 -0
  144. package/dist/migration/validation/CredentialValidator.d.ts +13 -0
  145. package/dist/migration/validation/CredentialValidator.js +46 -0
  146. package/dist/migration/validation/DIDCompatibilityValidator.d.ts +16 -0
  147. package/dist/migration/validation/DIDCompatibilityValidator.js +127 -0
  148. package/dist/migration/validation/LifecycleValidator.d.ts +10 -0
  149. package/dist/migration/validation/LifecycleValidator.js +52 -0
  150. package/dist/migration/validation/StorageValidator.d.ts +10 -0
  151. package/dist/migration/validation/StorageValidator.js +65 -0
  152. package/dist/migration/validation/ValidationPipeline.d.ts +29 -0
  153. package/dist/migration/validation/ValidationPipeline.js +180 -0
  154. package/dist/resources/ResourceManager.d.ts +231 -0
  155. package/dist/resources/ResourceManager.js +573 -0
  156. package/dist/resources/index.d.ts +11 -0
  157. package/dist/resources/index.js +10 -0
  158. package/dist/resources/types.d.ts +93 -0
  159. package/dist/resources/types.js +80 -0
  160. package/dist/storage/LocalStorageAdapter.d.ts +11 -0
  161. package/dist/storage/LocalStorageAdapter.js +53 -0
  162. package/dist/storage/MemoryStorageAdapter.d.ts +6 -0
  163. package/dist/storage/MemoryStorageAdapter.js +21 -0
  164. package/dist/storage/StorageAdapter.d.ts +16 -0
  165. package/dist/storage/StorageAdapter.js +1 -0
  166. package/dist/storage/index.d.ts +2 -0
  167. package/dist/storage/index.js +2 -0
  168. package/dist/types/bitcoin.d.ts +84 -0
  169. package/dist/types/bitcoin.js +1 -0
  170. package/dist/types/common.d.ts +82 -0
  171. package/dist/types/common.js +1 -0
  172. package/dist/types/credentials.d.ts +75 -0
  173. package/dist/types/credentials.js +1 -0
  174. package/dist/types/did.d.ts +26 -0
  175. package/dist/types/did.js +1 -0
  176. package/dist/types/index.d.ts +5 -0
  177. package/dist/types/index.js +5 -0
  178. package/dist/types/network.d.ts +78 -0
  179. package/dist/types/network.js +145 -0
  180. package/dist/utils/EventLogger.d.ts +71 -0
  181. package/dist/utils/EventLogger.js +232 -0
  182. package/dist/utils/Logger.d.ts +106 -0
  183. package/dist/utils/Logger.js +257 -0
  184. package/dist/utils/MetricsCollector.d.ts +110 -0
  185. package/dist/utils/MetricsCollector.js +264 -0
  186. package/dist/utils/bitcoin-address.d.ts +38 -0
  187. package/dist/utils/bitcoin-address.js +113 -0
  188. package/dist/utils/cbor.d.ts +2 -0
  189. package/dist/utils/cbor.js +9 -0
  190. package/dist/utils/encoding.d.ts +37 -0
  191. package/dist/utils/encoding.js +120 -0
  192. package/dist/utils/hash.d.ts +1 -0
  193. package/dist/utils/hash.js +5 -0
  194. package/dist/utils/retry.d.ts +10 -0
  195. package/dist/utils/retry.js +35 -0
  196. package/dist/utils/satoshi-validation.d.ts +60 -0
  197. package/dist/utils/satoshi-validation.js +156 -0
  198. package/dist/utils/serialization.d.ts +14 -0
  199. package/dist/utils/serialization.js +76 -0
  200. package/dist/utils/telemetry.d.ts +17 -0
  201. package/dist/utils/telemetry.js +24 -0
  202. package/dist/utils/validation.d.ts +5 -0
  203. package/dist/utils/validation.js +98 -0
  204. package/dist/vc/CredentialManager.d.ts +329 -0
  205. package/dist/vc/CredentialManager.js +615 -0
  206. package/dist/vc/Issuer.d.ts +27 -0
  207. package/dist/vc/Issuer.js +70 -0
  208. package/dist/vc/Verifier.d.ts +16 -0
  209. package/dist/vc/Verifier.js +50 -0
  210. package/dist/vc/cryptosuites/bbs.d.ts +44 -0
  211. package/dist/vc/cryptosuites/bbs.js +213 -0
  212. package/dist/vc/cryptosuites/bbsSimple.d.ts +9 -0
  213. package/dist/vc/cryptosuites/bbsSimple.js +12 -0
  214. package/dist/vc/cryptosuites/eddsa.d.ts +30 -0
  215. package/dist/vc/cryptosuites/eddsa.js +81 -0
  216. package/dist/vc/documentLoader.d.ts +16 -0
  217. package/dist/vc/documentLoader.js +59 -0
  218. package/dist/vc/proofs/data-integrity.d.ts +21 -0
  219. package/dist/vc/proofs/data-integrity.js +15 -0
  220. package/dist/vc/utils/jsonld.d.ts +2 -0
  221. package/dist/vc/utils/jsonld.js +15 -0
  222. package/package.json +2 -1
@@ -0,0 +1,145 @@
1
+ /**
2
+ * WebVH Network Configuration
3
+ *
4
+ * Defines the three deployment networks for the Originals Protocol:
5
+ * - magby: Development network (patch versions) → Bitcoin regtest
6
+ * - cleffa: Staging network (minor versions) → Bitcoin signet
7
+ * - pichu: Production network (major versions) → Bitcoin mainnet
8
+ */
9
+ /**
10
+ * Network configurations for the Originals Protocol WebVH deployments
11
+ */
12
+ export const WEBVH_NETWORKS = {
13
+ magby: {
14
+ name: 'magby',
15
+ domain: 'magby.originals.build',
16
+ stability: 'patch',
17
+ description: 'Development network - accepts all patch versions (most unstable)',
18
+ contextUrl: 'https://magby.originals.build/context',
19
+ bitcoinNetwork: 'regtest', // Development → regtest
20
+ },
21
+ cleffa: {
22
+ name: 'cleffa',
23
+ domain: 'cleffa.originals.build',
24
+ stability: 'minor',
25
+ description: 'Staging network - accepts minor releases',
26
+ contextUrl: 'https://cleffa.originals.build/context',
27
+ bitcoinNetwork: 'signet', // Staging → signet
28
+ },
29
+ pichu: {
30
+ name: 'pichu',
31
+ domain: 'pichu.originals.build',
32
+ stability: 'major',
33
+ description: 'Production network - accepts major releases only (most stable)',
34
+ contextUrl: 'https://pichu.originals.build/context',
35
+ bitcoinNetwork: 'mainnet', // Production → mainnet
36
+ },
37
+ };
38
+ /**
39
+ * Default network for backward compatibility
40
+ */
41
+ export const DEFAULT_WEBVH_NETWORK = 'pichu';
42
+ /**
43
+ * Get network configuration by name
44
+ * @param network - Network name
45
+ * @returns Network configuration
46
+ */
47
+ export function getNetworkConfig(network) {
48
+ const config = WEBVH_NETWORKS[network];
49
+ if (!config) {
50
+ throw new Error(`Invalid WebVH network: ${network}. Valid networks: magby, cleffa, pichu`);
51
+ }
52
+ return config;
53
+ }
54
+ /**
55
+ * Get network domain
56
+ * @param network - Network name
57
+ * @returns Network domain
58
+ */
59
+ export function getNetworkDomain(network) {
60
+ return getNetworkConfig(network).domain;
61
+ }
62
+ /**
63
+ * Get network context URL
64
+ * @param network - Network name
65
+ * @returns Context URL for the network
66
+ */
67
+ export function getNetworkContextUrl(network) {
68
+ return getNetworkConfig(network).contextUrl;
69
+ }
70
+ /**
71
+ * Validate that a version string matches the network's stability requirements
72
+ * @param version - Semver version string (e.g., "1.2.3")
73
+ * @param network - Network name
74
+ * @returns True if the version is allowed on this network
75
+ */
76
+ export function validateVersionForNetwork(version, network) {
77
+ const config = getNetworkConfig(network);
78
+ // Parse semver (basic parsing, assumes format X.Y.Z)
79
+ const match = version.match(/^(\d+)\.(\d+)\.(\d+)(?:-.*)?$/);
80
+ if (!match) {
81
+ throw new Error(`Invalid version format: ${version}. Expected semver format (e.g., 1.2.3)`);
82
+ }
83
+ const [, major, minor, patch] = match;
84
+ switch (config.stability) {
85
+ case 'major':
86
+ // Pichu: Only allow major releases (X.0.0)
87
+ return minor === '0' && patch === '0';
88
+ case 'minor':
89
+ // Cleffa: Allow minor releases (X.Y.0)
90
+ return patch === '0';
91
+ case 'patch':
92
+ // Magby: Allow all versions including patches
93
+ return true;
94
+ default:
95
+ throw new Error(`Unknown stability level: ${config.stability}`);
96
+ }
97
+ }
98
+ /**
99
+ * Get the appropriate network for a given version
100
+ * Returns the most restrictive network that accepts this version
101
+ * @param version - Semver version string
102
+ * @returns Recommended network name
103
+ */
104
+ export function getRecommendedNetworkForVersion(version) {
105
+ // Try networks from most restrictive to least restrictive
106
+ if (validateVersionForNetwork(version, 'pichu')) {
107
+ return 'pichu';
108
+ }
109
+ if (validateVersionForNetwork(version, 'cleffa')) {
110
+ return 'cleffa';
111
+ }
112
+ return 'magby';
113
+ }
114
+ /**
115
+ * Get the corresponding Bitcoin network for a WebVH network
116
+ * This ensures consistent environment mapping across the stack:
117
+ * - magby (dev) → regtest (dev)
118
+ * - cleffa (staging) → signet (staging)
119
+ * - pichu (production) → mainnet (production)
120
+ *
121
+ * @param webvhNetwork - WebVH network name
122
+ * @returns Corresponding Bitcoin network name
123
+ */
124
+ export function getBitcoinNetworkForWebVH(webvhNetwork) {
125
+ return getNetworkConfig(webvhNetwork).bitcoinNetwork;
126
+ }
127
+ /**
128
+ * Get the WebVH network that corresponds to a Bitcoin network
129
+ * This is the reverse mapping of getBitcoinNetworkForWebVH
130
+ *
131
+ * @param bitcoinNetwork - Bitcoin network name
132
+ * @returns Corresponding WebVH network name, or undefined if no mapping exists
133
+ */
134
+ export function getWebVHNetworkForBitcoin(bitcoinNetwork) {
135
+ switch (bitcoinNetwork) {
136
+ case 'mainnet':
137
+ return 'pichu';
138
+ case 'signet':
139
+ return 'cleffa';
140
+ case 'regtest':
141
+ return 'magby';
142
+ default:
143
+ return undefined;
144
+ }
145
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Event Logger - Integration between Event System and Logger
3
+ *
4
+ * Features:
5
+ * - Auto-subscribe to EventEmitter events
6
+ * - Configurable logging levels per event type
7
+ * - Automatic metrics extraction from events
8
+ * - Performance tracking
9
+ */
10
+ import type { EventEmitter } from '../events/EventEmitter';
11
+ import type { Logger, LogLevel } from './Logger';
12
+ import type { MetricsCollector } from './MetricsCollector';
13
+ /**
14
+ * Event logging configuration
15
+ */
16
+ export interface EventLoggingConfig {
17
+ 'asset:created'?: LogLevel | false;
18
+ 'asset:migrated'?: LogLevel | false;
19
+ 'asset:transferred'?: LogLevel | false;
20
+ 'resource:published'?: LogLevel | false;
21
+ 'credential:issued'?: LogLevel | false;
22
+ 'resource:version:created'?: LogLevel | false;
23
+ 'verification:completed'?: LogLevel | false;
24
+ 'batch:started'?: LogLevel | false;
25
+ 'batch:completed'?: LogLevel | false;
26
+ 'batch:failed'?: LogLevel | false;
27
+ 'migration:started'?: LogLevel | false;
28
+ 'migration:validated'?: LogLevel | false;
29
+ 'migration:checkpointed'?: LogLevel | false;
30
+ 'migration:in_progress'?: LogLevel | false;
31
+ 'migration:anchoring'?: LogLevel | false;
32
+ 'migration:completed'?: LogLevel | false;
33
+ 'migration:failed'?: LogLevel | false;
34
+ 'migration:rolledback'?: LogLevel | false;
35
+ 'migration:quarantine'?: LogLevel | false;
36
+ 'batch:progress'?: LogLevel | false;
37
+ }
38
+ /**
39
+ * EventLogger class for integrating events with logging and metrics
40
+ */
41
+ export declare class EventLogger {
42
+ private logger;
43
+ private metricsCollector;
44
+ private config;
45
+ private unsubscribeFns;
46
+ constructor(logger: Logger, metricsCollector: MetricsCollector);
47
+ /**
48
+ * Subscribe to all events from an EventEmitter
49
+ */
50
+ subscribeToEvents(eventEmitter: EventEmitter): void;
51
+ /**
52
+ * Configure which events to log at which levels
53
+ */
54
+ configureEventLogging(config: EventLoggingConfig): void;
55
+ /**
56
+ * Unsubscribe from all events
57
+ */
58
+ unsubscribe(): void;
59
+ /**
60
+ * Handle an event - log and extract metrics
61
+ */
62
+ private handleEvent;
63
+ /**
64
+ * Log an event at the specified level
65
+ */
66
+ private logEvent;
67
+ /**
68
+ * Extract metrics from an event
69
+ */
70
+ private extractMetrics;
71
+ }
@@ -0,0 +1,232 @@
1
+ /**
2
+ * Event Logger - Integration between Event System and Logger
3
+ *
4
+ * Features:
5
+ * - Auto-subscribe to EventEmitter events
6
+ * - Configurable logging levels per event type
7
+ * - Automatic metrics extraction from events
8
+ * - Performance tracking
9
+ */
10
+ /**
11
+ * Default event logging configuration
12
+ */
13
+ const DEFAULT_EVENT_CONFIG = {
14
+ 'asset:created': 'info',
15
+ 'asset:migrated': 'info',
16
+ 'asset:transferred': 'info',
17
+ 'resource:published': 'info',
18
+ 'credential:issued': 'info',
19
+ 'resource:version:created': 'info',
20
+ 'verification:completed': 'info',
21
+ 'batch:started': 'info',
22
+ 'batch:completed': 'info',
23
+ 'batch:failed': 'warn',
24
+ 'migration:started': 'info',
25
+ 'migration:validated': 'info',
26
+ 'migration:checkpointed': 'info',
27
+ 'migration:in_progress': 'info',
28
+ 'migration:anchoring': 'info',
29
+ 'migration:completed': 'info',
30
+ 'migration:failed': 'warn',
31
+ 'migration:rolledback': 'warn',
32
+ 'migration:quarantine': 'error',
33
+ 'batch:progress': 'debug'
34
+ };
35
+ /**
36
+ * EventLogger class for integrating events with logging and metrics
37
+ */
38
+ export class EventLogger {
39
+ constructor(logger, metricsCollector) {
40
+ this.logger = logger;
41
+ this.metricsCollector = metricsCollector;
42
+ this.unsubscribeFns = [];
43
+ this.config = { ...DEFAULT_EVENT_CONFIG };
44
+ }
45
+ /**
46
+ * Subscribe to all events from an EventEmitter
47
+ */
48
+ subscribeToEvents(eventEmitter) {
49
+ // Subscribe to each event type
50
+ const eventTypes = [
51
+ 'asset:created',
52
+ 'asset:migrated',
53
+ 'asset:transferred',
54
+ 'resource:published',
55
+ 'credential:issued',
56
+ 'resource:version:created',
57
+ 'verification:completed',
58
+ 'batch:started',
59
+ 'batch:completed',
60
+ 'batch:failed'
61
+ ];
62
+ for (const eventType of eventTypes) {
63
+ const unsubscribe = eventEmitter.on(eventType, (event) => {
64
+ this.handleEvent(event);
65
+ });
66
+ this.unsubscribeFns.push(unsubscribe);
67
+ }
68
+ }
69
+ /**
70
+ * Configure which events to log at which levels
71
+ */
72
+ configureEventLogging(config) {
73
+ this.config = { ...this.config, ...config };
74
+ }
75
+ /**
76
+ * Unsubscribe from all events
77
+ */
78
+ unsubscribe() {
79
+ for (const unsubscribe of this.unsubscribeFns) {
80
+ unsubscribe();
81
+ }
82
+ this.unsubscribeFns = [];
83
+ }
84
+ /**
85
+ * Handle an event - log and extract metrics
86
+ */
87
+ handleEvent(event) {
88
+ const eventType = event.type;
89
+ const logLevel = this.config[eventType];
90
+ // Always extract metrics from the event (even if logging is disabled)
91
+ this.extractMetrics(event);
92
+ // Skip logging if disabled for this event type
93
+ if (logLevel === false) {
94
+ return;
95
+ }
96
+ // Log the event
97
+ if (logLevel) {
98
+ this.logEvent(event, logLevel);
99
+ }
100
+ }
101
+ /**
102
+ * Log an event at the specified level
103
+ */
104
+ logEvent(event, level) {
105
+ let message;
106
+ let data;
107
+ switch (event.type) {
108
+ case 'asset:created':
109
+ message = 'Asset created';
110
+ data = {
111
+ assetId: event.asset.id,
112
+ layer: event.asset.layer,
113
+ resourceCount: event.asset.resourceCount
114
+ };
115
+ break;
116
+ case 'asset:migrated':
117
+ message = 'Asset migrated';
118
+ data = {
119
+ assetId: event.asset.id,
120
+ fromLayer: event.asset.fromLayer,
121
+ toLayer: event.asset.toLayer,
122
+ details: event.details
123
+ };
124
+ break;
125
+ case 'asset:transferred':
126
+ message = 'Asset transferred';
127
+ data = {
128
+ assetId: event.asset.id,
129
+ layer: event.asset.layer,
130
+ from: event.from,
131
+ to: event.to,
132
+ transactionId: event.transactionId
133
+ };
134
+ break;
135
+ case 'resource:published':
136
+ message = 'Resource published';
137
+ data = {
138
+ assetId: event.asset.id,
139
+ resourceId: event.resource.id,
140
+ url: event.resource.url,
141
+ publisherDid: event.publisherDid
142
+ };
143
+ break;
144
+ case 'credential:issued':
145
+ message = 'Credential issued';
146
+ data = {
147
+ assetId: event.asset.id,
148
+ credentialType: event.credential.type,
149
+ issuer: event.credential.issuer
150
+ };
151
+ break;
152
+ case 'resource:version:created':
153
+ message = 'Resource version created';
154
+ data = {
155
+ assetId: event.asset.id,
156
+ resourceId: event.resource.id,
157
+ fromVersion: event.resource.fromVersion,
158
+ toVersion: event.resource.toVersion,
159
+ changes: event.changes
160
+ };
161
+ break;
162
+ case 'verification:completed':
163
+ message = 'Verification completed';
164
+ data = {
165
+ assetId: event.asset.id,
166
+ result: event.result,
167
+ checks: event.checks
168
+ };
169
+ break;
170
+ case 'batch:started':
171
+ message = 'Batch operation started';
172
+ data = {
173
+ batchId: event.batchId,
174
+ operation: event.operation,
175
+ itemCount: event.itemCount
176
+ };
177
+ break;
178
+ case 'batch:completed':
179
+ message = 'Batch operation completed';
180
+ data = {
181
+ batchId: event.batchId,
182
+ operation: event.operation,
183
+ results: event.results
184
+ };
185
+ break;
186
+ case 'batch:failed':
187
+ message = 'Batch operation failed';
188
+ data = {
189
+ batchId: event.batchId,
190
+ operation: event.operation,
191
+ error: event.error,
192
+ partialResults: event.partialResults
193
+ };
194
+ break;
195
+ default:
196
+ return; // Unknown event type
197
+ }
198
+ // Call the appropriate log method based on level
199
+ switch (level) {
200
+ case 'debug':
201
+ this.logger.debug(message, data);
202
+ break;
203
+ case 'info':
204
+ this.logger.info(message, data);
205
+ break;
206
+ case 'warn':
207
+ this.logger.warn(message, data);
208
+ break;
209
+ case 'error':
210
+ this.logger.error(message, undefined, data);
211
+ break;
212
+ }
213
+ }
214
+ /**
215
+ * Extract metrics from an event
216
+ */
217
+ extractMetrics(event) {
218
+ switch (event.type) {
219
+ case 'asset:created':
220
+ this.metricsCollector.recordAssetCreated();
221
+ break;
222
+ case 'asset:migrated':
223
+ this.metricsCollector.recordMigration(event.asset.fromLayer, event.asset.toLayer);
224
+ break;
225
+ case 'asset:transferred':
226
+ this.metricsCollector.recordTransfer();
227
+ break;
228
+ // Other events don't need explicit metric recording
229
+ // as they're tracked elsewhere
230
+ }
231
+ }
232
+ }
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Enhanced Logger for Originals SDK
3
+ *
4
+ * Features:
5
+ * - Multiple log levels (debug, info, warn, error)
6
+ * - Child loggers with hierarchical context
7
+ * - Performance timing with startTimer
8
+ * - Multiple output destinations
9
+ * - Data sanitization for sensitive information
10
+ * - Async-safe operations
11
+ */
12
+ import type { OriginalsConfig } from '../types';
13
+ /**
14
+ * Log level type
15
+ */
16
+ export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
17
+ /**
18
+ * Structured log entry
19
+ */
20
+ export interface LogEntry {
21
+ timestamp: string;
22
+ level: LogLevel;
23
+ context: string;
24
+ message: string;
25
+ data?: any;
26
+ duration?: number;
27
+ traceId?: string;
28
+ }
29
+ /**
30
+ * Log output interface for custom outputs
31
+ */
32
+ export interface LogOutput {
33
+ write(entry: LogEntry): void | Promise<void>;
34
+ }
35
+ /**
36
+ * Console log output implementation
37
+ */
38
+ export declare class ConsoleLogOutput implements LogOutput {
39
+ write(entry: LogEntry): void;
40
+ }
41
+ /**
42
+ * File log output implementation (async)
43
+ */
44
+ export declare class FileLogOutput implements LogOutput {
45
+ private filePath;
46
+ private buffer;
47
+ private flushTimeout;
48
+ private readonly flushInterval;
49
+ constructor(filePath: string);
50
+ write(entry: LogEntry): Promise<void>;
51
+ private flush;
52
+ }
53
+ /**
54
+ * Main Logger class
55
+ */
56
+ export declare class Logger {
57
+ private context;
58
+ private outputs;
59
+ private minLevel;
60
+ private includeTimestamps;
61
+ private includeContext;
62
+ private sanitizeLogs;
63
+ private static readonly LEVEL_PRIORITY;
64
+ constructor(context: string, config: OriginalsConfig);
65
+ /**
66
+ * Log a debug message
67
+ */
68
+ debug(message: string, data?: any): void;
69
+ /**
70
+ * Log an info message
71
+ */
72
+ info(message: string, data?: any): void;
73
+ /**
74
+ * Log a warning message
75
+ */
76
+ warn(message: string, data?: any): void;
77
+ /**
78
+ * Log an error message
79
+ */
80
+ error(message: string, error?: Error, data?: any): void;
81
+ /**
82
+ * Start a timer for performance tracking
83
+ * Returns a function that stops the timer and logs the duration
84
+ */
85
+ startTimer(operation: string): () => void;
86
+ /**
87
+ * Create a child logger with nested context
88
+ */
89
+ child(childContext: string): Logger;
90
+ /**
91
+ * Set a single output (replaces existing outputs)
92
+ */
93
+ setOutput(output: LogOutput): void;
94
+ /**
95
+ * Add an output to the existing outputs
96
+ */
97
+ addOutput(output: LogOutput): void;
98
+ /**
99
+ * Internal log method
100
+ */
101
+ private log;
102
+ /**
103
+ * Sanitize sensitive data from logs
104
+ */
105
+ private sanitize;
106
+ }