emblem-vault-sdk 1.9.11 → 1.9.13
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/bundle.js +106 -40
- package/dist/derive.js +1 -1
- package/dist/index.js +37 -36
- package/dist/utils.js +66 -1
- package/docs/bundle.js +106 -40
- package/package.json +1 -1
- package/src/derive.ts +1 -1
- package/src/index.ts +39 -45
- package/src/utils.ts +72 -0
- package/types/index.d.ts +3 -15
- package/types/utils.d.ts +8 -0
package/dist/bundle.js
CHANGED
|
@@ -709408,7 +709408,7 @@ const getPsbtTxnSize = (phrase, psbtBase64) => {
|
|
|
709408
709408
|
hash: "0000000000000000000000000000000000000000000000000000000000000000",
|
|
709409
709409
|
index: i,
|
|
709410
709410
|
witnessUtxo: {
|
|
709411
|
-
script:
|
|
709411
|
+
script: p2sh.output || Buffer.alloc(0),
|
|
709412
709412
|
value: 100000,
|
|
709413
709413
|
},
|
|
709414
709414
|
redeemScript: (_a = p2sh.redeem) === null || _a === void 0 ? void 0 : _a.output,
|
|
@@ -709475,9 +709475,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
709475
709475
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
709476
709476
|
const bignumber_1 = require("@ethersproject/bignumber");
|
|
709477
709477
|
const utils_1 = require("./utils");
|
|
709478
|
-
const sats_connect_1 = require("sats-connect");
|
|
709479
709478
|
const derive_1 = require("./derive");
|
|
709480
|
-
const SDK_VERSION = '1.9.
|
|
709479
|
+
const SDK_VERSION = '1.9.13';
|
|
709481
709480
|
class EmblemVaultSDK {
|
|
709482
709481
|
constructor(apiKey, baseUrl) {
|
|
709483
709482
|
this.apiKey = apiKey;
|
|
@@ -709789,6 +709788,9 @@ class EmblemVaultSDK {
|
|
|
709789
709788
|
const chainId = yield web3.eth.getChainId();
|
|
709790
709789
|
let url = `${this.baseUrl}/mint-curated`;
|
|
709791
709790
|
let remoteMintResponse = yield (0, utils_1.fetchData)(url, this.apiKey, 'POST', { method: 'buyWithQuote', tokenId: tokenId, signature: signature, chainId: chainId.toString() });
|
|
709791
|
+
if (remoteMintResponse.error) {
|
|
709792
|
+
throw new Error(remoteMintResponse.error);
|
|
709793
|
+
}
|
|
709792
709794
|
if (callback) {
|
|
709793
709795
|
callback(`remote Mint signature`, remoteMintResponse);
|
|
709794
709796
|
}
|
|
@@ -709926,40 +709928,42 @@ class EmblemVaultSDK {
|
|
|
709926
709928
|
}));
|
|
709927
709929
|
});
|
|
709928
709930
|
}
|
|
709929
|
-
|
|
709930
|
-
getSatsConnectAddress() {
|
|
709931
|
+
checkLiveliness(tokenId, chainId = 1) {
|
|
709931
709932
|
return __awaiter(this, void 0, void 0, function* () {
|
|
709932
|
-
|
|
709933
|
-
|
|
709934
|
-
|
|
709935
|
-
|
|
709936
|
-
|
|
709937
|
-
|
|
709938
|
-
|
|
709939
|
-
|
|
709940
|
-
|
|
709941
|
-
|
|
709942
|
-
|
|
709943
|
-
|
|
709944
|
-
|
|
709945
|
-
|
|
709946
|
-
|
|
709947
|
-
|
|
709948
|
-
|
|
709949
|
-
|
|
709950
|
-
|
|
709951
|
-
|
|
709952
|
-
|
|
709953
|
-
|
|
709954
|
-
|
|
709955
|
-
}
|
|
709933
|
+
let url = `${this.baseUrl}/liveliness-curated/`;
|
|
709934
|
+
return yield (0, utils_1.fetchData)(url, this.apiKey, 'POST', { tokenId: tokenId }, { chainid: chainId, "Content-Type": "application/json" });
|
|
709935
|
+
});
|
|
709936
|
+
}
|
|
709937
|
+
checkLivelinessBulk(tokenIds, chainId = 1) {
|
|
709938
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
709939
|
+
const chunkSize = 20;
|
|
709940
|
+
let results = [];
|
|
709941
|
+
let url = `${this.baseUrl}/batch_liveliness/`;
|
|
709942
|
+
let apiKey = this.apiKey;
|
|
709943
|
+
function processChunks(i = 0, delay = 1000) {
|
|
709944
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
709945
|
+
if (i < tokenIds.length) {
|
|
709946
|
+
let chunk = tokenIds.slice(i, i + chunkSize);
|
|
709947
|
+
try {
|
|
709948
|
+
let result = yield (0, utils_1.fetchData)(url, apiKey, 'POST', { tokenIds: chunk }, { chainid: chainId, "Content-Type": "application/json" });
|
|
709949
|
+
results.push(result);
|
|
709950
|
+
processChunks(i + chunkSize);
|
|
709951
|
+
}
|
|
709952
|
+
catch (error) {
|
|
709953
|
+
console.error(`Error fetching data for chunk starting at index ${i}. Retrying in ${delay}ms...`, error);
|
|
709954
|
+
setTimeout(() => processChunks(i, delay * 2), delay);
|
|
709955
|
+
}
|
|
709956
|
+
}
|
|
709956
709957
|
});
|
|
709957
|
-
}
|
|
709958
|
+
}
|
|
709959
|
+
processChunks();
|
|
709960
|
+
return results;
|
|
709958
709961
|
});
|
|
709959
709962
|
}
|
|
709960
|
-
|
|
709963
|
+
// BTC
|
|
709964
|
+
sweepVaultUsingPhrase(phrase, satsPerByte = 20, broadcast = false) {
|
|
709961
709965
|
return __awaiter(this, void 0, void 0, function* () {
|
|
709962
|
-
const { paymentAddress, paymentPublicKey, ordinalsAddress } = yield
|
|
709966
|
+
const { paymentAddress, paymentPublicKey, ordinalsAddress } = yield (0, utils_1.getSatsConnectAddress)();
|
|
709963
709967
|
// change this to mainnet
|
|
709964
709968
|
if (window.bitcoin) {
|
|
709965
709969
|
let bitcoin = window.bitcoin;
|
|
@@ -710034,14 +710038,11 @@ class EmblemVaultSDK {
|
|
|
710034
710038
|
// send this to wallet to sign all indexes except the first one
|
|
710035
710039
|
const psbtBase64 = psbt.toBase64();
|
|
710036
710040
|
console.log(psbtBase64);
|
|
710041
|
+
let signedPsbt = yield (0, utils_1.signPSBT)(psbtBase64, paymentAddress, [...Array(paymentUtxos.length).keys()].map(i => i + taprootUtxos.length), broadcast);
|
|
710042
|
+
return signedPsbt;
|
|
710037
710043
|
}
|
|
710038
710044
|
});
|
|
710039
710045
|
}
|
|
710040
|
-
getTaprootAddressFromMnemonic(phrase) {
|
|
710041
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
710042
|
-
return (0, derive_1.generateTaprootAddressFromMnemonic)(phrase);
|
|
710043
|
-
});
|
|
710044
|
-
}
|
|
710045
710046
|
}
|
|
710046
710047
|
if (typeof window !== 'undefined') {
|
|
710047
710048
|
window.EmblemVaultSDK = EmblemVaultSDK;
|
|
@@ -710049,7 +710050,7 @@ if (typeof window !== 'undefined') {
|
|
|
710049
710050
|
exports.default = EmblemVaultSDK;
|
|
710050
710051
|
|
|
710051
710052
|
}).call(this)}).call(this,require("buffer").Buffer)
|
|
710052
|
-
},{"./derive":3,"./utils":5,"@ethersproject/bignumber":58,"buffer":203,"
|
|
710053
|
+
},{"./derive":3,"./utils":5,"@ethersproject/bignumber":58,"buffer":203,"web3":559}],5:[function(require,module,exports){
|
|
710053
710054
|
"use strict";
|
|
710054
710055
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
710055
710056
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -710064,10 +710065,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
710064
710065
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
710065
710066
|
};
|
|
710066
710067
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
710067
|
-
exports.decryptKeys = exports.getTorusKeys = exports.COIN_TO_NETWORK = exports.checkContentType = exports.getLegacyContract = exports.getHandlerContract = exports.getQuoteContractObject = exports.genericGuard = exports.templateGuard = exports.generateTemplate = exports.generateImageTemplate = exports.generateAttributeTemplate = exports.fetchData = exports.metadataAllProjects = exports.metadataObj2Arr = exports.evaluateFacts = exports.pad = exports.NFT_DATA = void 0;
|
|
710068
|
+
exports.signPSBT = exports.getSatsConnectAddress = exports.decryptKeys = exports.getTorusKeys = exports.COIN_TO_NETWORK = exports.checkContentType = exports.getLegacyContract = exports.getHandlerContract = exports.getQuoteContractObject = exports.genericGuard = exports.templateGuard = exports.generateTemplate = exports.generateImageTemplate = exports.generateAttributeTemplate = exports.fetchData = exports.metadataAllProjects = exports.metadataObj2Arr = exports.evaluateFacts = exports.pad = exports.NFT_DATA = void 0;
|
|
710068
710069
|
const crypto_js_1 = __importDefault(require("crypto-js"));
|
|
710069
710070
|
const metadata_json_1 = __importDefault(require("./curated/metadata.json"));
|
|
710070
710071
|
const abi_json_1 = __importDefault(require("./abi/abi.json"));
|
|
710072
|
+
const sats_connect_1 = require("sats-connect");
|
|
710071
710073
|
// import { phrasePathToKey } from './derive'
|
|
710072
710074
|
exports.NFT_DATA = metadata_json_1.default;
|
|
710073
710075
|
// PROJECTS_DATA is list of projects i.e. curated collection names
|
|
@@ -710776,8 +710778,72 @@ function decryptKeys(vaultCiphertextV2, keys, addresses) {
|
|
|
710776
710778
|
});
|
|
710777
710779
|
}
|
|
710778
710780
|
exports.decryptKeys = decryptKeys;
|
|
710781
|
+
function getSatsConnectAddress() {
|
|
710782
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
710783
|
+
return new Promise((resolve, reject) => {
|
|
710784
|
+
(0, sats_connect_1.getAddress)({
|
|
710785
|
+
payload: {
|
|
710786
|
+
purposes: [
|
|
710787
|
+
sats_connect_1.AddressPurpose.Ordinals,
|
|
710788
|
+
sats_connect_1.AddressPurpose.Payment,
|
|
710789
|
+
],
|
|
710790
|
+
message: "My App's Name",
|
|
710791
|
+
network: {
|
|
710792
|
+
type: sats_connect_1.BitcoinNetworkType.Mainnet,
|
|
710793
|
+
},
|
|
710794
|
+
},
|
|
710795
|
+
onFinish: (response) => {
|
|
710796
|
+
const paymentAddressItem = response.addresses.find((address) => address.purpose === sats_connect_1.AddressPurpose.Payment);
|
|
710797
|
+
const ordinalsAddressItem = response.addresses.find((address) => address.purpose === sats_connect_1.AddressPurpose.Ordinals);
|
|
710798
|
+
resolve({
|
|
710799
|
+
paymentAddress: (paymentAddressItem === null || paymentAddressItem === void 0 ? void 0 : paymentAddressItem.address) || "",
|
|
710800
|
+
paymentPublicKey: (paymentAddressItem === null || paymentAddressItem === void 0 ? void 0 : paymentAddressItem.publicKey) || "",
|
|
710801
|
+
ordinalsAddress: (ordinalsAddressItem === null || ordinalsAddressItem === void 0 ? void 0 : ordinalsAddressItem.address) || ""
|
|
710802
|
+
});
|
|
710803
|
+
},
|
|
710804
|
+
onCancel: () => {
|
|
710805
|
+
reject("Request canceled");
|
|
710806
|
+
},
|
|
710807
|
+
});
|
|
710808
|
+
});
|
|
710809
|
+
});
|
|
710810
|
+
}
|
|
710811
|
+
exports.getSatsConnectAddress = getSatsConnectAddress;
|
|
710812
|
+
function signPSBT(psbtBase64, paymentAddress, indexes, broadcast = false) {
|
|
710813
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
710814
|
+
return new Promise((resolve, reject) => {
|
|
710815
|
+
(0, sats_connect_1.signTransaction)({
|
|
710816
|
+
payload: {
|
|
710817
|
+
network: {
|
|
710818
|
+
type: sats_connect_1.BitcoinNetworkType.Mainnet,
|
|
710819
|
+
},
|
|
710820
|
+
message: "Sign Transaction",
|
|
710821
|
+
psbtBase64,
|
|
710822
|
+
broadcast: broadcast, // or false if you want to broadcast yourself
|
|
710823
|
+
inputsToSign: [
|
|
710824
|
+
{
|
|
710825
|
+
address: paymentAddress,
|
|
710826
|
+
signingIndexes: indexes, // this needs to match the number of inputs coming from the payment address
|
|
710827
|
+
sigHash: 1,
|
|
710828
|
+
},
|
|
710829
|
+
],
|
|
710830
|
+
},
|
|
710831
|
+
onFinish: (response) => {
|
|
710832
|
+
console.log('PSBT', response.psbtBase64);
|
|
710833
|
+
console.log('txid', response.txid); // only populated if broadcast is true
|
|
710834
|
+
resolve(response);
|
|
710835
|
+
},
|
|
710836
|
+
onCancel: () => {
|
|
710837
|
+
alert("Canceled");
|
|
710838
|
+
reject(new Error("Transaction cancelled"));
|
|
710839
|
+
},
|
|
710840
|
+
});
|
|
710841
|
+
});
|
|
710842
|
+
});
|
|
710843
|
+
}
|
|
710844
|
+
exports.signPSBT = signPSBT;
|
|
710779
710845
|
|
|
710780
|
-
},{"./abi/abi.json":1,"./curated/metadata.json":2,"@toruslabs/fetch-node-details":113,"@toruslabs/torus.js":115,"crypto-js":230}],6:[function(require,module,exports){
|
|
710846
|
+
},{"./abi/abi.json":1,"./curated/metadata.json":2,"@toruslabs/fetch-node-details":113,"@toruslabs/torus.js":115,"crypto-js":230,"sats-connect":457}],6:[function(require,module,exports){
|
|
710781
710847
|
var toPropertyKey = require("./toPropertyKey.js");
|
|
710782
710848
|
function _defineProperty(obj, key, value) {
|
|
710783
710849
|
key = toPropertyKey(key);
|
package/dist/derive.js
CHANGED
|
@@ -94,7 +94,7 @@ const getPsbtTxnSize = (phrase, psbtBase64) => {
|
|
|
94
94
|
hash: "0000000000000000000000000000000000000000000000000000000000000000",
|
|
95
95
|
index: i,
|
|
96
96
|
witnessUtxo: {
|
|
97
|
-
script:
|
|
97
|
+
script: p2sh.output || Buffer.alloc(0),
|
|
98
98
|
value: 100000,
|
|
99
99
|
},
|
|
100
100
|
redeemScript: (_a = p2sh.redeem) === null || _a === void 0 ? void 0 : _a.output,
|
package/dist/index.js
CHANGED
|
@@ -34,9 +34,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
35
|
const bignumber_1 = require("@ethersproject/bignumber");
|
|
36
36
|
const utils_1 = require("./utils");
|
|
37
|
-
const sats_connect_1 = require("sats-connect");
|
|
38
37
|
const derive_1 = require("./derive");
|
|
39
|
-
const SDK_VERSION = '1.9.
|
|
38
|
+
const SDK_VERSION = '1.9.13';
|
|
40
39
|
class EmblemVaultSDK {
|
|
41
40
|
constructor(apiKey, baseUrl) {
|
|
42
41
|
this.apiKey = apiKey;
|
|
@@ -348,6 +347,9 @@ class EmblemVaultSDK {
|
|
|
348
347
|
const chainId = yield web3.eth.getChainId();
|
|
349
348
|
let url = `${this.baseUrl}/mint-curated`;
|
|
350
349
|
let remoteMintResponse = yield (0, utils_1.fetchData)(url, this.apiKey, 'POST', { method: 'buyWithQuote', tokenId: tokenId, signature: signature, chainId: chainId.toString() });
|
|
350
|
+
if (remoteMintResponse.error) {
|
|
351
|
+
throw new Error(remoteMintResponse.error);
|
|
352
|
+
}
|
|
351
353
|
if (callback) {
|
|
352
354
|
callback(`remote Mint signature`, remoteMintResponse);
|
|
353
355
|
}
|
|
@@ -485,40 +487,42 @@ class EmblemVaultSDK {
|
|
|
485
487
|
}));
|
|
486
488
|
});
|
|
487
489
|
}
|
|
488
|
-
|
|
489
|
-
getSatsConnectAddress() {
|
|
490
|
+
checkLiveliness(tokenId, chainId = 1) {
|
|
490
491
|
return __awaiter(this, void 0, void 0, function* () {
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
}
|
|
492
|
+
let url = `${this.baseUrl}/liveliness-curated/`;
|
|
493
|
+
return yield (0, utils_1.fetchData)(url, this.apiKey, 'POST', { tokenId: tokenId }, { chainid: chainId, "Content-Type": "application/json" });
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
checkLivelinessBulk(tokenIds, chainId = 1) {
|
|
497
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
498
|
+
const chunkSize = 20;
|
|
499
|
+
let results = [];
|
|
500
|
+
let url = `${this.baseUrl}/batch_liveliness/`;
|
|
501
|
+
let apiKey = this.apiKey;
|
|
502
|
+
function processChunks(i = 0, delay = 1000) {
|
|
503
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
504
|
+
if (i < tokenIds.length) {
|
|
505
|
+
let chunk = tokenIds.slice(i, i + chunkSize);
|
|
506
|
+
try {
|
|
507
|
+
let result = yield (0, utils_1.fetchData)(url, apiKey, 'POST', { tokenIds: chunk }, { chainid: chainId, "Content-Type": "application/json" });
|
|
508
|
+
results.push(result);
|
|
509
|
+
processChunks(i + chunkSize);
|
|
510
|
+
}
|
|
511
|
+
catch (error) {
|
|
512
|
+
console.error(`Error fetching data for chunk starting at index ${i}. Retrying in ${delay}ms...`, error);
|
|
513
|
+
setTimeout(() => processChunks(i, delay * 2), delay);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
515
516
|
});
|
|
516
|
-
}
|
|
517
|
+
}
|
|
518
|
+
processChunks();
|
|
519
|
+
return results;
|
|
517
520
|
});
|
|
518
521
|
}
|
|
519
|
-
|
|
522
|
+
// BTC
|
|
523
|
+
sweepVaultUsingPhrase(phrase, satsPerByte = 20, broadcast = false) {
|
|
520
524
|
return __awaiter(this, void 0, void 0, function* () {
|
|
521
|
-
const { paymentAddress, paymentPublicKey, ordinalsAddress } = yield
|
|
525
|
+
const { paymentAddress, paymentPublicKey, ordinalsAddress } = yield (0, utils_1.getSatsConnectAddress)();
|
|
522
526
|
// change this to mainnet
|
|
523
527
|
if (window.bitcoin) {
|
|
524
528
|
let bitcoin = window.bitcoin;
|
|
@@ -593,14 +597,11 @@ class EmblemVaultSDK {
|
|
|
593
597
|
// send this to wallet to sign all indexes except the first one
|
|
594
598
|
const psbtBase64 = psbt.toBase64();
|
|
595
599
|
console.log(psbtBase64);
|
|
600
|
+
let signedPsbt = yield (0, utils_1.signPSBT)(psbtBase64, paymentAddress, [...Array(paymentUtxos.length).keys()].map(i => i + taprootUtxos.length), broadcast);
|
|
601
|
+
return signedPsbt;
|
|
596
602
|
}
|
|
597
603
|
});
|
|
598
604
|
}
|
|
599
|
-
getTaprootAddressFromMnemonic(phrase) {
|
|
600
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
601
|
-
return (0, derive_1.generateTaprootAddressFromMnemonic)(phrase);
|
|
602
|
-
});
|
|
603
|
-
}
|
|
604
605
|
}
|
|
605
606
|
if (typeof window !== 'undefined') {
|
|
606
607
|
window.EmblemVaultSDK = EmblemVaultSDK;
|
package/dist/utils.js
CHANGED
|
@@ -12,10 +12,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.decryptKeys = exports.getTorusKeys = exports.COIN_TO_NETWORK = exports.checkContentType = exports.getLegacyContract = exports.getHandlerContract = exports.getQuoteContractObject = exports.genericGuard = exports.templateGuard = exports.generateTemplate = exports.generateImageTemplate = exports.generateAttributeTemplate = exports.fetchData = exports.metadataAllProjects = exports.metadataObj2Arr = exports.evaluateFacts = exports.pad = exports.NFT_DATA = void 0;
|
|
15
|
+
exports.signPSBT = exports.getSatsConnectAddress = exports.decryptKeys = exports.getTorusKeys = exports.COIN_TO_NETWORK = exports.checkContentType = exports.getLegacyContract = exports.getHandlerContract = exports.getQuoteContractObject = exports.genericGuard = exports.templateGuard = exports.generateTemplate = exports.generateImageTemplate = exports.generateAttributeTemplate = exports.fetchData = exports.metadataAllProjects = exports.metadataObj2Arr = exports.evaluateFacts = exports.pad = exports.NFT_DATA = void 0;
|
|
16
16
|
const crypto_js_1 = __importDefault(require("crypto-js"));
|
|
17
17
|
const metadata_json_1 = __importDefault(require("./curated/metadata.json"));
|
|
18
18
|
const abi_json_1 = __importDefault(require("./abi/abi.json"));
|
|
19
|
+
const sats_connect_1 = require("sats-connect");
|
|
19
20
|
// import { phrasePathToKey } from './derive'
|
|
20
21
|
exports.NFT_DATA = metadata_json_1.default;
|
|
21
22
|
// PROJECTS_DATA is list of projects i.e. curated collection names
|
|
@@ -724,3 +725,67 @@ function decryptKeys(vaultCiphertextV2, keys, addresses) {
|
|
|
724
725
|
});
|
|
725
726
|
}
|
|
726
727
|
exports.decryptKeys = decryptKeys;
|
|
728
|
+
function getSatsConnectAddress() {
|
|
729
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
730
|
+
return new Promise((resolve, reject) => {
|
|
731
|
+
(0, sats_connect_1.getAddress)({
|
|
732
|
+
payload: {
|
|
733
|
+
purposes: [
|
|
734
|
+
sats_connect_1.AddressPurpose.Ordinals,
|
|
735
|
+
sats_connect_1.AddressPurpose.Payment,
|
|
736
|
+
],
|
|
737
|
+
message: "My App's Name",
|
|
738
|
+
network: {
|
|
739
|
+
type: sats_connect_1.BitcoinNetworkType.Mainnet,
|
|
740
|
+
},
|
|
741
|
+
},
|
|
742
|
+
onFinish: (response) => {
|
|
743
|
+
const paymentAddressItem = response.addresses.find((address) => address.purpose === sats_connect_1.AddressPurpose.Payment);
|
|
744
|
+
const ordinalsAddressItem = response.addresses.find((address) => address.purpose === sats_connect_1.AddressPurpose.Ordinals);
|
|
745
|
+
resolve({
|
|
746
|
+
paymentAddress: (paymentAddressItem === null || paymentAddressItem === void 0 ? void 0 : paymentAddressItem.address) || "",
|
|
747
|
+
paymentPublicKey: (paymentAddressItem === null || paymentAddressItem === void 0 ? void 0 : paymentAddressItem.publicKey) || "",
|
|
748
|
+
ordinalsAddress: (ordinalsAddressItem === null || ordinalsAddressItem === void 0 ? void 0 : ordinalsAddressItem.address) || ""
|
|
749
|
+
});
|
|
750
|
+
},
|
|
751
|
+
onCancel: () => {
|
|
752
|
+
reject("Request canceled");
|
|
753
|
+
},
|
|
754
|
+
});
|
|
755
|
+
});
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
exports.getSatsConnectAddress = getSatsConnectAddress;
|
|
759
|
+
function signPSBT(psbtBase64, paymentAddress, indexes, broadcast = false) {
|
|
760
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
761
|
+
return new Promise((resolve, reject) => {
|
|
762
|
+
(0, sats_connect_1.signTransaction)({
|
|
763
|
+
payload: {
|
|
764
|
+
network: {
|
|
765
|
+
type: sats_connect_1.BitcoinNetworkType.Mainnet,
|
|
766
|
+
},
|
|
767
|
+
message: "Sign Transaction",
|
|
768
|
+
psbtBase64,
|
|
769
|
+
broadcast: broadcast, // or false if you want to broadcast yourself
|
|
770
|
+
inputsToSign: [
|
|
771
|
+
{
|
|
772
|
+
address: paymentAddress,
|
|
773
|
+
signingIndexes: indexes, // this needs to match the number of inputs coming from the payment address
|
|
774
|
+
sigHash: 1,
|
|
775
|
+
},
|
|
776
|
+
],
|
|
777
|
+
},
|
|
778
|
+
onFinish: (response) => {
|
|
779
|
+
console.log('PSBT', response.psbtBase64);
|
|
780
|
+
console.log('txid', response.txid); // only populated if broadcast is true
|
|
781
|
+
resolve(response);
|
|
782
|
+
},
|
|
783
|
+
onCancel: () => {
|
|
784
|
+
alert("Canceled");
|
|
785
|
+
reject(new Error("Transaction cancelled"));
|
|
786
|
+
},
|
|
787
|
+
});
|
|
788
|
+
});
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
exports.signPSBT = signPSBT;
|
package/docs/bundle.js
CHANGED
|
@@ -709408,7 +709408,7 @@ const getPsbtTxnSize = (phrase, psbtBase64) => {
|
|
|
709408
709408
|
hash: "0000000000000000000000000000000000000000000000000000000000000000",
|
|
709409
709409
|
index: i,
|
|
709410
709410
|
witnessUtxo: {
|
|
709411
|
-
script:
|
|
709411
|
+
script: p2sh.output || Buffer.alloc(0),
|
|
709412
709412
|
value: 100000,
|
|
709413
709413
|
},
|
|
709414
709414
|
redeemScript: (_a = p2sh.redeem) === null || _a === void 0 ? void 0 : _a.output,
|
|
@@ -709475,9 +709475,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
709475
709475
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
709476
709476
|
const bignumber_1 = require("@ethersproject/bignumber");
|
|
709477
709477
|
const utils_1 = require("./utils");
|
|
709478
|
-
const sats_connect_1 = require("sats-connect");
|
|
709479
709478
|
const derive_1 = require("./derive");
|
|
709480
|
-
const SDK_VERSION = '1.9.
|
|
709479
|
+
const SDK_VERSION = '1.9.13';
|
|
709481
709480
|
class EmblemVaultSDK {
|
|
709482
709481
|
constructor(apiKey, baseUrl) {
|
|
709483
709482
|
this.apiKey = apiKey;
|
|
@@ -709789,6 +709788,9 @@ class EmblemVaultSDK {
|
|
|
709789
709788
|
const chainId = yield web3.eth.getChainId();
|
|
709790
709789
|
let url = `${this.baseUrl}/mint-curated`;
|
|
709791
709790
|
let remoteMintResponse = yield (0, utils_1.fetchData)(url, this.apiKey, 'POST', { method: 'buyWithQuote', tokenId: tokenId, signature: signature, chainId: chainId.toString() });
|
|
709791
|
+
if (remoteMintResponse.error) {
|
|
709792
|
+
throw new Error(remoteMintResponse.error);
|
|
709793
|
+
}
|
|
709792
709794
|
if (callback) {
|
|
709793
709795
|
callback(`remote Mint signature`, remoteMintResponse);
|
|
709794
709796
|
}
|
|
@@ -709926,40 +709928,42 @@ class EmblemVaultSDK {
|
|
|
709926
709928
|
}));
|
|
709927
709929
|
});
|
|
709928
709930
|
}
|
|
709929
|
-
|
|
709930
|
-
getSatsConnectAddress() {
|
|
709931
|
+
checkLiveliness(tokenId, chainId = 1) {
|
|
709931
709932
|
return __awaiter(this, void 0, void 0, function* () {
|
|
709932
|
-
|
|
709933
|
-
|
|
709934
|
-
|
|
709935
|
-
|
|
709936
|
-
|
|
709937
|
-
|
|
709938
|
-
|
|
709939
|
-
|
|
709940
|
-
|
|
709941
|
-
|
|
709942
|
-
|
|
709943
|
-
|
|
709944
|
-
|
|
709945
|
-
|
|
709946
|
-
|
|
709947
|
-
|
|
709948
|
-
|
|
709949
|
-
|
|
709950
|
-
|
|
709951
|
-
|
|
709952
|
-
|
|
709953
|
-
|
|
709954
|
-
|
|
709955
|
-
}
|
|
709933
|
+
let url = `${this.baseUrl}/liveliness-curated/`;
|
|
709934
|
+
return yield (0, utils_1.fetchData)(url, this.apiKey, 'POST', { tokenId: tokenId }, { chainid: chainId, "Content-Type": "application/json" });
|
|
709935
|
+
});
|
|
709936
|
+
}
|
|
709937
|
+
checkLivelinessBulk(tokenIds, chainId = 1) {
|
|
709938
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
709939
|
+
const chunkSize = 20;
|
|
709940
|
+
let results = [];
|
|
709941
|
+
let url = `${this.baseUrl}/batch_liveliness/`;
|
|
709942
|
+
let apiKey = this.apiKey;
|
|
709943
|
+
function processChunks(i = 0, delay = 1000) {
|
|
709944
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
709945
|
+
if (i < tokenIds.length) {
|
|
709946
|
+
let chunk = tokenIds.slice(i, i + chunkSize);
|
|
709947
|
+
try {
|
|
709948
|
+
let result = yield (0, utils_1.fetchData)(url, apiKey, 'POST', { tokenIds: chunk }, { chainid: chainId, "Content-Type": "application/json" });
|
|
709949
|
+
results.push(result);
|
|
709950
|
+
processChunks(i + chunkSize);
|
|
709951
|
+
}
|
|
709952
|
+
catch (error) {
|
|
709953
|
+
console.error(`Error fetching data for chunk starting at index ${i}. Retrying in ${delay}ms...`, error);
|
|
709954
|
+
setTimeout(() => processChunks(i, delay * 2), delay);
|
|
709955
|
+
}
|
|
709956
|
+
}
|
|
709956
709957
|
});
|
|
709957
|
-
}
|
|
709958
|
+
}
|
|
709959
|
+
processChunks();
|
|
709960
|
+
return results;
|
|
709958
709961
|
});
|
|
709959
709962
|
}
|
|
709960
|
-
|
|
709963
|
+
// BTC
|
|
709964
|
+
sweepVaultUsingPhrase(phrase, satsPerByte = 20, broadcast = false) {
|
|
709961
709965
|
return __awaiter(this, void 0, void 0, function* () {
|
|
709962
|
-
const { paymentAddress, paymentPublicKey, ordinalsAddress } = yield
|
|
709966
|
+
const { paymentAddress, paymentPublicKey, ordinalsAddress } = yield (0, utils_1.getSatsConnectAddress)();
|
|
709963
709967
|
// change this to mainnet
|
|
709964
709968
|
if (window.bitcoin) {
|
|
709965
709969
|
let bitcoin = window.bitcoin;
|
|
@@ -710034,14 +710038,11 @@ class EmblemVaultSDK {
|
|
|
710034
710038
|
// send this to wallet to sign all indexes except the first one
|
|
710035
710039
|
const psbtBase64 = psbt.toBase64();
|
|
710036
710040
|
console.log(psbtBase64);
|
|
710041
|
+
let signedPsbt = yield (0, utils_1.signPSBT)(psbtBase64, paymentAddress, [...Array(paymentUtxos.length).keys()].map(i => i + taprootUtxos.length), broadcast);
|
|
710042
|
+
return signedPsbt;
|
|
710037
710043
|
}
|
|
710038
710044
|
});
|
|
710039
710045
|
}
|
|
710040
|
-
getTaprootAddressFromMnemonic(phrase) {
|
|
710041
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
710042
|
-
return (0, derive_1.generateTaprootAddressFromMnemonic)(phrase);
|
|
710043
|
-
});
|
|
710044
|
-
}
|
|
710045
710046
|
}
|
|
710046
710047
|
if (typeof window !== 'undefined') {
|
|
710047
710048
|
window.EmblemVaultSDK = EmblemVaultSDK;
|
|
@@ -710049,7 +710050,7 @@ if (typeof window !== 'undefined') {
|
|
|
710049
710050
|
exports.default = EmblemVaultSDK;
|
|
710050
710051
|
|
|
710051
710052
|
}).call(this)}).call(this,require("buffer").Buffer)
|
|
710052
|
-
},{"./derive":3,"./utils":5,"@ethersproject/bignumber":58,"buffer":203,"
|
|
710053
|
+
},{"./derive":3,"./utils":5,"@ethersproject/bignumber":58,"buffer":203,"web3":559}],5:[function(require,module,exports){
|
|
710053
710054
|
"use strict";
|
|
710054
710055
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
710055
710056
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -710064,10 +710065,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
710064
710065
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
710065
710066
|
};
|
|
710066
710067
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
710067
|
-
exports.decryptKeys = exports.getTorusKeys = exports.COIN_TO_NETWORK = exports.checkContentType = exports.getLegacyContract = exports.getHandlerContract = exports.getQuoteContractObject = exports.genericGuard = exports.templateGuard = exports.generateTemplate = exports.generateImageTemplate = exports.generateAttributeTemplate = exports.fetchData = exports.metadataAllProjects = exports.metadataObj2Arr = exports.evaluateFacts = exports.pad = exports.NFT_DATA = void 0;
|
|
710068
|
+
exports.signPSBT = exports.getSatsConnectAddress = exports.decryptKeys = exports.getTorusKeys = exports.COIN_TO_NETWORK = exports.checkContentType = exports.getLegacyContract = exports.getHandlerContract = exports.getQuoteContractObject = exports.genericGuard = exports.templateGuard = exports.generateTemplate = exports.generateImageTemplate = exports.generateAttributeTemplate = exports.fetchData = exports.metadataAllProjects = exports.metadataObj2Arr = exports.evaluateFacts = exports.pad = exports.NFT_DATA = void 0;
|
|
710068
710069
|
const crypto_js_1 = __importDefault(require("crypto-js"));
|
|
710069
710070
|
const metadata_json_1 = __importDefault(require("./curated/metadata.json"));
|
|
710070
710071
|
const abi_json_1 = __importDefault(require("./abi/abi.json"));
|
|
710072
|
+
const sats_connect_1 = require("sats-connect");
|
|
710071
710073
|
// import { phrasePathToKey } from './derive'
|
|
710072
710074
|
exports.NFT_DATA = metadata_json_1.default;
|
|
710073
710075
|
// PROJECTS_DATA is list of projects i.e. curated collection names
|
|
@@ -710776,8 +710778,72 @@ function decryptKeys(vaultCiphertextV2, keys, addresses) {
|
|
|
710776
710778
|
});
|
|
710777
710779
|
}
|
|
710778
710780
|
exports.decryptKeys = decryptKeys;
|
|
710781
|
+
function getSatsConnectAddress() {
|
|
710782
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
710783
|
+
return new Promise((resolve, reject) => {
|
|
710784
|
+
(0, sats_connect_1.getAddress)({
|
|
710785
|
+
payload: {
|
|
710786
|
+
purposes: [
|
|
710787
|
+
sats_connect_1.AddressPurpose.Ordinals,
|
|
710788
|
+
sats_connect_1.AddressPurpose.Payment,
|
|
710789
|
+
],
|
|
710790
|
+
message: "My App's Name",
|
|
710791
|
+
network: {
|
|
710792
|
+
type: sats_connect_1.BitcoinNetworkType.Mainnet,
|
|
710793
|
+
},
|
|
710794
|
+
},
|
|
710795
|
+
onFinish: (response) => {
|
|
710796
|
+
const paymentAddressItem = response.addresses.find((address) => address.purpose === sats_connect_1.AddressPurpose.Payment);
|
|
710797
|
+
const ordinalsAddressItem = response.addresses.find((address) => address.purpose === sats_connect_1.AddressPurpose.Ordinals);
|
|
710798
|
+
resolve({
|
|
710799
|
+
paymentAddress: (paymentAddressItem === null || paymentAddressItem === void 0 ? void 0 : paymentAddressItem.address) || "",
|
|
710800
|
+
paymentPublicKey: (paymentAddressItem === null || paymentAddressItem === void 0 ? void 0 : paymentAddressItem.publicKey) || "",
|
|
710801
|
+
ordinalsAddress: (ordinalsAddressItem === null || ordinalsAddressItem === void 0 ? void 0 : ordinalsAddressItem.address) || ""
|
|
710802
|
+
});
|
|
710803
|
+
},
|
|
710804
|
+
onCancel: () => {
|
|
710805
|
+
reject("Request canceled");
|
|
710806
|
+
},
|
|
710807
|
+
});
|
|
710808
|
+
});
|
|
710809
|
+
});
|
|
710810
|
+
}
|
|
710811
|
+
exports.getSatsConnectAddress = getSatsConnectAddress;
|
|
710812
|
+
function signPSBT(psbtBase64, paymentAddress, indexes, broadcast = false) {
|
|
710813
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
710814
|
+
return new Promise((resolve, reject) => {
|
|
710815
|
+
(0, sats_connect_1.signTransaction)({
|
|
710816
|
+
payload: {
|
|
710817
|
+
network: {
|
|
710818
|
+
type: sats_connect_1.BitcoinNetworkType.Mainnet,
|
|
710819
|
+
},
|
|
710820
|
+
message: "Sign Transaction",
|
|
710821
|
+
psbtBase64,
|
|
710822
|
+
broadcast: broadcast, // or false if you want to broadcast yourself
|
|
710823
|
+
inputsToSign: [
|
|
710824
|
+
{
|
|
710825
|
+
address: paymentAddress,
|
|
710826
|
+
signingIndexes: indexes, // this needs to match the number of inputs coming from the payment address
|
|
710827
|
+
sigHash: 1,
|
|
710828
|
+
},
|
|
710829
|
+
],
|
|
710830
|
+
},
|
|
710831
|
+
onFinish: (response) => {
|
|
710832
|
+
console.log('PSBT', response.psbtBase64);
|
|
710833
|
+
console.log('txid', response.txid); // only populated if broadcast is true
|
|
710834
|
+
resolve(response);
|
|
710835
|
+
},
|
|
710836
|
+
onCancel: () => {
|
|
710837
|
+
alert("Canceled");
|
|
710838
|
+
reject(new Error("Transaction cancelled"));
|
|
710839
|
+
},
|
|
710840
|
+
});
|
|
710841
|
+
});
|
|
710842
|
+
});
|
|
710843
|
+
}
|
|
710844
|
+
exports.signPSBT = signPSBT;
|
|
710779
710845
|
|
|
710780
|
-
},{"./abi/abi.json":1,"./curated/metadata.json":2,"@toruslabs/fetch-node-details":113,"@toruslabs/torus.js":115,"crypto-js":230}],6:[function(require,module,exports){
|
|
710846
|
+
},{"./abi/abi.json":1,"./curated/metadata.json":2,"@toruslabs/fetch-node-details":113,"@toruslabs/torus.js":115,"crypto-js":230,"sats-connect":457}],6:[function(require,module,exports){
|
|
710781
710847
|
var toPropertyKey = require("./toPropertyKey.js");
|
|
710782
710848
|
function _defineProperty(obj, key, value) {
|
|
710783
710849
|
key = toPropertyKey(key);
|
package/package.json
CHANGED
package/src/derive.ts
CHANGED
|
@@ -82,7 +82,7 @@ export const getPsbtTxnSize = (phrase: string, psbtBase64: string) => {
|
|
|
82
82
|
hash: "0000000000000000000000000000000000000000000000000000000000000000",
|
|
83
83
|
index: i,
|
|
84
84
|
witnessUtxo: {
|
|
85
|
-
script:
|
|
85
|
+
script: p2sh.output || Buffer.alloc(0),
|
|
86
86
|
value: 100000,
|
|
87
87
|
},
|
|
88
88
|
redeemScript: p2sh.redeem?.output,
|
package/src/index.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { BigNumber } from '@ethersproject/bignumber'
|
|
2
2
|
import { Collection, CuratedCollectionsResponse, MetaData, Vault } from './types';
|
|
3
|
-
import { COIN_TO_NETWORK, NFT_DATA, checkContentType, decryptKeys, evaluateFacts, fetchData, generateTemplate, genericGuard, getHandlerContract, getLegacyContract, getQuoteContractObject, getTorusKeys, metadataAllProjects, metadataObj2Arr, pad, templateGuard } from './utils';
|
|
4
|
-
import { getAddress, BitcoinNetworkType, AddressPurpose } from "sats-connect";
|
|
3
|
+
import { COIN_TO_NETWORK, NFT_DATA, checkContentType, decryptKeys, evaluateFacts, fetchData, generateTemplate, genericGuard, getHandlerContract, getLegacyContract, getQuoteContractObject, getSatsConnectAddress, getTorusKeys, metadataAllProjects, metadataObj2Arr, pad, signPSBT, templateGuard } from './utils';
|
|
4
|
+
import { getAddress, BitcoinNetworkType, AddressPurpose, signTransaction } from "sats-connect";
|
|
5
5
|
import { generateTaprootAddressFromMnemonic, getPsbtTxnSize } from './derive';
|
|
6
6
|
const SDK_VERSION = '__SDK_VERSION__';
|
|
7
|
-
|
|
8
|
-
paymentAddress: string;
|
|
9
|
-
paymentPublicKey: string;
|
|
10
|
-
ordinalsAddress: string;
|
|
11
|
-
}
|
|
7
|
+
|
|
12
8
|
class EmblemVaultSDK {
|
|
13
9
|
private baseUrl: string;
|
|
14
10
|
private v3Url: string;
|
|
@@ -289,6 +285,9 @@ class EmblemVaultSDK {
|
|
|
289
285
|
const chainId = await web3.eth.getChainId();
|
|
290
286
|
let url = `${this.baseUrl}/mint-curated`;
|
|
291
287
|
let remoteMintResponse = await fetchData(url, this.apiKey, 'POST', {method: 'buyWithQuote', tokenId: tokenId, signature: signature, chainId: chainId.toString()});
|
|
288
|
+
if (remoteMintResponse.error) {
|
|
289
|
+
throw new Error(remoteMintResponse.error)
|
|
290
|
+
}
|
|
292
291
|
if (callback) { callback(`remote Mint signature`, remoteMintResponse)}
|
|
293
292
|
return remoteMintResponse
|
|
294
293
|
}
|
|
@@ -411,44 +410,39 @@ class EmblemVaultSDK {
|
|
|
411
410
|
})
|
|
412
411
|
}
|
|
413
412
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
return
|
|
417
|
-
getAddress({
|
|
418
|
-
payload: {
|
|
419
|
-
purposes: [
|
|
420
|
-
AddressPurpose.Ordinals,
|
|
421
|
-
AddressPurpose.Payment,
|
|
422
|
-
],
|
|
423
|
-
message: "My App's Name",
|
|
424
|
-
network: {
|
|
425
|
-
type: BitcoinNetworkType.Mainnet,
|
|
426
|
-
},
|
|
427
|
-
},
|
|
428
|
-
onFinish: (response) => {
|
|
429
|
-
const paymentAddressItem = response.addresses.find(
|
|
430
|
-
(address) => address.purpose === AddressPurpose.Payment
|
|
431
|
-
);
|
|
432
|
-
|
|
433
|
-
const ordinalsAddressItem = response.addresses.find(
|
|
434
|
-
(address) => address.purpose === AddressPurpose.Ordinals
|
|
435
|
-
);
|
|
436
|
-
resolve({
|
|
437
|
-
paymentAddress: paymentAddressItem?.address || "",
|
|
438
|
-
paymentPublicKey: paymentAddressItem?.publicKey || "",
|
|
439
|
-
ordinalsAddress: ordinalsAddressItem?.address || ""
|
|
440
|
-
});
|
|
441
|
-
},
|
|
442
|
-
onCancel: () => {
|
|
443
|
-
reject("Request canceled");
|
|
444
|
-
},
|
|
445
|
-
});
|
|
446
|
-
});
|
|
413
|
+
async checkLiveliness(tokenId: string, chainId: number = 1) {
|
|
414
|
+
let url = `${this.baseUrl}/liveliness-curated/`;
|
|
415
|
+
return await fetchData(url, this.apiKey, 'POST', {tokenId: tokenId}, {chainid: chainId, "Content-Type":"application/json"});
|
|
447
416
|
}
|
|
448
417
|
|
|
449
|
-
async
|
|
418
|
+
async checkLivelinessBulk(tokenIds: string[], chainId: number = 1){
|
|
419
|
+
const chunkSize = 20;
|
|
420
|
+
let results: any[] = [];
|
|
421
|
+
let url = `${this.baseUrl}/batch_liveliness/`;
|
|
422
|
+
let apiKey = this.apiKey;
|
|
423
|
+
async function processChunks(i = 0, delay = 1000) {
|
|
424
|
+
if (i < tokenIds.length) {
|
|
425
|
+
let chunk = tokenIds.slice(i, i + chunkSize);
|
|
426
|
+
|
|
427
|
+
try {
|
|
428
|
+
let result = await fetchData(url, apiKey, 'POST', {tokenIds: chunk}, {chainid: chainId, "Content-Type":"application/json"});
|
|
429
|
+
results.push(result);
|
|
430
|
+
processChunks(i + chunkSize);
|
|
431
|
+
} catch (error) {
|
|
432
|
+
console.error(`Error fetching data for chunk starting at index ${i}. Retrying in ${delay}ms...`, error);
|
|
433
|
+
setTimeout(() => processChunks(i, delay * 2), delay);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
processChunks();
|
|
438
|
+
return results;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// BTC
|
|
450
442
|
|
|
451
|
-
|
|
443
|
+
async sweepVaultUsingPhrase(phrase: string, satsPerByte: number = 20, broadcast: boolean = false) {
|
|
444
|
+
|
|
445
|
+
const { paymentAddress, paymentPublicKey, ordinalsAddress } = await getSatsConnectAddress();
|
|
452
446
|
|
|
453
447
|
// change this to mainnet
|
|
454
448
|
if (window.bitcoin) {
|
|
@@ -545,13 +539,13 @@ class EmblemVaultSDK {
|
|
|
545
539
|
const psbtBase64 = psbt.toBase64();
|
|
546
540
|
|
|
547
541
|
console.log(psbtBase64);
|
|
542
|
+
|
|
543
|
+
let signedPsbt = await signPSBT(psbtBase64, paymentAddress, [...Array(paymentUtxos.length).keys()].map(i => i + taprootUtxos.length), broadcast);
|
|
544
|
+
return signedPsbt;
|
|
548
545
|
}
|
|
549
546
|
|
|
550
547
|
}
|
|
551
548
|
|
|
552
|
-
async getTaprootAddressFromMnemonic(phrase: string) {
|
|
553
|
-
return generateTaprootAddressFromMnemonic(phrase)
|
|
554
|
-
}
|
|
555
549
|
}
|
|
556
550
|
|
|
557
551
|
declare global {
|
package/src/utils.ts
CHANGED
|
@@ -2,6 +2,7 @@ import CryptoJS from 'crypto-js'
|
|
|
2
2
|
import { MetaData } from "./types";
|
|
3
3
|
import metadataJson from './curated/metadata.json';
|
|
4
4
|
import abi from './abi/abi.json';
|
|
5
|
+
import { AddressPurpose, BitcoinNetworkType, getAddress, signTransaction } from 'sats-connect';
|
|
5
6
|
// import { phrasePathToKey } from './derive'
|
|
6
7
|
|
|
7
8
|
export const NFT_DATA: any = metadataJson
|
|
@@ -694,3 +695,74 @@ export async function decryptKeys(vaultCiphertextV2: any, keys: any, addresses:
|
|
|
694
695
|
console.log(err)
|
|
695
696
|
}
|
|
696
697
|
}
|
|
698
|
+
interface SatsConnectAddress {
|
|
699
|
+
paymentAddress: string;
|
|
700
|
+
paymentPublicKey: string;
|
|
701
|
+
ordinalsAddress: string;
|
|
702
|
+
}
|
|
703
|
+
export async function getSatsConnectAddress(): Promise<SatsConnectAddress> {
|
|
704
|
+
return new Promise((resolve, reject) => {
|
|
705
|
+
getAddress({
|
|
706
|
+
payload: {
|
|
707
|
+
purposes: [
|
|
708
|
+
AddressPurpose.Ordinals,
|
|
709
|
+
AddressPurpose.Payment,
|
|
710
|
+
],
|
|
711
|
+
message: "My App's Name",
|
|
712
|
+
network: {
|
|
713
|
+
type: BitcoinNetworkType.Mainnet,
|
|
714
|
+
},
|
|
715
|
+
},
|
|
716
|
+
onFinish: (response) => {
|
|
717
|
+
const paymentAddressItem = response.addresses.find(
|
|
718
|
+
(address) => address.purpose === AddressPurpose.Payment
|
|
719
|
+
);
|
|
720
|
+
|
|
721
|
+
const ordinalsAddressItem = response.addresses.find(
|
|
722
|
+
(address) => address.purpose === AddressPurpose.Ordinals
|
|
723
|
+
);
|
|
724
|
+
resolve({
|
|
725
|
+
paymentAddress: paymentAddressItem?.address || "",
|
|
726
|
+
paymentPublicKey: paymentAddressItem?.publicKey || "",
|
|
727
|
+
ordinalsAddress: ordinalsAddressItem?.address || ""
|
|
728
|
+
});
|
|
729
|
+
},
|
|
730
|
+
onCancel: () => {
|
|
731
|
+
reject("Request canceled");
|
|
732
|
+
},
|
|
733
|
+
});
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
export async function signPSBT(psbtBase64: any, paymentAddress: any, indexes: number[], broadcast: boolean = false) {
|
|
738
|
+
return new Promise((resolve, reject) => {
|
|
739
|
+
signTransaction({
|
|
740
|
+
payload: {
|
|
741
|
+
network: {
|
|
742
|
+
type: BitcoinNetworkType.Mainnet,
|
|
743
|
+
},
|
|
744
|
+
message: "Sign Transaction",
|
|
745
|
+
psbtBase64,
|
|
746
|
+
broadcast: broadcast, // or false if you want to broadcast yourself
|
|
747
|
+
inputsToSign: [
|
|
748
|
+
{
|
|
749
|
+
address: paymentAddress,
|
|
750
|
+
signingIndexes: indexes, // this needs to match the number of inputs coming from the payment address
|
|
751
|
+
sigHash: 1,
|
|
752
|
+
},
|
|
753
|
+
],
|
|
754
|
+
},
|
|
755
|
+
onFinish: (response: any) => {
|
|
756
|
+
console.log('PSBT', response.psbtBase64);
|
|
757
|
+
console.log('txid', response.txid); // only populated if broadcast is true
|
|
758
|
+
resolve(response);
|
|
759
|
+
},
|
|
760
|
+
onCancel: () => {
|
|
761
|
+
alert("Canceled");
|
|
762
|
+
reject(new Error("Transaction cancelled"));
|
|
763
|
+
},
|
|
764
|
+
});
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
|
package/types/index.d.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { BigNumber } from '@ethersproject/bignumber';
|
|
3
2
|
import { Collection, CuratedCollectionsResponse, MetaData, Vault } from './types';
|
|
4
|
-
interface SatsConnectAddress {
|
|
5
|
-
paymentAddress: string;
|
|
6
|
-
paymentPublicKey: string;
|
|
7
|
-
ordinalsAddress: string;
|
|
8
|
-
}
|
|
9
3
|
declare class EmblemVaultSDK {
|
|
10
4
|
private apiKey;
|
|
11
5
|
private baseUrl;
|
|
@@ -45,15 +39,9 @@ declare class EmblemVaultSDK {
|
|
|
45
39
|
contentTypeReport(url: string): Promise<unknown>;
|
|
46
40
|
legacyBalanceFromContractByAddress(web3: any, address: string): Promise<number[]>;
|
|
47
41
|
refreshLegacyOwnership(web3: any, address: string): Promise<void>;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
p2tr: any;
|
|
52
|
-
tweakedSigner: import("bip32/types/bip32").Signer;
|
|
53
|
-
pubKey: Buffer;
|
|
54
|
-
path: string;
|
|
55
|
-
coin: string;
|
|
56
|
-
}>;
|
|
42
|
+
checkLiveliness(tokenId: string, chainId?: number): Promise<any>;
|
|
43
|
+
checkLivelinessBulk(tokenIds: string[], chainId?: number): Promise<any[]>;
|
|
44
|
+
sweepVaultUsingPhrase(phrase: string, satsPerByte?: number, broadcast?: boolean): Promise<unknown>;
|
|
57
45
|
}
|
|
58
46
|
declare global {
|
|
59
47
|
interface Window {
|
package/types/utils.d.ts
CHANGED
|
@@ -33,3 +33,11 @@ export declare function getTorusKeys(verifierId: string, idToken: any, cb?: any)
|
|
|
33
33
|
privateKey: any;
|
|
34
34
|
}>;
|
|
35
35
|
export declare function decryptKeys(vaultCiphertextV2: any, keys: any, addresses: any[]): Promise<any>;
|
|
36
|
+
interface SatsConnectAddress {
|
|
37
|
+
paymentAddress: string;
|
|
38
|
+
paymentPublicKey: string;
|
|
39
|
+
ordinalsAddress: string;
|
|
40
|
+
}
|
|
41
|
+
export declare function getSatsConnectAddress(): Promise<SatsConnectAddress>;
|
|
42
|
+
export declare function signPSBT(psbtBase64: any, paymentAddress: any, indexes: number[], broadcast?: boolean): Promise<unknown>;
|
|
43
|
+
export {};
|