emblem-vault-sdk 2.3.6 → 3.0.0-experimental

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 (147) hide show
  1. package/.traces/blockchain-provider-abstraction-plan.md +302 -0
  2. package/.traces/notes.md +43 -0
  3. package/.traces/readme-verification-trace.md +988 -0
  4. package/.traces/test-migration-status.md +227 -0
  5. package/.traces/tests-consolidated-trace.md +667 -0
  6. package/dist/abi/abi.json +53 -0
  7. package/dist/bundle.js +21602 -17419
  8. package/dist/clients/emblemVaultSolanaWalletClient.d.ts +74 -0
  9. package/dist/clients/emblemVaultSolanaWalletClient.js +149 -0
  10. package/dist/clients/emblemVaultSolanaWalletClient.js.map +1 -0
  11. package/dist/clients/emblemVaultWalletClient.d.ts +52 -0
  12. package/dist/clients/emblemVaultWalletClient.js +110 -0
  13. package/dist/clients/emblemVaultWalletClient.js.map +1 -0
  14. package/dist/derive.js +7 -0
  15. package/dist/derive.js.map +1 -0
  16. package/dist/index.js +319 -114
  17. package/dist/index.js.map +1 -0
  18. package/dist/providers/ProviderManager.d.ts +57 -0
  19. package/dist/providers/ProviderManager.js +283 -0
  20. package/dist/providers/ProviderManager.js.map +1 -0
  21. package/dist/providers.d.ts +101 -0
  22. package/dist/providers.js +96 -0
  23. package/dist/providers.js.map +1 -0
  24. package/dist/types.js +1 -0
  25. package/dist/types.js.map +1 -0
  26. package/dist/utils.js +61 -58
  27. package/dist/utils.js.map +1 -0
  28. package/docs/bundle.js +21602 -17419
  29. package/docs/index.html +150 -13
  30. package/docs/local.html +385 -0
  31. package/docs/steps.html +420 -53
  32. package/package.json +22 -13
  33. package/readme.md +795 -21
  34. package/src/abi/abi.json +54 -1
  35. package/src/clients/emblemVaultSolanaWalletClient.ts +257 -0
  36. package/src/clients/emblemVaultWalletClient.ts +159 -0
  37. package/src/derive.ts +5 -5
  38. package/src/index.ts +320 -102
  39. package/src/providers/ProviderManager.ts +254 -0
  40. package/src/providers.ts +163 -0
  41. package/src/types.ts +50 -0
  42. package/src/utils.ts +63 -62
  43. package/test/.mocharc.js +8 -0
  44. package/test/README.md +212 -0
  45. package/test/fixtures/ethscriptions/balance-with-native-first.json +24 -0
  46. package/test/fixtures/ethscriptions/balance-with-native.json +23 -0
  47. package/test/fixtures/ethscriptions/balance.json +18 -0
  48. package/test/helpers/sdkLoader.js +88 -0
  49. package/test/helpers/setup.js +55 -0
  50. package/test/integration/ApiOperations.spec.js +102 -0
  51. package/test/integration/VaultAI.spec.js +57 -0
  52. package/test/integration/VaultCreation.spec.js +95 -0
  53. package/test/mocks.js +127 -0
  54. package/test/tsconfig.json +25 -0
  55. package/test/unit/AllowedBells.spec.js +53 -0
  56. package/test/unit/AllowedBitcoinDeGods.spec.js +53 -0
  57. package/test/unit/AllowedBitcoinOrdinals.spec.js +46 -0
  58. package/test/unit/AllowedCounterparty.spec.js +66 -0
  59. package/test/unit/AllowedCursedOrdinals.spec.js +68 -0
  60. package/test/unit/AllowedEmbells.spec.js +11 -0
  61. package/test/unit/AllowedEmbels.spec.js +11 -0
  62. package/test/unit/AllowedEmblemOpen.spec.js +20 -0
  63. package/test/unit/AllowedEthscriptions.spec.js +53 -0
  64. package/test/unit/AllowedHardcodedNfts.spec.js +77 -0
  65. package/test/unit/AllowedNamecoin.spec.js +33 -0
  66. package/test/unit/AllowedOrdi.spec.js +46 -0
  67. package/test/unit/AllowedOxbt.spec.js +46 -0
  68. package/test/unit/AllowedProjectCollection.spec.js +51 -0
  69. package/test/unit/AllowedProtocolCollection.spec.js +44 -0
  70. package/test/unit/AllowedStamps.spec.js +78 -0
  71. package/test/unit/DarkfarmsMetadata.spec.js +10 -0
  72. package/test/unit/EmblemVaultSdk.spec.js +188 -0
  73. package/test/unit/Providers.spec.js +290 -0
  74. package/test/unit/ResourceMonitor.spec.js +111 -0
  75. package/test/unit/SDKMemoryLeaks.spec.js +176 -0
  76. package/test/unit/Signing.spec.js +321 -0
  77. package/test/unit/VaultAI.spec.js +140 -0
  78. package/test/unit/clients/EmblemVaultSolanaWalletClient.spec.js +296 -0
  79. package/test/unit/clients/EmblemVaultWalletClient.spec.js +246 -0
  80. package/test/utils/ResourceMonitor.js +169 -0
  81. package/test/windsurf-rules.md +68 -0
  82. package/tsconfig.json +7 -3
  83. package/types/derive.d.ts +0 -5
  84. package/types/index.d.ts +152 -32
  85. package/types/types.d.ts +43 -0
  86. package/types/utils.d.ts +7 -1
  87. package/dist/abi/quote.js +0 -29
  88. package/dist/abi/quote.json +0 -26
  89. package/jest.config.js +0 -6
  90. package/tests/AllowedBells.test.ts +0 -53
  91. package/tests/AllowedBitcoinDeGods.test.ts +0 -53
  92. package/tests/AllowedBitcoinOrdinals.test.ts +0 -46
  93. package/tests/AllowedCounterparty.test.ts +0 -45
  94. package/tests/AllowedCursedOrdinals.test.ts +0 -68
  95. package/tests/AllowedEmbells.test.ts +0 -12
  96. package/tests/AllowedEmbels.test.ts +0 -16
  97. package/tests/AllowedEmblemOpen.test.ts +0 -20
  98. package/tests/AllowedEthscriptions.test.ts +0 -39
  99. package/tests/AllowedHardcodedNfts.test.ts +0 -78
  100. package/tests/AllowedNamecoin.test.ts +0 -33
  101. package/tests/AllowedOrdi.test.ts +0 -47
  102. package/tests/AllowedOxbt.test.ts +0 -47
  103. package/tests/AllowedProjectlCollection.test.ts +0 -51
  104. package/tests/AllowedProtocolCollection.test.ts +0 -44
  105. package/tests/AllowedStamps.test.ts +0 -73
  106. package/tests/DarkfarmsMetadata.test.ts +0 -10
  107. package/tests/EmblemVaultSdk.test.ts +0 -124
  108. package/tests/fixtures/embels/balance.json +0 -10
  109. package/tests/fixtures/ethscriptions/balance-with-native-first.json +0 -69
  110. package/tests/fixtures/ethscriptions/balance-with-native.json +0 -37
  111. package/tests/fixtures/ethscriptions/balance.json +0 -64
  112. /package/{tests → test}/fixtures/bells/balance-with-non-bell-first.json +0 -0
  113. /package/{tests → test}/fixtures/bells/balance-with-non-bell.json +0 -0
  114. /package/{tests → test}/fixtures/bells/balance.json +0 -0
  115. /package/{tests → test}/fixtures/bitcoin-degods/balance-with-non-degods-first.json +0 -0
  116. /package/{tests → test}/fixtures/bitcoin-degods/balance-with-non-degods.json +0 -0
  117. /package/{tests → test}/fixtures/bitcoin-degods/balance.json +0 -0
  118. /package/{tests → test}/fixtures/bitcoin-ordinals/balance-with-native-first.json +0 -0
  119. /package/{tests → test}/fixtures/bitcoin-ordinals/balance-with-only-native.json +0 -0
  120. /package/{tests → test}/fixtures/bitcoin-ordinals/balance.json +0 -0
  121. /package/{tests → test}/fixtures/counterparty/balance-with-multiple.json +0 -0
  122. /package/{tests → test}/fixtures/counterparty/balance.json +0 -0
  123. /package/{tests → test}/fixtures/cursed-ordinals/balance-with-native-first.json +0 -0
  124. /package/{tests → test}/fixtures/cursed-ordinals/balance-with-native.json +0 -0
  125. /package/{tests → test}/fixtures/cursed-ordinals/balance.json +0 -0
  126. /package/{tests → test}/fixtures/dogeparty/balance-with-non-dogeparty-first.json +0 -0
  127. /package/{tests → test}/fixtures/dogeparty/balance-with-non-dogeparty.json +0 -0
  128. /package/{tests → test}/fixtures/dogeparty/balance.json +0 -0
  129. /package/{tests → test}/fixtures/emblem-open/balance.json +0 -0
  130. /package/{tests → test}/fixtures/hardcoded-nfts/balance-witn-non-hardcoded-first.json +0 -0
  131. /package/{tests → test}/fixtures/hardcoded-nfts/balance-witn-non-hardcoded.json +0 -0
  132. /package/{tests → test}/fixtures/hardcoded-nfts/balance.json +0 -0
  133. /package/{tests → test}/fixtures/megapunks/balance-with-non-megapunk-first.json +0 -0
  134. /package/{tests → test}/fixtures/megapunks/balance-with-non-megapunk.json +0 -0
  135. /package/{tests → test}/fixtures/megapunks/balance.json +0 -0
  136. /package/{tests → test}/fixtures/namecoin/balance-with-native-first.json +0 -0
  137. /package/{tests → test}/fixtures/namecoin/balance-with-native.json +0 -0
  138. /package/{tests → test}/fixtures/namecoin/balance.json +0 -0
  139. /package/{tests → test}/fixtures/ordi/balance-with-native-first.json +0 -0
  140. /package/{tests → test}/fixtures/ordi/balance-with-native.json +0 -0
  141. /package/{tests → test}/fixtures/ordi/balance.json +0 -0
  142. /package/{tests → test}/fixtures/oxbt/balance-with-native-first.json +0 -0
  143. /package/{tests → test}/fixtures/oxbt/balance-with-native.json +0 -0
  144. /package/{tests → test}/fixtures/oxbt/balance.json +0 -0
  145. /package/{tests → test}/fixtures/stamps/balance-with-non-stamps-first.json +0 -0
  146. /package/{tests → test}/fixtures/stamps/balance-with-non-stamps.json +0 -0
  147. /package/{tests → test}/fixtures/stamps/balance.json +0 -0
@@ -0,0 +1,302 @@
1
+ # Blockchain Provider Abstraction Plan
2
+
3
+ ## Overview
4
+
5
+ This document outlines the plan for implementing a flexible blockchain provider abstraction in the Emblem Vault SDK. The goal is to create a system that allows the SDK to work with multiple blockchain ecosystems (Ethereum, Solana, Bitcoin) without directly depending on specific implementations, while maintaining backward compatibility with existing code.
6
+
7
+ ## Current State
8
+
9
+ Currently, the SDK:
10
+ - Has direct dependencies on web3.js for Ethereum interactions
11
+ - Uses window.ethereum for browser wallet connections
12
+ - Requires passing web3 instances to methods that need blockchain interaction
13
+ - Has hard-coded references to blockchain-specific functionality
14
+
15
+ ## Goals
16
+
17
+ 1. **Provider Registration**: Allow developers to register providers for different blockchain types
18
+ 2. **Auto-Detection**: Automatically detect and use available providers in the environment
19
+ 3. **Method Simplification**: Methods should not require passing providers directly
20
+ 4. **Backward Compatibility**: Maintain support for existing code that passes web3 instances
21
+ 5. **Testing Support**: Continue supporting the override function pattern for testing
22
+ 6. **Environment Agnostic**: Work in browser, Node.js, or any JavaScript environment
23
+
24
+ ## Implementation Plan
25
+
26
+ ### 1. Provider Interface
27
+
28
+ ```typescript
29
+ export type BlockchainType = 'ethereum' | 'solana' | 'bitcoin' | 'other';
30
+
31
+ export class EmblemVaultSDK {
32
+ private providers: Map<BlockchainType, any> = new Map();
33
+
34
+ // Register a provider for a specific blockchain type
35
+ registerProvider(type: BlockchainType, provider: any): void {
36
+ this.providers.set(type, provider);
37
+ }
38
+
39
+ // Get a registered provider by type
40
+ getProvider(type: BlockchainType): any {
41
+ return this.providers.get(type);
42
+ }
43
+ }
44
+ ```
45
+
46
+ ### 2. Auto-Detection Mechanism
47
+
48
+ ```typescript
49
+ // Auto-detect and use available providers in the environment
50
+ private async getOrDetectProvider(type: BlockchainType): Promise<any> {
51
+ // First check if we have a registered provider
52
+ let provider = this.providers.get(type);
53
+ if (provider) return provider;
54
+
55
+ // If not, try to detect one in the environment
56
+ if (typeof window !== 'undefined') {
57
+ switch (type) {
58
+ case 'ethereum':
59
+ if (window.ethereum) {
60
+ // Connect to MetaMask or other injected provider
61
+ await window.ethereum.request({ method: 'eth_requestAccounts' });
62
+ const { default: Web3 } = await import('web3');
63
+ provider = new Web3(window.ethereum);
64
+ this.registerProvider('ethereum', provider);
65
+ return provider;
66
+ }
67
+ break;
68
+ case 'solana':
69
+ if (window.solana) {
70
+ // Connect to Phantom or other Solana wallet
71
+ await window.solana.connect();
72
+ this.registerProvider('solana', window.solana);
73
+ return window.solana;
74
+ }
75
+ break;
76
+ case 'bitcoin':
77
+ if (window.bitcoin) {
78
+ this.registerProvider('bitcoin', window.bitcoin);
79
+ return window.bitcoin;
80
+ }
81
+ break;
82
+ }
83
+ }
84
+
85
+ throw new Error(`No provider available for blockchain type: ${type}`);
86
+ }
87
+ ```
88
+
89
+ ### 3. Method Updates
90
+
91
+ Update all methods that currently require a web3 instance to use the provider abstraction:
92
+
93
+ ```typescript
94
+ // Before
95
+ async legacyBalanceFromContractByAddress(web3: any, address: string) {
96
+ let legacyContract = await getLegacyContract(web3);
97
+ // ...
98
+ }
99
+
100
+ // After
101
+ async legacyBalanceFromContractByAddress(
102
+ address: string,
103
+ overrideFunc: Function | null = null
104
+ ) {
105
+ // If override function is provided, use it
106
+ if (overrideFunc && typeof overrideFunc === 'function') {
107
+ return await overrideFunc(this.apiKey, { address });
108
+ }
109
+
110
+ // Get or detect an Ethereum provider
111
+ const provider = await this.getOrDetectProvider('ethereum');
112
+
113
+ // Use the provider
114
+ let legacyContract = await getLegacyContract(provider);
115
+ // ...
116
+ }
117
+ ```
118
+
119
+ ### 4. Backward Compatibility
120
+
121
+ To maintain backward compatibility, we'll:
122
+
123
+ 1. Keep the `loadWeb3` method for existing code
124
+ 2. Add detection for when a web3 instance is passed directly to methods
125
+ 3. Update utility functions like `getLegacyContract` to work with both web3 instances and providers
126
+
127
+ ```typescript
128
+ // Update utility functions to handle both web3 and providers
129
+ export async function getLegacyContract(web3OrProvider: any) {
130
+ // If it's a web3 instance
131
+ if (web3OrProvider.eth && web3OrProvider.eth.Contract) {
132
+ return new web3OrProvider.eth.Contract(ABI, CONTRACT_ADDRESS);
133
+ }
134
+
135
+ // If it's an EIP-1193 provider
136
+ if (web3OrProvider.request) {
137
+ const { default: Web3 } = await import('web3');
138
+ const web3 = new Web3(web3OrProvider);
139
+ return new web3.eth.Contract(ABI, CONTRACT_ADDRESS);
140
+ }
141
+
142
+ throw new Error('Invalid provider or web3 instance');
143
+ }
144
+ ```
145
+
146
+ ### 5. Global Type Declarations
147
+
148
+ ```typescript
149
+ declare global {
150
+ interface Window {
151
+ ethereum: any;
152
+ solana: any;
153
+ bitcoin: any;
154
+ web3: any;
155
+ }
156
+ }
157
+ ```
158
+
159
+ ## Implementation Phases
160
+
161
+ ### Phase 1: Core Infrastructure (Completed)
162
+
163
+ 1. Add provider registration and retrieval methods
164
+ 2. Implement auto-detection mechanism
165
+ 3. Update global type declarations
166
+ 4. Create utility functions for provider detection and conversion
167
+
168
+ ### Phase 2: Method Updates (In Progress)
169
+
170
+ 1. Update Ethereum-specific methods to use the provider abstraction
171
+ - Added `performMintHelper` to replace web3-dependent `performMintChain`
172
+ 2. Add Solana-specific methods
173
+ 3. Add Bitcoin-specific methods
174
+ 4. Ensure backward compatibility with existing code
175
+
176
+ ### Phase 3: Signing Implementation (Next Focus)
177
+
178
+ 1. Create a consistent interface for transaction and message signing
179
+ 2. Implement adapters for different provider types
180
+ 3. Add methods for signing transactions and messages
181
+
182
+ ### Phase 4: Testing and Documentation
183
+
184
+ 1. Update tests to use the new provider abstraction
185
+ 2. Add tests for auto-detection
186
+ 3. Update documentation with examples
187
+ 4. Create migration guide for existing users
188
+
189
+ ## Current Implementation Status
190
+
191
+ ### Provider Abstraction Progress
192
+
193
+ 1. **Core Infrastructure (Completed)**:
194
+ - Provider registration and retrieval methods have been implemented
195
+ - Type detection for Ethereum, Solana, and Bitcoin providers is working
196
+ - Web3ProviderAdapter successfully bridges legacy Web3 instances to the new abstraction
197
+
198
+ 2. **Provider Types (Implemented)**:
199
+ - `ethereum`: Support for Web3.js and EIP-1193 providers
200
+ - `solana`: Support for Phantom-like wallets and Solana Connection objects
201
+ - `bitcoin`: Basic type detection implemented
202
+ - `other`: Fallback for unrecognized providers
203
+
204
+ 3. **SDK Integration (Partially Complete)**:
205
+ - `registerProvider()` method for registering blockchain providers
206
+ - `getProvider()` and `hasProvider()` for provider management
207
+ - `getOrDetectProvider()` for auto-detection with fallback
208
+ - `loadWeb3()` for backward compatibility
209
+
210
+ 4. **Method Migration (In Progress)**:
211
+ - Added `performMintHelper` stub as a provider-abstracted replacement for `performMintChain`
212
+ - Updated deprecation notices to point to new methods
213
+
214
+ 5. **Solana-Specific Features (Implemented)**:
215
+ - Added `createSolanaWalletClient()` method for Solana wallet integration
216
+ - Implemented detection for Phantom wallets and Solana Connection objects
217
+ - Proper type detection for Solana providers
218
+
219
+ 6. **AI Integration (Implemented)**:
220
+ - Added AI-specific functionality
221
+ - Implemented `vaultInfoFromApiKey()` with proper API key handling
222
+ - Added AI URL and API key configuration in the SDK constructor
223
+
224
+ ## Usage Examples
225
+
226
+ ### Lazy Developer (No Provider Registration)
227
+
228
+ ```typescript
229
+ // The SDK will auto-detect and use available providers
230
+ const sdk = new EmblemVaultSDK('YOUR_API_KEY');
231
+
232
+ // Use Ethereum methods (will auto-detect MetaMask if available)
233
+ const balance = await sdk.legacyBalanceFromContractByAddress('0x123...');
234
+ ```
235
+
236
+ ### Server-Side with Explicit Provider
237
+
238
+ ```typescript
239
+ // In Node.js environment
240
+ const sdk = new EmblemVaultSDK('YOUR_API_KEY');
241
+ const Web3 = require('web3');
242
+ const web3 = new Web3('https://mainnet.infura.io/v3/YOUR_INFURA_KEY');
243
+
244
+ // Register the provider once
245
+ sdk.registerProvider('ethereum', web3);
246
+
247
+ // Use Ethereum methods (will use the registered provider)
248
+ const balance = await sdk.legacyBalanceFromContractByAddress('0x123...');
249
+ ```
250
+
251
+ ### Using with WalletConnect
252
+
253
+ ```typescript
254
+ // Using with WalletConnect
255
+ const sdk = new EmblemVaultSDK('YOUR_API_KEY');
256
+
257
+ // Create a WalletConnect provider
258
+ const walletConnectProvider = await EthereumProvider.init({
259
+ projectId: 'YOUR_PROJECT_ID',
260
+ chains: [1],
261
+ showQrModal: true
262
+ });
263
+
264
+ // Register it once
265
+ sdk.registerProvider('ethereum', walletConnectProvider);
266
+
267
+ // Use Ethereum methods (will use WalletConnect)
268
+ const balance = await sdk.legacyBalanceFromContractByAddress('0x123...');
269
+ ```
270
+
271
+ ### Testing with Override Functions
272
+
273
+ ```typescript
274
+ // Testing with override functions
275
+ const sdk = new EmblemVaultSDK('YOUR_API_KEY');
276
+
277
+ // Mock data for testing
278
+ const mockData = [1, 2, 3];
279
+
280
+ // Use override function (no provider needed)
281
+ const balance = await sdk.legacyBalanceFromContractByAddress(
282
+ '0x123...',
283
+ () => mockData
284
+ );
285
+ ```
286
+
287
+ ## Benefits
288
+
289
+ 1. **Developer-Friendly**: Developers don't need to worry about providers unless they want to
290
+ 2. **Environment-Aware**: Works in browser, Node.js, or any JavaScript environment
291
+ 3. **Register Once, Use Everywhere**: Register providers once and use them across all methods
292
+ 4. **Auto-Detection**: Automatically detects and uses available providers
293
+ 5. **Blockchain-Specific Methods**: Each method is designed for a specific blockchain
294
+ 6. **Override Function Pattern**: Maintains the established pattern for testing
295
+ 7. **Backward Compatibility**: Works with existing code through the loadWeb3 method
296
+
297
+ ## Next Steps
298
+
299
+ 1. Complete the implementation of `performMintHelper` and other signing-related methods
300
+ 2. Add tests for the new signing functionality
301
+ 3. Update documentation with examples of using the provider abstraction
302
+ 4. Create a migration guide for existing users
@@ -0,0 +1,43 @@
1
+ every function that fetches data, should allow for an override function that can provide an alternate source (for mocking, for database usage to pass in a db, etc)
2
+ imports should be normal
3
+
4
+ support import and require
5
+ so js and ts
6
+
7
+ remove dependancy on web3
8
+
9
+ make a signer
10
+
11
+ let another vault be the signer (with a vault api key)
12
+
13
+ document a vault api key,
14
+
15
+ allow vaults to be created with a to that's not an eoa, so we can assign it to a social auth
16
+
17
+
18
+ Vault lifecycle
19
+
20
+ Get curated collection(s)
21
+ select one collection to mint
22
+ grab template from collection.mintTemplate
23
+ populate template with owner, name description and curated contents if required
24
+ validate template
25
+ create vault
26
+
27
+ **** balance loading ****
28
+
29
+ check mintabilty with collection.valid()
30
+ if valid, perform mint steps
31
+ get local signature
32
+
33
+ TODO NEXT
34
+ * make signer util for tests
35
+ * import into tests, making 2 signers, a user and a server
36
+ * request remote signature using user signature
37
+ * fake server signature
38
+ * perform mint, overriding result
39
+
40
+ bonus:
41
+ add emblem vault ai as a provider, and implement the functions for each vault type using the sdk
42
+
43
+