emblem-vault-sdk 1.9.16 → 1.9.18

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/index.js CHANGED
@@ -35,7 +35,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
35
35
  const bignumber_1 = require("@ethersproject/bignumber");
36
36
  const utils_1 = require("./utils");
37
37
  const derive_1 = require("./derive");
38
- const SDK_VERSION = '1.9.16';
38
+ const SDK_VERSION = '1.9.18';
39
39
  class EmblemVaultSDK {
40
40
  constructor(apiKey, baseUrl) {
41
41
  this.apiKey = apiKey;
package/dist/utils.js CHANGED
@@ -318,6 +318,10 @@ function generateTemplate(record) {
318
318
  else if (recordName == "Bitcoin DeGods") {
319
319
  allowed = firstAsset.coin == "ordinalsbtc" && firstAsset.balance == 1 && firstAsset.project == "DeGods";
320
320
  }
321
+ else if (recordName == "dot_id" || recordName == "dot_bit") {
322
+ data = _this.filterNativeBalances({ balances: data }, _this);
323
+ allowed = data[0].project == recordName;
324
+ }
321
325
  else if (PROJECTS_DATA.includes(recordName)) { // XCP
322
326
  allowed = !!exports.NFT_DATA[assetName] &&
323
327
  exports.NFT_DATA[assetName]["projectName"].toLowerCase() == recordName.toLowerCase() &&
package/docs/index.html CHANGED
@@ -121,6 +121,7 @@
121
121
  function selectContract(index) {
122
122
  let contract = window.curatedContracts[index];
123
123
  let template = contract.generateCreateTemplate(contract)
124
+ template.chainId = 1
124
125
  template.toAddress = document.getElementById('ethAddress').value;
125
126
  template.fromAddress = document.getElementById('ethAddress').value;
126
127
  window.contract = contract;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emblem-vault-sdk",
3
- "version": "1.9.16",
3
+ "version": "1.9.18",
4
4
  "description": "Emblem Vault Software Development Kit",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/readme.md CHANGED
@@ -1,61 +1,306 @@
1
- # Emblem Vault SDK
1
+ # Emblem Vault SDK Documentation
2
2
 
3
- ## Overview
4
- The EmblemVault SDK provides developers with the tools needed to interact with the EmblemVault API, facilitating the seamless integration of EmblemVault functionalities into applications.
3
+ The Emblem Vault SDK is a JavaScript library that provides functionality for interacting with Emblem Vaults, including creating vaults, refreshing balances, and performing minting operations.
5
4
 
6
- ## Getting Started
5
+ ## Table of Contents
6
+ - [Installation](#installation)
7
+ - [Initialization](#initialization)
8
+ - [Fetching Curated Contracts](#fetching-curated-contracts)
9
+ - [Creating a Vault](#creating-a-vault)
10
+ - [Refreshing Vault Balance](#refreshing-vault-balance)
11
+ - [Validating Mintability](#validating-mintability)
12
+ - [Performing a Mint](#performing-a-mint)
13
+ - [Utility Functions](#utility-functions)
14
+ - [generateUploadUrl()](#generateuploadurl)
15
+ - [generateAttributeTemplate(record: any)](#generateattributetemplaterecord-any)
16
+ - [generateImageTemplate(record: any)](#generateimagetemplaterecord-any)
17
+ - [generateTemplate(record: any)](#generatetemplaterecord-any)
18
+ - [templateGuard(input: { [x: string]: any; hasOwnProperty: (arg0: string) => any; })](#templateguardinput--x-string-any-hasownproperty-arg0-string--any-)
19
+ - [genericGuard(input: any, type: string, key: string)](#genericguardinput-any-type-string-key-string)
20
+ - [getQuoteContractObject(web3: any)](#getquotecontractobjectweb3-any)
21
+ - [getHandlerContract(web3: any)](#gethandlercontractweb3-any)
22
+ - [getLegacyContract(web3: any)](#getlegacycontractweb3-any)
23
+ - [checkContentType(url: string)](#checkcontenttypeurl-string)
24
+ - [getTorusKeys(verifierId: string, idToken: any, cb: any = null)](#gettoruskeysveriferid-string-idtoken-any-cb-any--null)
25
+ - [decryptKeys(vaultCiphertextV2: any, keys: any, addresses: any[])](#decryptkeysvaultciphertextv2-any-keys-any-addresses-any)
26
+ - [getSatsConnectAddress()](#getsatsconnectaddress)
27
+ - [signPSBT(psbtBase64: any, paymentAddress: any, indexes: number[], broadcast: boolean = false)](#signpsbtpsbtbase64-any-paymentaddress-any-indexes-number-broadcast-boolean--false)
28
+ - [Example Usage](#example-usage)
7
29
 
8
- ### Installation
9
- Install via npm or yarn:
10
- - `npm install emblemvault-sdk`
11
- - `yarn add emblemvault-sdk`
30
+ ## Installation
31
+
32
+ To use the Emblem Vault SDK in your project, include the `bundle.js` file in your HTML file:
33
+
34
+ ```html
35
+ <script src="./bundle.js"></script>
36
+ ```
37
+
38
+ Or use within NodeJS by `npm install emblem-vault-sdk`
12
39
 
13
- ### Initialization
14
- Initialize with your API key:
15
40
  ```javascript
16
- import EmblemVaultSDK from 'emblemvault-sdk';
17
- const emblemVaultSDK = new EmblemVaultSDK('YOUR_API_KEY');
41
+ let EmblemVaultSDK = require('emblem-vault-sdk').default
18
42
  ```
19
43
 
20
- ## API Reference
44
+ ## Initialization
21
45
 
22
- ### Asset Metadata Methods
23
- - **getAssetMetadata(projectName, strict = false)**: Fetch metadata for assets by project name.
24
- - **getAllAssetMetadata()**: Retrieve metadata for all assets.
25
- - **getAllProjects()**: Get a list of all projects.
46
+ To initialize the SDK, create an instance of the `EmblemVaultSDK` class:
26
47
 
27
- ### Curated Collections Methods
28
- - **fetchCuratedContracts(hideUnMintable = false, overrideFunc = false)**: Fetch curated contracts, with optional parameters to hide unmintable contracts or override the fetching function.
29
- - **fetchCuratedContractByName(name, contracts = false)**: Fetch a curated contract by its name.
48
+ ```javascript
30
49
 
31
- ### Web3 Integration Methods
32
- - **loadWeb3()**: Dynamically load Web3 and connect to MetaMask.
50
+ const sdk = new EmblemVaultSDK('demo');
51
+ ```
33
52
 
34
- ### Minting, Burning, and Claiming Methods
35
- - **performMintChain(web3, tokenId, collectionName, callback = null)**: Perform the minting process for a specific token in a collection.
36
- - **performBurn(web3, tokenId, callback = null)**: Burn a token.
37
- - **performClaimChain(web3, tokenId, serialNumber, callback = null)**: Claim ownership of a token.
53
+ ## Fetching Curated Contracts
54
+ To fetch the curated contracts, use the fetchCuratedContracts method:
55
+ ```javascript
56
+ sdk.fetchCuratedContracts(false).then(curatedContracts => {
57
+ // Use the curated contracts
58
+ });
59
+ ```
38
60
 
39
- ### Bitcoin Network Methods
40
- - **getSatsConnectAddress()**: Generate a SatsConnect address for Bitcoin transactions.
41
- - **generatePSBT(phrase, satsPerByte = 20)**: Generate a Partially Signed Bitcoin Transaction (PSBT).
42
- - **getTaprootAddressFromMnemonic(phrase)**: Generate a Taproot address from a mnemonic phrase.
61
+ ## Creating a Vault
62
+ To create a vault, prepare a contract template object and call the createCuratedVault method:
43
63
 
44
- ## Global Declaration
45
- The `EmblemVaultSDK` is available globally in web applications through the `window` object.
64
+ ```javascript
65
+ let contractTemplate = {
66
+ fromAddress: null,
67
+ toAddress: null,
68
+ chainId: 1,
69
+ experimental: true,
70
+ targetContract: {
71
+ "1": "0x345eF9d7E75aEEb979053AA41BB6330683353B7b",
72
+ "5": "0x582699d2c58A38056Cf02875540705137f0bbbF7",
73
+ name: "Bitcoin DeGods",
74
+ description: "Bitcoin DeGods is a collection of 535 Bitcoin Ordinals inscribed in the 77236 to 77770 range. This collection is curated by Emblem Vault."
75
+ },
76
+ targetAsset: {
77
+ image: "https://emblem.finance/btcdegods.jpg",
78
+ name: "Loading...",
79
+ xtra: "anything else you need here"
80
+ }
81
+ };
46
82
 
83
+ vaultData = await sdk.createCuratedVault(contractTemplate, updateLogCallback);
84
+ ```
85
+ ## Refreshing Vault Balance
86
+ To refresh the balance of a vault, use the refreshBalance method:
47
87
 
48
- ## Simple Html Demo
88
+ ```javascript
89
+ vaultBalance = await sdk.refreshBalance(vaultData.tokenId, updateLogCallback);
90
+ ```
91
+ ## Validating Mintability
92
+ To validate if a vault is mintable, use the allowed method of the curated contract object:
49
93
 
50
- View Live Demo Here(https://emblemcompany.github.io/emblem-vault-sdk/)
94
+ ```javascript
95
+ let contractObject = await sdk.fetchCuratedContractByName(contractTemplate.targetContract.name);
96
+ let mintable = contractObject.allowed(vaultBalance, contractObject);
51
97
  ```
52
- git clone https://github.com/EmblemCompany/emblem-vault-sdk.git
53
- cd emblem-vault-sdk/docs
54
- open index.html
98
+ ## Performing a Mint
99
+ To perform a mint, use the performMintChain method:
100
+
101
+ ```javascript
102
+ sdk.performMintChain(web3, vaultData.tokenId, contractTemplate.targetContract.name, updateLogCallback)
103
+ .then(result => {
104
+ // Handle success
105
+ })
106
+ .catch(error => {
107
+ // Handle error
108
+ });
55
109
  ```
110
+ ## Utility Functions
111
+ #### `generateUploadUrl()`
112
+
113
+ Generates a URL for uploading files.
114
+
115
+ #### `generateAttributeTemplate(record: any)`
56
116
 
57
- ### Visit our #Development channel on Discord
58
- #development (https://discord.gg/UEkrya8usj)
117
+ Generates an attribute template based on the provided record.
59
118
 
119
+ * Parameters:
120
+ * `record`: The record object containing information about the asset.
121
+ * Returns:
122
+ * An array of attribute templates.
60
123
 
124
+ #### `generateImageTemplate(record: any)`
125
+
126
+ Generates an image template based on the provided record.
127
+
128
+ * Parameters:
129
+ * `record`: The record object containing information about the asset.
130
+ * Returns:
131
+ * An object containing image template properties.
132
+
133
+ #### `generateTemplate(record: any)`
134
+
135
+ Generates a template for a given curated collection record.
136
+
137
+ * Parameters:
138
+ * `record`: The curated collection record.
139
+ * Returns:
140
+ A template object containing rules and utilities for the curated collection.
141
+
142
+ #### `templateGuard(input: { [x: string]: any; hasOwnProperty: (arg0: string) => any; })`
143
+
144
+ Validates the provided template input and throws an error if any required fields are missing or invalid.
145
+
146
+ * Parameters:
147
+ * `input`: The template input object to validate.
148
+
149
+ #### `genericGuard(input: any, type: string, key: string)`
150
+
151
+ Validates the provided input against the specified type and key.
152
+
153
+ * Parameters:
154
+ * `input`: The input value to validate.
155
+ * `type`: The expected type of the input.
156
+ * `key`: The key or name of the input.
157
+
158
+ #### `getQuoteContractObject(web3: any)`
159
+
160
+ Retrieves the quote contract object using the provided Web3 instance. Used to calculate the amount in BASE CURRENCY to charge for an operation
161
+
162
+ * Parameters:
163
+ * web3: The Web3 instance.
164
+ * Returns:
165
+ * A promise that resolves to the quote contract object.
166
+
167
+ Example
168
+ ```javascript
169
+ let USDPrice = 25;
170
+ ...
171
+ const quoteContract = await sdk.getQuoteContractObject(web3);
172
+ ...
173
+ // Get the current user's account
174
+ const userAccount = accounts[0];
175
+
176
+ // Call the quoteExternalPrice method on the quote contract
177
+ const quote = await quoteContract.methods.quoteExternalPrice(userAccount, USDPrice).call();
178
+
179
+ console.log('Quote:', quote);
180
+ } catch (error) {
181
+ console.error('Error getting quote:', error);
182
+ }
183
+
184
+ ```
185
+
186
+
187
+ #### `getHandlerContract(web3: any)`
188
+
189
+ Retrieves the handler contract object using the provided Web3 instance.
190
+
191
+ * Parameters:
192
+ * `web3`: The Web3 instance.
193
+ * Returns:
194
+ * A promise that resolves to the handler contract object.
195
+
196
+ #### `getLegacyContract(web3: any)`
197
+
198
+ Retrieves the legacy contract object using the provided Web3 instance.
199
+
200
+ * Parameters:
201
+ * `web3`: The Web3 instance.
202
+ * Returns:
203
+ * A promise that resolves to the legacy contract object.
204
+
205
+ #### `checkContentType(url: string)`
206
+
207
+ Checks the content type of the provided URL by making a HEAD request.
208
+
209
+ * Parameters:
210
+ * `url`: The URL to check the content type of.
211
+ * Returns:
212
+ * A promise that resolves to an object containing the content type information.
213
+
214
+ #### `getTorusKeys(verifierId: string, idToken: any, cb: any = null)`
215
+
216
+ Retrieves the Torus keys using the provided verifier ID and ID token.
217
+
218
+ * Parameters:
219
+ * `verifierId`: The verifier ID.
220
+ * `idToken`: The ID token.
221
+ * `cb` (optional): A callback function to handle the retrieved keys.
222
+ * Returns:
223
+ * A promise that resolves to an object containing the private key.
224
+
225
+ #### `decryptKeys(vaultCiphertextV2: any, keys: any, addresses: any[])`
226
+
227
+ Decrypts the vault keys using the provided ciphertext, keys, and addresses.
228
+
229
+ * Parameters:
230
+ * `vaultCiphertextV2`: The vault ciphertext to decrypt.
231
+ * `keys`: The keys used for decryption.
232
+ * `addresses`: An array of addresses associated with the vault.
233
+ * Returns:
234
+ * A promise that resolves to the decrypted payload.
235
+
236
+ #### `getSatsConnectAddress()`
237
+
238
+ Retrieves the Sats Connect address.
239
+
240
+ * Returns:
241
+ * A promise that resolves to an object containing the payment address, payment public key, and ordinals address.
242
+
243
+ #### `signPSBT(psbtBase64: any, paymentAddress: any, indexes: number[], broadcast: boolean = false)`
244
+
245
+ Signs a Partially Signed Bitcoin Transaction (PSBT) using the provided PSBT base64 data, payment address, and input indexes.
246
+
247
+ * Parameters:
248
+ * `psbtBase64`: The base64-encoded PSBT data.
249
+ * `paymentAddress`: The payment address.
250
+ * `indexes`: An array of input indexes to sign.
251
+ * `broadcast` (optional): A boolean indicating whether to broadcast the transaction after signing (default: false).
252
+ * Returns:
253
+ * A promise that resolves to the signed PSBT response.
254
+
255
+ ## Example Usage
256
+ Here's an example of how to use the Emblem Vault SDK to create a vault, refresh its balance, validate mintability, and perform a mint:
257
+ ```javascript
258
+ async function Step1() {
259
+ if (!defaultAccount) {
260
+ await sdk.loadWeb3();
261
+ defaultAccount = await web3.eth.getAccounts().then(accounts => accounts[0]).catch(err => console);
262
+ }
263
+ if (!vaultData) {
264
+ let chainId = Number(await web3.eth.net.getId());
265
+ contractTemplate.toAddress = defaultAccount;
266
+ contractTemplate.fromAddress = defaultAccount;
267
+ contractTemplate.chainId = chainId;
268
+ vaultData = await sdk.createCuratedVault(contractTemplate, updateLogCallback).catch(err => console.log(err));
269
+ if (!vaultData || vaultData.err) {
270
+ setTimeout(Step1, 1000);
271
+ } else {
272
+ updateLogCallback("deposit Address", vaultData.addresses.find(address => { return address.coin == 'TAP' }).address);
273
+ }
274
+ }
275
+ }
276
+
277
+ async function Step2() {
278
+ if (vaultData) {
279
+ vaultBalance = await sdk.refreshBalance(vaultData.tokenId, updateLogCallback).catch(err => console);
280
+ }
281
+ }
282
+
283
+ async function Step3() {
284
+ if (vaultBalance.length > 0) {
285
+ let contractObject = await sdk.fetchCuratedContractByName(contractTemplate.targetContract.name);
286
+ let mintable = contractObject.allowed(vaultBalance, contractObject);
287
+ if (mintable) {
288
+ performMint();
289
+ }
290
+ }
291
+ }
292
+
293
+ async function performMint() {
294
+ if (vaultData.tokenId) {
295
+ sdk.performMintChain(web3, vaultData.tokenId, contractTemplate.targetContract.name, updateLogCallback)
296
+ .then(result => {
297
+ updateLogCallback('Minting success', 'tokenId: ' + vaultData.tokenId);
298
+ })
299
+ .catch(error => {
300
+ updateLogCallback('', error.message);
301
+ });
302
+ }
303
+ }
304
+ ```
305
+ This example demonstrates the step-by-step process of creating a vault, refreshing its balance, validating mintability, and performing a mint using the Emblem Vault SDK.
61
306
 
package/src/abi/abi.json CHANGED
@@ -111,5 +111,5 @@
111
111
  "stateMutability": "view",
112
112
  "type": "function"
113
113
  }
114
- ]
114
+ ]
115
115
  }
package/src/utils.ts CHANGED
@@ -295,6 +295,9 @@ export function generateTemplate(record: any) {
295
295
  }
296
296
  } else if (recordName == "Bitcoin DeGods") {
297
297
  allowed = firstAsset.coin == "ordinalsbtc" && firstAsset.balance == 1 && firstAsset.project == "DeGods"
298
+ } else if (recordName == "dot_id" || recordName == "dot_bit") {
299
+ data = _this.filterNativeBalances({balances: data}, _this)
300
+ allowed = data[0].project == recordName
298
301
  } else if (PROJECTS_DATA.includes(recordName)) { // XCP
299
302
  allowed = !!NFT_DATA[assetName] &&
300
303
  NFT_DATA[assetName]["projectName"].toLowerCase() == recordName.toLowerCase() &&
@@ -1,15 +0,0 @@
1
- export declare const abi: {
2
- inputs: {
3
- internalType: string;
4
- name: string;
5
- type: string;
6
- }[];
7
- name: string;
8
- outputs: {
9
- internalType: string;
10
- name: string;
11
- type: string;
12
- }[];
13
- stateMutability: string;
14
- type: string;
15
- }[];