@cityofzion/bs-ethereum 1.2.3 → 1.3.0
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/BSEthereum.d.ts +1 -1
- package/dist/BSEthereum.js +27 -18
- package/dist/BitqueryEDSEthereum.d.ts +2 -2
- package/dist/BitqueryEDSEthereum.js +3 -1
- package/dist/GhostMarketNDSEthereum.d.ts +4 -3
- package/dist/GhostMarketNDSEthereum.js +5 -3
- package/dist/LedgerServiceEthereum.d.ts +12 -3
- package/dist/LedgerServiceEthereum.js +110 -22
- package/dist/RpcNDSEthereum.d.ts +8 -0
- package/dist/RpcNDSEthereum.js +49 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +2 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +4 -2
package/dist/BSEthereum.d.ts
CHANGED
|
@@ -23,6 +23,6 @@ export declare class BSEthereum<BSCustomName extends string = string> implements
|
|
|
23
23
|
decrypt(json: string, password: string): Promise<Account>;
|
|
24
24
|
encrypt(key: string, password: string): Promise<string>;
|
|
25
25
|
transfer(param: TransferParam): Promise<string>;
|
|
26
|
-
calculateTransferFee(
|
|
26
|
+
calculateTransferFee(param: TransferParam): Promise<string>;
|
|
27
27
|
resolveNameServiceDomain(domainName: string): Promise<string>;
|
|
28
28
|
}
|
package/dist/BSEthereum.js
CHANGED
|
@@ -66,7 +66,7 @@ class BSEthereum {
|
|
|
66
66
|
this.blockchainDataService = new BitqueryBDSEthereum_1.BitqueryBDSEthereum(network);
|
|
67
67
|
}
|
|
68
68
|
this.exchangeDataService = new BitqueryEDSEthereum_1.BitqueryEDSEthereum(network.type);
|
|
69
|
-
this.nftDataService = new GhostMarketNDSEthereum_1.GhostMarketNDSEthereum(network
|
|
69
|
+
this.nftDataService = new GhostMarketNDSEthereum_1.GhostMarketNDSEthereum(network);
|
|
70
70
|
}
|
|
71
71
|
validateAddress(address) {
|
|
72
72
|
return ethers_1.ethers.utils.isAddress(address);
|
|
@@ -144,13 +144,12 @@ class BSEthereum {
|
|
|
144
144
|
throw new Error('You must provide getLedgerTransport function to use Ledger');
|
|
145
145
|
ledgerTransport = yield this.ledgerService.getLedgerTransport(param.senderAccount);
|
|
146
146
|
}
|
|
147
|
-
let
|
|
147
|
+
let signer;
|
|
148
148
|
if (ledgerTransport) {
|
|
149
|
-
|
|
149
|
+
signer = new LedgerServiceEthereum_1.LedgerSigner(ledgerTransport, provider);
|
|
150
150
|
}
|
|
151
151
|
else {
|
|
152
|
-
|
|
153
|
-
signTransactionFunction = wallet.signTransaction.bind(wallet);
|
|
152
|
+
signer = new ethers_1.ethers.Wallet(param.senderAccount.key, provider);
|
|
154
153
|
}
|
|
155
154
|
const decimals = (_a = param.intent.tokenDecimals) !== null && _a !== void 0 ? _a : 18;
|
|
156
155
|
const amount = ethersBigNumber.parseFixed(param.intent.amount, decimals);
|
|
@@ -168,29 +167,39 @@ class BSEthereum {
|
|
|
168
167
|
]);
|
|
169
168
|
transactionParams = yield contract.populateTransaction.transfer(param.intent.receiverAddress, amount);
|
|
170
169
|
}
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
const signedTransaction = yield signTransactionFunction(transaction);
|
|
174
|
-
const transactionResponse = yield provider.sendTransaction(signedTransaction);
|
|
175
|
-
return transactionResponse.hash;
|
|
170
|
+
const transaction = yield signer.sendTransaction(transactionParams);
|
|
171
|
+
return transaction.hash;
|
|
176
172
|
});
|
|
177
173
|
}
|
|
178
|
-
calculateTransferFee(
|
|
174
|
+
calculateTransferFee(param) {
|
|
179
175
|
var _a;
|
|
180
176
|
return __awaiter(this, void 0, void 0, function* () {
|
|
181
177
|
const provider = new ethers_1.ethers.providers.JsonRpcProvider(this.network.url);
|
|
178
|
+
let ledgerTransport;
|
|
179
|
+
if (param.isLedger) {
|
|
180
|
+
if (!this.ledgerService.getLedgerTransport)
|
|
181
|
+
throw new Error('You must provide getLedgerTransport function to use Ledger');
|
|
182
|
+
ledgerTransport = yield this.ledgerService.getLedgerTransport(param.senderAccount);
|
|
183
|
+
}
|
|
184
|
+
let signer;
|
|
185
|
+
if (ledgerTransport) {
|
|
186
|
+
signer = new LedgerServiceEthereum_1.LedgerSigner(ledgerTransport, provider);
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
signer = new ethers_1.ethers.Wallet(param.senderAccount.key, provider);
|
|
190
|
+
}
|
|
182
191
|
const gasPrice = yield provider.getGasPrice();
|
|
183
192
|
let estimated;
|
|
184
|
-
const isNative = constants_1.NATIVE_ASSETS.some(asset => asset.hash === intent.tokenHash);
|
|
185
|
-
const decimals = (_a = intent.tokenDecimals) !== null && _a !== void 0 ? _a : 18;
|
|
186
|
-
const amount = ethersBigNumber.parseFixed(intent.amount, decimals);
|
|
193
|
+
const isNative = constants_1.NATIVE_ASSETS.some(asset => asset.hash === param.intent.tokenHash);
|
|
194
|
+
const decimals = (_a = param.intent.tokenDecimals) !== null && _a !== void 0 ? _a : 18;
|
|
195
|
+
const amount = ethersBigNumber.parseFixed(param.intent.amount, decimals);
|
|
187
196
|
if (!isNative) {
|
|
188
|
-
const contract = new ethers_1.ethers.Contract(intent.tokenHash, ['function transfer(address to, uint amount) returns (bool)'],
|
|
189
|
-
estimated = yield contract.estimateGas.transfer(intent.receiverAddress, amount);
|
|
197
|
+
const contract = new ethers_1.ethers.Contract(param.intent.tokenHash, ['function transfer(address to, uint amount) returns (bool)'], signer);
|
|
198
|
+
estimated = yield contract.estimateGas.transfer(param.intent.receiverAddress, amount);
|
|
190
199
|
}
|
|
191
200
|
else {
|
|
192
|
-
estimated = yield
|
|
193
|
-
to: intent.receiverAddress,
|
|
201
|
+
estimated = yield signer.estimateGas({
|
|
202
|
+
to: param.intent.receiverAddress,
|
|
194
203
|
value: amount,
|
|
195
204
|
});
|
|
196
205
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Currency, ExchangeDataService, NetworkType, TokenPricesResponse } from '@cityofzion/blockchain-service';
|
|
2
|
-
export declare class BitqueryEDSEthereum implements ExchangeDataService {
|
|
1
|
+
import { CryptoCompareEDS, Currency, ExchangeDataService, NetworkType, TokenPricesResponse } from '@cityofzion/blockchain-service';
|
|
2
|
+
export declare class BitqueryEDSEthereum extends CryptoCompareEDS implements ExchangeDataService {
|
|
3
3
|
#private;
|
|
4
4
|
constructor(networkType: NetworkType);
|
|
5
5
|
getTokenPrices(currency: Currency): Promise<TokenPricesResponse[]>;
|
|
@@ -25,13 +25,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
25
25
|
var _BitqueryEDSEthereum_client, _BitqueryEDSEthereum_networkType;
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
27
|
exports.BitqueryEDSEthereum = void 0;
|
|
28
|
+
const blockchain_service_1 = require("@cityofzion/blockchain-service");
|
|
28
29
|
const axios_1 = __importDefault(require("axios"));
|
|
29
30
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
30
31
|
const utc_1 = __importDefault(require("dayjs/plugin/utc"));
|
|
31
32
|
const constants_1 = require("./constants");
|
|
32
33
|
dayjs_1.default.extend(utc_1.default);
|
|
33
|
-
class BitqueryEDSEthereum {
|
|
34
|
+
class BitqueryEDSEthereum extends blockchain_service_1.CryptoCompareEDS {
|
|
34
35
|
constructor(networkType) {
|
|
36
|
+
super(networkType, constants_1.TOKENS[networkType]);
|
|
35
37
|
_BitqueryEDSEthereum_client.set(this, void 0);
|
|
36
38
|
_BitqueryEDSEthereum_networkType.set(this, void 0);
|
|
37
39
|
__classPrivateFieldSet(this, _BitqueryEDSEthereum_networkType, networkType, "f");
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { NftResponse, NftsResponse,
|
|
2
|
-
|
|
1
|
+
import { NftResponse, NftsResponse, GetNftParam, GetNftsByAddressParams, Network } from '@cityofzion/blockchain-service';
|
|
2
|
+
import { RpcNDSEthereum } from './RpcNDSEthereum';
|
|
3
|
+
export declare class GhostMarketNDSEthereum extends RpcNDSEthereum {
|
|
3
4
|
#private;
|
|
4
|
-
constructor(
|
|
5
|
+
constructor(network: Network);
|
|
5
6
|
getNftsByAddress({ address, size, cursor }: GetNftsByAddressParams): Promise<NftsResponse>;
|
|
6
7
|
getNft({ contractHash, tokenId }: GetNftParam): Promise<NftResponse>;
|
|
7
8
|
private treatGhostMarketImage;
|
|
@@ -28,10 +28,12 @@ exports.GhostMarketNDSEthereum = void 0;
|
|
|
28
28
|
const query_string_1 = __importDefault(require("query-string"));
|
|
29
29
|
const axios_1 = __importDefault(require("axios"));
|
|
30
30
|
const constants_1 = require("./constants");
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
const RpcNDSEthereum_1 = require("./RpcNDSEthereum");
|
|
32
|
+
class GhostMarketNDSEthereum extends RpcNDSEthereum_1.RpcNDSEthereum {
|
|
33
|
+
constructor(network) {
|
|
34
|
+
super(network);
|
|
33
35
|
_GhostMarketNDSEthereum_networkType.set(this, void 0);
|
|
34
|
-
__classPrivateFieldSet(this, _GhostMarketNDSEthereum_networkType,
|
|
36
|
+
__classPrivateFieldSet(this, _GhostMarketNDSEthereum_networkType, network.type, "f");
|
|
35
37
|
}
|
|
36
38
|
getNftsByAddress({ address, size = 18, cursor }) {
|
|
37
39
|
var _a;
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import { Account, LedgerService } from '@cityofzion/blockchain-service';
|
|
2
2
|
import Transport from '@ledgerhq/hw-transport';
|
|
3
|
-
import { ethers } from 'ethers';
|
|
3
|
+
import { ethers, Signer } from 'ethers';
|
|
4
|
+
import { TypedDataSigner } from '@ethersproject/abstract-signer';
|
|
4
5
|
export declare class LedgerServiceEthereum implements LedgerService {
|
|
5
|
-
#private;
|
|
6
6
|
getLedgerTransport?: ((account: Account) => Promise<Transport>) | undefined;
|
|
7
7
|
constructor(getLedgerTransport?: ((account: Account) => Promise<Transport>) | undefined);
|
|
8
8
|
getAddress(transport: Transport): Promise<string>;
|
|
9
9
|
getPublicKey(transport: Transport): Promise<string>;
|
|
10
|
-
|
|
10
|
+
}
|
|
11
|
+
export declare class LedgerSigner extends Signer implements TypedDataSigner {
|
|
12
|
+
#private;
|
|
13
|
+
constructor(transport: Transport, provider?: ethers.providers.Provider);
|
|
14
|
+
connect(provider: ethers.providers.Provider): LedgerSigner;
|
|
15
|
+
getAddress(): Promise<string>;
|
|
16
|
+
getPublicKey(): Promise<string>;
|
|
17
|
+
signMessage(message: string | ethers.utils.Bytes): Promise<string>;
|
|
18
|
+
signTransaction(transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>): Promise<string>;
|
|
19
|
+
_signTypedData(domain: ethers.TypedDataDomain, types: Record<string, ethers.TypedDataField[]>, value: Record<string, any>): Promise<string>;
|
|
11
20
|
}
|
|
@@ -31,51 +31,139 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
31
31
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
35
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
36
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
37
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
38
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
39
|
+
};
|
|
34
40
|
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
35
41
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
36
42
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
37
43
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
38
44
|
};
|
|
39
|
-
var
|
|
45
|
+
var _LedgerSigner_instances, _LedgerSigner_transport, _LedgerSigner_path, _LedgerSigner_retry;
|
|
40
46
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
-
exports.LedgerServiceEthereum = void 0;
|
|
47
|
+
exports.LedgerSigner = exports.LedgerServiceEthereum = void 0;
|
|
42
48
|
const hw_app_eth_1 = __importStar(require("@ledgerhq/hw-app-eth"));
|
|
43
49
|
const ethers_1 = require("ethers");
|
|
50
|
+
const properties_1 = require("@ethersproject/properties");
|
|
51
|
+
const constants_1 = require("./constants");
|
|
44
52
|
class LedgerServiceEthereum {
|
|
45
53
|
constructor(getLedgerTransport) {
|
|
46
54
|
this.getLedgerTransport = getLedgerTransport;
|
|
47
|
-
_LedgerServiceEthereum_defaultPath.set(this, "44'/60'/0'/0/0");
|
|
48
55
|
}
|
|
49
56
|
getAddress(transport) {
|
|
50
57
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
return address;
|
|
58
|
+
const signer = new LedgerSigner(transport);
|
|
59
|
+
return yield signer.getAddress();
|
|
54
60
|
});
|
|
55
61
|
}
|
|
56
62
|
getPublicKey(transport) {
|
|
57
63
|
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
-
const
|
|
59
|
-
|
|
64
|
+
const signer = new LedgerSigner(transport);
|
|
65
|
+
return yield signer.getPublicKey();
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.LedgerServiceEthereum = LedgerServiceEthereum;
|
|
70
|
+
function wait(duration) {
|
|
71
|
+
return new Promise(resolve => {
|
|
72
|
+
setTimeout(resolve, duration);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
class LedgerSigner extends ethers_1.Signer {
|
|
76
|
+
constructor(transport, provider) {
|
|
77
|
+
super();
|
|
78
|
+
_LedgerSigner_instances.add(this);
|
|
79
|
+
_LedgerSigner_transport.set(this, void 0);
|
|
80
|
+
_LedgerSigner_path.set(this, void 0);
|
|
81
|
+
__classPrivateFieldSet(this, _LedgerSigner_path, constants_1.DEFAULT_PATH, "f");
|
|
82
|
+
__classPrivateFieldSet(this, _LedgerSigner_transport, transport, "f");
|
|
83
|
+
(0, properties_1.defineReadOnly)(this, 'provider', provider);
|
|
84
|
+
}
|
|
85
|
+
connect(provider) {
|
|
86
|
+
return new LedgerSigner(__classPrivateFieldGet(this, _LedgerSigner_transport, "f"), provider);
|
|
87
|
+
}
|
|
88
|
+
getAddress() {
|
|
89
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
const ledgerApp = new hw_app_eth_1.default(__classPrivateFieldGet(this, _LedgerSigner_transport, "f"));
|
|
91
|
+
const { address } = yield __classPrivateFieldGet(this, _LedgerSigner_instances, "m", _LedgerSigner_retry).call(this, () => ledgerApp.getAddress(__classPrivateFieldGet(this, _LedgerSigner_path, "f")));
|
|
92
|
+
return ethers_1.ethers.utils.getAddress(address);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
getPublicKey() {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
const ledgerApp = new hw_app_eth_1.default(__classPrivateFieldGet(this, _LedgerSigner_transport, "f"));
|
|
98
|
+
const { publicKey } = yield __classPrivateFieldGet(this, _LedgerSigner_instances, "m", _LedgerSigner_retry).call(this, () => ledgerApp.getAddress(__classPrivateFieldGet(this, _LedgerSigner_path, "f")));
|
|
60
99
|
return '0x' + publicKey;
|
|
61
100
|
});
|
|
62
101
|
}
|
|
63
|
-
|
|
102
|
+
signMessage(message) {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
if (typeof message === 'string') {
|
|
105
|
+
message = ethers_1.ethers.utils.toUtf8Bytes(message);
|
|
106
|
+
}
|
|
107
|
+
const ledgerApp = new hw_app_eth_1.default(__classPrivateFieldGet(this, _LedgerSigner_transport, "f"));
|
|
108
|
+
const obj = yield __classPrivateFieldGet(this, _LedgerSigner_instances, "m", _LedgerSigner_retry).call(this, () => ledgerApp.signPersonalMessage(__classPrivateFieldGet(this, _LedgerSigner_path, "f"), ethers_1.ethers.utils.hexlify(message).substring(2)));
|
|
109
|
+
// Normalize the signature for Ethers
|
|
110
|
+
obj.r = '0x' + obj.r;
|
|
111
|
+
obj.s = '0x' + obj.s;
|
|
112
|
+
return ethers_1.ethers.utils.joinSignature(obj);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
signTransaction(transaction) {
|
|
64
116
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
});
|
|
117
|
+
const ledgerApp = new hw_app_eth_1.default(__classPrivateFieldGet(this, _LedgerSigner_transport, "f"));
|
|
118
|
+
const tx = yield ethers_1.ethers.utils.resolveProperties(transaction);
|
|
119
|
+
const unsignedTransaction = Object.assign(Object.assign({}, tx), { nonce: tx.nonce ? ethers_1.ethers.BigNumber.from(transaction.nonce).toNumber() : undefined });
|
|
120
|
+
const serializedUnsignedTransaction = ethers_1.ethers.utils.serializeTransaction(unsignedTransaction).substring(2);
|
|
121
|
+
const resolution = yield hw_app_eth_1.ledgerService.resolveTransaction(serializedUnsignedTransaction, {}, {});
|
|
122
|
+
const signature = yield __classPrivateFieldGet(this, _LedgerSigner_instances, "m", _LedgerSigner_retry).call(this, () => ledgerApp.signTransaction(__classPrivateFieldGet(this, _LedgerSigner_path, "f"), serializedUnsignedTransaction, resolution));
|
|
123
|
+
return ethers_1.ethers.utils.serializeTransaction(unsignedTransaction, {
|
|
124
|
+
v: ethers_1.ethers.BigNumber.from('0x' + signature.v).toNumber(),
|
|
125
|
+
r: '0x' + signature.r,
|
|
126
|
+
s: '0x' + signature.s,
|
|
76
127
|
});
|
|
77
128
|
});
|
|
78
129
|
}
|
|
130
|
+
_signTypedData(domain, types, value) {
|
|
131
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
const populated = yield ethers_1.ethers.utils._TypedDataEncoder.resolveNames(domain, types, value, (name) => __awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
if (!this.provider)
|
|
134
|
+
throw new Error('Cannot resolve ENS names without a provider');
|
|
135
|
+
const resolved = yield this.provider.resolveName(name);
|
|
136
|
+
if (!resolved)
|
|
137
|
+
throw new Error('No address found for domain name');
|
|
138
|
+
return resolved;
|
|
139
|
+
}));
|
|
140
|
+
const payload = ethers_1.ethers.utils._TypedDataEncoder.getPayload(populated.domain, types, populated.value);
|
|
141
|
+
const ledgerApp = new hw_app_eth_1.default(__classPrivateFieldGet(this, _LedgerSigner_transport, "f"));
|
|
142
|
+
const obj = yield __classPrivateFieldGet(this, _LedgerSigner_instances, "m", _LedgerSigner_retry).call(this, () => ledgerApp.signEIP712Message(__classPrivateFieldGet(this, _LedgerSigner_path, "f"), payload));
|
|
143
|
+
// Normalize the signature for Ethers
|
|
144
|
+
obj.r = '0x' + obj.r;
|
|
145
|
+
obj.s = '0x' + obj.s;
|
|
146
|
+
return ethers_1.ethers.utils.joinSignature(obj);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
79
149
|
}
|
|
80
|
-
exports.
|
|
81
|
-
|
|
150
|
+
exports.LedgerSigner = LedgerSigner;
|
|
151
|
+
_LedgerSigner_transport = new WeakMap(), _LedgerSigner_path = new WeakMap(), _LedgerSigner_instances = new WeakSet(), _LedgerSigner_retry = function _LedgerSigner_retry(callback) {
|
|
152
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
153
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
154
|
+
// Wait up to 5 seconds
|
|
155
|
+
for (let i = 0; i < 50; i++) {
|
|
156
|
+
try {
|
|
157
|
+
const result = yield callback();
|
|
158
|
+
return resolve(result);
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
if (error.id !== 'TransportLocked') {
|
|
162
|
+
return reject(error);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
yield wait(100);
|
|
166
|
+
}
|
|
167
|
+
return reject(new Error('timeout'));
|
|
168
|
+
}));
|
|
169
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { GetNftParam, GetNftsByAddressParams, HasTokenParam, Network, NftDataService, NftResponse, NftsResponse } from '@cityofzion/blockchain-service';
|
|
2
|
+
export declare abstract class RpcNDSEthereum implements NftDataService {
|
|
3
|
+
#private;
|
|
4
|
+
protected constructor(network: Network);
|
|
5
|
+
abstract getNftsByAddress(params: GetNftsByAddressParams): Promise<NftsResponse>;
|
|
6
|
+
abstract getNft(params: GetNftParam): Promise<NftResponse>;
|
|
7
|
+
hasToken({ contractHash, address }: HasTokenParam): Promise<boolean>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
12
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
13
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
14
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
15
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
16
|
+
};
|
|
17
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
18
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
19
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
20
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
|
+
};
|
|
22
|
+
var _RpcNDSEthereum_network;
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.RpcNDSEthereum = void 0;
|
|
25
|
+
const ethers_1 = require("ethers");
|
|
26
|
+
class RpcNDSEthereum {
|
|
27
|
+
constructor(network) {
|
|
28
|
+
_RpcNDSEthereum_network.set(this, void 0);
|
|
29
|
+
__classPrivateFieldSet(this, _RpcNDSEthereum_network, network, "f");
|
|
30
|
+
}
|
|
31
|
+
hasToken({ contractHash, address }) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
try {
|
|
34
|
+
const provider = new ethers_1.ethers.providers.JsonRpcProvider(__classPrivateFieldGet(this, _RpcNDSEthereum_network, "f").url);
|
|
35
|
+
const contract = new ethers_1.ethers.Contract(contractHash, ['function balanceOf(address _owner) external view returns (uint256)'], provider);
|
|
36
|
+
const response = yield contract.balanceOf(address);
|
|
37
|
+
if (!response)
|
|
38
|
+
throw new Error();
|
|
39
|
+
const parsedResponse = response;
|
|
40
|
+
return parsedResponse.gt(0);
|
|
41
|
+
}
|
|
42
|
+
catch (_a) {
|
|
43
|
+
throw new Error(`Token not found: ${contractHash}`);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.RpcNDSEthereum = RpcNDSEthereum;
|
|
49
|
+
_RpcNDSEthereum_network = new WeakMap();
|
package/dist/constants.d.ts
CHANGED
|
@@ -14,3 +14,4 @@ export declare const GHOSTMARKET_CHAIN_BY_NETWORK_TYPE: Partial<Record<NetworkTy
|
|
|
14
14
|
export declare const DERIVATION_PATH = "m/44'/60'/0'/0/?";
|
|
15
15
|
export declare const RPC_LIST_BY_NETWORK_TYPE: Record<NetworkType, string[]>;
|
|
16
16
|
export declare const DEFAULT_URL_BY_NETWORK_TYPE: Record<NetworkType, string>;
|
|
17
|
+
export declare const DEFAULT_PATH = "44'/60'/0'/0/0";
|
package/dist/constants.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.DEFAULT_URL_BY_NETWORK_TYPE = exports.RPC_LIST_BY_NETWORK_TYPE = exports.DERIVATION_PATH = exports.GHOSTMARKET_CHAIN_BY_NETWORK_TYPE = exports.GHOSTMARKET_URL_BY_NETWORK_TYPE = exports.BITQUERY_MIRROR_NETWORK_BY_NETWORK_TYPE = exports.BITQUERY_MIRROR_URL = exports.NATIVE_ASSETS = exports.TOKENS = void 0;
|
|
6
|
+
exports.DEFAULT_PATH = exports.DEFAULT_URL_BY_NETWORK_TYPE = exports.RPC_LIST_BY_NETWORK_TYPE = exports.DERIVATION_PATH = exports.GHOSTMARKET_CHAIN_BY_NETWORK_TYPE = exports.GHOSTMARKET_URL_BY_NETWORK_TYPE = exports.BITQUERY_MIRROR_NETWORK_BY_NETWORK_TYPE = exports.BITQUERY_MIRROR_URL = exports.NATIVE_ASSETS = exports.TOKENS = void 0;
|
|
7
7
|
const common_json_1 = __importDefault(require("./assets/tokens/common.json"));
|
|
8
8
|
exports.TOKENS = {
|
|
9
9
|
mainnet: [...common_json_1.default],
|
|
@@ -49,3 +49,4 @@ exports.DEFAULT_URL_BY_NETWORK_TYPE = {
|
|
|
49
49
|
testnet: exports.RPC_LIST_BY_NETWORK_TYPE.testnet[0],
|
|
50
50
|
custom: exports.RPC_LIST_BY_NETWORK_TYPE.custom[0],
|
|
51
51
|
};
|
|
52
|
+
exports.DEFAULT_PATH = "44'/60'/0'/0/0";
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -20,3 +20,4 @@ __exportStar(require("./constants"), exports);
|
|
|
20
20
|
__exportStar(require("./BitqueryBDSEthereum"), exports);
|
|
21
21
|
__exportStar(require("./BitqueryEDSEthereum"), exports);
|
|
22
22
|
__exportStar(require("./RpcBDSEthereum"), exports);
|
|
23
|
+
__exportStar(require("./LedgerServiceEthereum"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cityofzion/bs-ethereum",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"repository": "https://github.com/CityOfZion/blockchain-services",
|
|
@@ -21,7 +21,9 @@
|
|
|
21
21
|
"@ledgerhq/hw-transport-node-hid": "~6.28.5",
|
|
22
22
|
"@ledgerhq/hw-transport": "~6.30.5",
|
|
23
23
|
"@ledgerhq/hw-app-eth": "~6.35.7",
|
|
24
|
-
"@
|
|
24
|
+
"@ethersproject/abstract-signer": "~5.7.0",
|
|
25
|
+
"@ethersproject/properties": "~5.7.0",
|
|
26
|
+
"@cityofzion/blockchain-service": "0.11.2"
|
|
25
27
|
},
|
|
26
28
|
"devDependencies": {
|
|
27
29
|
"@types/jest": "29.5.3",
|