emblem-vault-sdk 2.9.0 → 2.9.2

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.
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ // ============================================================================
3
+ // Supported Chains
4
+ // ============================================================================
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.TORUS_SIGNER_API = exports.EMBLEM_API_2 = exports.EMBLEM_API_V2 = exports.ZERO_ADDRESS = exports.UNVAULTING_DIAMOND_ADDRESS = exports.HANDLER_CONTRACT_ADDRESS = exports.SUPPORTED_CHAINS = exports.SOLANA_CHAIN_IDENTIFIER = exports.POLYGON_MAINNET_CHAIN_ID = exports.ETHEREUM_MAINNET_CHAIN_ID = void 0;
7
+ exports.ETHEREUM_MAINNET_CHAIN_ID = 1;
8
+ exports.POLYGON_MAINNET_CHAIN_ID = 137;
9
+ exports.SOLANA_CHAIN_IDENTIFIER = 'solana';
10
+ exports.SUPPORTED_CHAINS = {
11
+ [exports.ETHEREUM_MAINNET_CHAIN_ID]: {
12
+ type: 'evm',
13
+ name: 'Ethereum Mainnet',
14
+ handlerContract: '0x23859b51117dbFBcdEf5b757028B18d7759a4460',
15
+ unvaultingContract: '0x214C964bBd3640971E111d3a994CbB89b296a9ad',
16
+ },
17
+ [exports.POLYGON_MAINNET_CHAIN_ID]: {
18
+ type: 'evm',
19
+ name: 'Polygon Mainnet',
20
+ handlerContract: '0x23859b51117dbFBcdEf5b757028B18d7759a4460',
21
+ unvaultingContract: '0x214C964bBd3640971E111d3a994CbB89b296a9ad',
22
+ },
23
+ };
24
+ // ============================================================================
25
+ // Contract Addresses (default to Ethereum mainnet)
26
+ // ============================================================================
27
+ exports.HANDLER_CONTRACT_ADDRESS = '0x23859b51117dbFBcdEf5b757028B18d7759a4460';
28
+ exports.UNVAULTING_DIAMOND_ADDRESS = '0x214C964bBd3640971E111d3a994CbB89b296a9ad';
29
+ exports.ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
30
+ // ============================================================================
31
+ // API Endpoints
32
+ // ============================================================================
33
+ exports.EMBLEM_API_V2 = 'https://v2.emblemvault.io';
34
+ exports.EMBLEM_API_2 = 'https://api2.emblemvault.io';
35
+ exports.TORUS_SIGNER_API = 'https://tor-us-signer-coval.vercel.app';
@@ -668143,7 +668143,7 @@
668143
668143
  "price": 1040.9323103174047,
668144
668144
  "lastPrice": 1314.8618656640904
668145
668145
  },
668146
- "video": "https://arweave.net/Fb7BMNWJQwNCrRxdw_dbMC01t6iSVUytBtg5LziOOlI/2o51ir_video.mp4\\",
668146
+ "video": "https://arweave.net/Fb7BMNWJQwNCrRxdw_dbMC01t6iSVUytBtg5LziOOlI/2o51ir_video.mp4",
668147
668147
  "projectProtocol": "Counterparty"
668148
668148
  },
668149
668149
  "DGAPEPE": {
package/dist/derive.js CHANGED
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
36
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
37
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -0,0 +1,298 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ Object.defineProperty(exports, "__esModule", { value: true });
45
+ exports.performMintEvm = performMintEvm;
46
+ exports.performClaimEvm = performClaimEvm;
47
+ exports.deleteVaultEvm = deleteVaultEvm;
48
+ const constants_1 = require("./constants");
49
+ const signing_messages_1 = require("./signing-messages");
50
+ const vault_utils_1 = require("./vault-utils");
51
+ const utils_1 = require("./utils");
52
+ const EVM_RPC_URLS = {
53
+ 1: 'https://eth.llamarpc.com',
54
+ 137: 'https://polygon-rpc.com',
55
+ };
56
+ function getEvmRpcUrl(chainId) {
57
+ return EVM_RPC_URLS[chainId] || EVM_RPC_URLS[1];
58
+ }
59
+ function performMintEvm(ctx, client, tokenId, chainId, callback) {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ var _a;
62
+ callback === null || callback === void 0 ? void 0 : callback('Initializing EVM signer...');
63
+ const { ethers } = yield Promise.resolve().then(() => __importStar(require('ethers')));
64
+ const provider = new ethers.providers.JsonRpcProvider(getEvmRpcUrl(chainId));
65
+ const wallet = yield client.toEthersWallet(provider);
66
+ (_a = wallet.setChainId) === null || _a === void 0 ? void 0 : _a.call(wallet, chainId);
67
+ callback === null || callback === void 0 ? void 0 : callback('Signing mint request...');
68
+ const mintMessage = (0, signing_messages_1.buildMintMessage)(tokenId);
69
+ const mintRequestSig = yield wallet.signMessage(mintMessage);
70
+ callback === null || callback === void 0 ? void 0 : callback('Getting remote mint signature...');
71
+ const remoteMintSig = yield requestRemoteMintSignature(ctx, tokenId, mintRequestSig, chainId);
72
+ callback === null || callback === void 0 ? void 0 : callback('Submitting mint transaction...');
73
+ const txHash = yield submitMintTransaction(wallet, remoteMintSig, chainId, callback);
74
+ callback === null || callback === void 0 ? void 0 : callback('Mint complete!', { txHash });
75
+ return { txHash, tokenId, chainId };
76
+ });
77
+ }
78
+ function performClaimEvm(ctx, client, tokenId, chainId, metadata, claimIdentifier, vaultIsV2, needsOnChainUnvault, callback) {
79
+ return __awaiter(this, void 0, void 0, function* () {
80
+ var _a, _b;
81
+ callback === null || callback === void 0 ? void 0 : callback('Initializing EVM signer...');
82
+ const { ethers } = yield Promise.resolve().then(() => __importStar(require('ethers')));
83
+ const provider = new ethers.providers.JsonRpcProvider(getEvmRpcUrl(chainId));
84
+ const wallet = yield client.toEthersWallet(provider);
85
+ (_a = wallet.setChainId) === null || _a === void 0 ? void 0 : _a.call(wallet, chainId);
86
+ // Determine if vault needs on-chain claim/unvault before getting keys
87
+ // For minted vaults (live=true, status=unclaimed), we must claim on-chain first
88
+ const isMinted = metadata.live === true || metadata.status === 'unclaimed';
89
+ const isAlreadyClaimed = metadata.status === 'claimed' || Boolean(metadata.claimedBy);
90
+ if (isMinted && !isAlreadyClaimed) {
91
+ if (needsOnChainUnvault) {
92
+ // V2 vault: use unvaultWithSignedPrice
93
+ yield performOnChainUnvault(ctx, wallet, tokenId, claimIdentifier, metadata.collectionAddress, chainId, callback);
94
+ }
95
+ else {
96
+ // Non-V2 vault: use handler's claim function
97
+ const targetContractAddress = ((_b = metadata.targetContract) === null || _b === void 0 ? void 0 : _b[chainId]) || metadata.collectionAddress;
98
+ if (targetContractAddress) {
99
+ callback === null || callback === void 0 ? void 0 : callback('Performing on-chain claim...');
100
+ yield performLegacyClaim(wallet, targetContractAddress, claimIdentifier, chainId, callback);
101
+ }
102
+ }
103
+ }
104
+ callback === null || callback === void 0 ? void 0 : callback('Signing claim message...');
105
+ const claimMessage = (0, signing_messages_1.buildClaimMessage)(claimIdentifier, vaultIsV2);
106
+ const signature = yield wallet.signMessage(claimMessage);
107
+ callback === null || callback === void 0 ? void 0 : callback('Requesting claim token...');
108
+ const jwt = yield requestClaimToken(tokenId, signature, chainId);
109
+ callback === null || callback === void 0 ? void 0 : callback('Requesting remote key...');
110
+ const decryptionKeys = yield ctx.requestRemoteKey(tokenId, jwt, callback);
111
+ if (!decryptionKeys) {
112
+ throw new Error('Failed to get decryption key');
113
+ }
114
+ callback === null || callback === void 0 ? void 0 : callback('Decrypting vault keys...');
115
+ return yield ctx.decryptVaultKeys(tokenId, decryptionKeys, callback);
116
+ });
117
+ }
118
+ function deleteVaultEvm(client, tokenId, chainId, callback) {
119
+ return __awaiter(this, void 0, void 0, function* () {
120
+ var _a;
121
+ callback === null || callback === void 0 ? void 0 : callback('Initializing EVM signer...');
122
+ const wallet = yield client.toEthersWallet(null);
123
+ (_a = wallet.setChainId) === null || _a === void 0 ? void 0 : _a.call(wallet, chainId);
124
+ callback === null || callback === void 0 ? void 0 : callback('Signing delete message...');
125
+ const deleteMessage = (0, signing_messages_1.buildDeleteMessage)(tokenId);
126
+ const signature = yield wallet.signMessage(deleteMessage);
127
+ callback === null || callback === void 0 ? void 0 : callback('Deleting vault...');
128
+ const response = yield fetch(`${constants_1.EMBLEM_API_2}/v2/delete`, {
129
+ method: 'POST',
130
+ headers: {
131
+ 'Content-Type': 'application/json',
132
+ service: 'evmetadata',
133
+ },
134
+ body: JSON.stringify({
135
+ tokenId,
136
+ signature,
137
+ chainId: chainId.toString(),
138
+ }),
139
+ });
140
+ if (!response.ok) {
141
+ const errorData = yield response.json().catch(() => ({}));
142
+ throw new Error(errorData.message || 'Failed to delete vault');
143
+ }
144
+ callback === null || callback === void 0 ? void 0 : callback('Vault deleted successfully');
145
+ return true;
146
+ });
147
+ }
148
+ function requestRemoteMintSignature(ctx, tokenId, signature, chainId) {
149
+ return __awaiter(this, void 0, void 0, function* () {
150
+ const url = `${ctx.baseUrl}/mint-curated`;
151
+ const remoteMintResponse = yield (0, utils_1.fetchData)(url, ctx.apiKey, 'POST', {
152
+ method: 'buyWithSignedPrice',
153
+ tokenId,
154
+ signature,
155
+ chainId: chainId.toString(),
156
+ });
157
+ if (remoteMintResponse.error) {
158
+ throw new Error(remoteMintResponse.error);
159
+ }
160
+ return remoteMintResponse;
161
+ });
162
+ }
163
+ function submitMintTransaction(wallet, remoteMintSig, chainId, callback) {
164
+ return __awaiter(this, void 0, void 0, function* () {
165
+ const { ethers } = yield Promise.resolve().then(() => __importStar(require('ethers')));
166
+ const handlerAddress = (0, vault_utils_1.getHandlerContractAddress)(chainId);
167
+ const priceBigInt = (0, utils_1.parseBigIntValue)(remoteMintSig._price);
168
+ const iface = new ethers.utils.Interface([
169
+ 'function buyWithSignedPrice(address _nftAddress, address _payment, uint256 _price, address _to, uint256 _tokenId, uint256 _nonce, bytes _signature, bytes serialNumber, uint256 _amount) payable'
170
+ ]);
171
+ const data = iface.encodeFunctionData('buyWithSignedPrice', [
172
+ remoteMintSig._nftAddress,
173
+ constants_1.ZERO_ADDRESS,
174
+ priceBigInt,
175
+ remoteMintSig._to,
176
+ (0, utils_1.parseBigIntValue)(remoteMintSig._tokenId),
177
+ (0, utils_1.parseBigIntValue)(remoteMintSig._nonce),
178
+ remoteMintSig._signature,
179
+ remoteMintSig.serialNumber,
180
+ BigInt(1),
181
+ ]);
182
+ const tx = yield wallet.sendTransaction({
183
+ to: handlerAddress,
184
+ data,
185
+ value: priceBigInt,
186
+ });
187
+ callback === null || callback === void 0 ? void 0 : callback('Waiting for confirmation...', { txHash: tx.hash });
188
+ yield tx.wait();
189
+ return tx.hash;
190
+ });
191
+ }
192
+ function performOnChainUnvault(ctx, wallet, tokenId, claimIdentifier, nftAddress, chainId, callback) {
193
+ return __awaiter(this, void 0, void 0, function* () {
194
+ callback === null || callback === void 0 ? void 0 : callback('Signing unvault request...');
195
+ // Sign with tokenId to match server expectation (server verifies "Unvault: " + req.body.tokenId)
196
+ const unvaultMessage = (0, signing_messages_1.buildUnvaultMessage)(tokenId);
197
+ const unvaultSignature = yield wallet.signMessage(unvaultMessage);
198
+ callback === null || callback === void 0 ? void 0 : callback('Requesting remote unvault signature...');
199
+ const remoteUnvaultSig = yield requestRemoteUnvaultSignature(ctx, tokenId, unvaultSignature, chainId);
200
+ callback === null || callback === void 0 ? void 0 : callback('Submitting on-chain unvault transaction...');
201
+ yield submitUnvaultTransaction(wallet, remoteUnvaultSig, nftAddress, chainId, callback);
202
+ callback === null || callback === void 0 ? void 0 : callback('On-chain unvault complete, retrieving keys...');
203
+ });
204
+ }
205
+ /**
206
+ * Perform legacy claim by calling the handler contract's claim function
207
+ * This is for non-V2 vaults that don't use signed price unvaulting
208
+ */
209
+ function performLegacyClaim(wallet, targetContractAddress, tokenId, chainId, callback) {
210
+ return __awaiter(this, void 0, void 0, function* () {
211
+ const { ethers } = yield Promise.resolve().then(() => __importStar(require('ethers')));
212
+ // Handler contract ABI for claim function
213
+ const HANDLER_CLAIM_ABI = [
214
+ 'function claim(address _nftAddress, uint256 _tokenId) external'
215
+ ];
216
+ const handlerAddress = (0, vault_utils_1.getHandlerContractAddress)(chainId);
217
+ const iface = new ethers.utils.Interface(HANDLER_CLAIM_ABI);
218
+ const data = iface.encodeFunctionData('claim', [
219
+ targetContractAddress,
220
+ BigInt(tokenId),
221
+ ]);
222
+ callback === null || callback === void 0 ? void 0 : callback('Submitting claim transaction...');
223
+ const tx = yield wallet.sendTransaction({
224
+ to: handlerAddress,
225
+ data,
226
+ });
227
+ callback === null || callback === void 0 ? void 0 : callback('Waiting for claim confirmation...', { txHash: tx.hash });
228
+ yield tx.wait();
229
+ callback === null || callback === void 0 ? void 0 : callback('On-chain claim complete!');
230
+ });
231
+ }
232
+ function requestRemoteUnvaultSignature(ctx, tokenId, signature, chainId) {
233
+ return __awaiter(this, void 0, void 0, function* () {
234
+ const response = yield fetch(`${ctx.baseUrl}/unvault-curated`, {
235
+ method: 'POST',
236
+ headers: { 'Content-Type': 'application/json' },
237
+ body: JSON.stringify({
238
+ method: 'unvaultWithSignedPrice',
239
+ tokenId,
240
+ signature,
241
+ chainId: chainId.toString(),
242
+ }),
243
+ });
244
+ const remoteUnvaultSig = yield response.json();
245
+ if (!(remoteUnvaultSig === null || remoteUnvaultSig === void 0 ? void 0 : remoteUnvaultSig.success)) {
246
+ throw new Error((remoteUnvaultSig === null || remoteUnvaultSig === void 0 ? void 0 : remoteUnvaultSig.msg) || (remoteUnvaultSig === null || remoteUnvaultSig === void 0 ? void 0 : remoteUnvaultSig.err) || 'Failed to get remote unvault signature');
247
+ }
248
+ return remoteUnvaultSig;
249
+ });
250
+ }
251
+ function submitUnvaultTransaction(wallet, remoteUnvaultSig, nftAddress, chainId, callback) {
252
+ return __awaiter(this, void 0, void 0, function* () {
253
+ const { ethers } = yield Promise.resolve().then(() => __importStar(require('ethers')));
254
+ const unvaultingAddress = (0, vault_utils_1.getUnvaultingContractAddress)(chainId);
255
+ const nftAddressToUse = nftAddress || remoteUnvaultSig._nftAddress;
256
+ const tokenId = (0, utils_1.parseBigIntValue)(remoteUnvaultSig._tokenId);
257
+ const nonce = (0, utils_1.parseBigIntValue)(remoteUnvaultSig._nonce);
258
+ const price = (0, utils_1.parseBigIntValue)(remoteUnvaultSig._price);
259
+ const timestamp = (0, utils_1.parseBigIntValue)(remoteUnvaultSig._timestamp);
260
+ const iface = new ethers.utils.Interface([
261
+ 'function unvaultWithSignedPrice(address _nftAddress, uint256 _tokenId, uint256 _nonce, address _payment, uint256 _price, bytes _signature, uint256 _timestamp) payable'
262
+ ]);
263
+ const data = iface.encodeFunctionData('unvaultWithSignedPrice', [
264
+ nftAddressToUse,
265
+ tokenId,
266
+ nonce,
267
+ constants_1.ZERO_ADDRESS,
268
+ price,
269
+ remoteUnvaultSig._signature,
270
+ timestamp,
271
+ ]);
272
+ const tx = yield wallet.sendTransaction({
273
+ to: unvaultingAddress,
274
+ data,
275
+ value: price,
276
+ });
277
+ callback === null || callback === void 0 ? void 0 : callback('Waiting for unvault confirmation...', { txHash: tx.hash });
278
+ yield tx.wait();
279
+ return tx.hash;
280
+ });
281
+ }
282
+ function requestClaimToken(tokenId, signature, chainId) {
283
+ return __awaiter(this, void 0, void 0, function* () {
284
+ const response = yield fetch(`${constants_1.TORUS_SIGNER_API}/sign`, {
285
+ method: 'POST',
286
+ headers: {
287
+ 'Content-Type': 'application/json',
288
+ chainid: chainId.toString(),
289
+ },
290
+ body: JSON.stringify({ signature, tokenId }),
291
+ });
292
+ const jwt = yield response.json();
293
+ if (!jwt || jwt.success === false) {
294
+ throw new Error((jwt === null || jwt === void 0 ? void 0 : jwt.debug) ? `Claim failed: ${JSON.stringify(jwt.debug)}` : 'Failed to get claim token');
295
+ }
296
+ return jwt;
297
+ });
298
+ }