@cityofzion/bs-neo-legacy 1.6.7 → 1.7.1
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/constants/BSNeoLegacyConstants.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/services/BSNeoLegacy.d.ts +7 -4
- package/dist/services/BSNeoLegacy.js +40 -7
- package/dist/services/explorer/NeoTubeESNeoLegacy.js +2 -1
- package/dist/services/ledger/NeonJsLedgerServiceNeoLegacy.d.ts +12 -0
- package/dist/services/ledger/NeonJsLedgerServiceNeoLegacy.js +153 -0
- package/package.json +4 -2
|
@@ -17,10 +17,10 @@ BSNeoLegacyConstants.EXTRA_TOKENS_BY_NETWORK_ID = {
|
|
|
17
17
|
BSNeoLegacyConstants.NATIVE_ASSETS = common_json_1.default;
|
|
18
18
|
BSNeoLegacyConstants.RPC_LIST_BY_NETWORK_ID = {
|
|
19
19
|
mainnet: [
|
|
20
|
-
'http://seed9.ngd.network:10332',
|
|
21
20
|
'https://mainnet1.neo2.coz.io:443',
|
|
22
21
|
'https://mainnet2.neo2.coz.io:443',
|
|
23
22
|
'https://mainnet3.neo2.coz.io:443',
|
|
23
|
+
'http://seed9.ngd.network:10332',
|
|
24
24
|
'http://seed1.ngd.network:10332',
|
|
25
25
|
'http://seed2.ngd.network:10332',
|
|
26
26
|
'http://seed3.ngd.network:10332',
|
package/dist/index.d.ts
CHANGED
|
@@ -4,3 +4,4 @@ export * from './helpers/BSNeoLegacyHelper';
|
|
|
4
4
|
export * from './services/blockchain-data/DoraBDSNeoLegacy';
|
|
5
5
|
export * from './services/exchange-data/CryptoCompareEDSNeoLegacy';
|
|
6
6
|
export * from './services/explorer/NeoTubeESNeoLegacy';
|
|
7
|
+
export * from './services/ledger/NeonJsLedgerServiceNeoLegacy';
|
package/dist/index.js
CHANGED
|
@@ -20,3 +20,4 @@ __exportStar(require("./helpers/BSNeoLegacyHelper"), exports);
|
|
|
20
20
|
__exportStar(require("./services/blockchain-data/DoraBDSNeoLegacy"), exports);
|
|
21
21
|
__exportStar(require("./services/exchange-data/CryptoCompareEDSNeoLegacy"), exports);
|
|
22
22
|
__exportStar(require("./services/explorer/NeoTubeESNeoLegacy"), exports);
|
|
23
|
+
__exportStar(require("./services/ledger/NeonJsLedgerServiceNeoLegacy"), exports);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Account, BDSClaimable, BlockchainDataService, BlockchainService, BSClaimable, ExchangeDataService, Token, Network, TransferParam, BSWithExplorerService, ExplorerService } from '@cityofzion/blockchain-service';
|
|
1
|
+
import { Account, BDSClaimable, BlockchainDataService, BlockchainService, BSClaimable, ExchangeDataService, Token, Network, TransferParam, BSWithExplorerService, ExplorerService, BSWithLedger, GetLedgerTransport } from '@cityofzion/blockchain-service';
|
|
2
2
|
import { BSNeoLegacyNetworkId } from '../constants/BSNeoLegacyConstants';
|
|
3
|
-
|
|
3
|
+
import { NeonJsLedgerServiceNeoLegacy } from './ledger/NeonJsLedgerServiceNeoLegacy';
|
|
4
|
+
export declare class BSNeoLegacy<BSName extends string = string> implements BlockchainService<BSName, BSNeoLegacyNetworkId>, BSClaimable<BSName>, BSWithExplorerService, BSWithLedger<BSName> {
|
|
4
5
|
#private;
|
|
5
6
|
readonly name: BSName;
|
|
6
7
|
readonly bip44DerivationPath: string;
|
|
@@ -9,11 +10,12 @@ export declare class BSNeoLegacy<BSName extends string = string> implements Bloc
|
|
|
9
10
|
burnToken: Token;
|
|
10
11
|
blockchainDataService: BlockchainDataService & BDSClaimable;
|
|
11
12
|
exchangeDataService: ExchangeDataService;
|
|
13
|
+
ledgerService: NeonJsLedgerServiceNeoLegacy<BSName>;
|
|
12
14
|
explorerService: ExplorerService;
|
|
13
15
|
tokens: Token[];
|
|
14
16
|
network: Network<BSNeoLegacyNetworkId>;
|
|
15
17
|
legacyNetwork: string;
|
|
16
|
-
constructor(name: BSName, network?: Network<BSNeoLegacyNetworkId>);
|
|
18
|
+
constructor(name: BSName, network?: Network<BSNeoLegacyNetworkId>, getLedgerTransport?: GetLedgerTransport<BSName>);
|
|
17
19
|
testNetwork(network: Network<BSNeoLegacyNetworkId>): Promise<void>;
|
|
18
20
|
setNetwork(network: Network<BSNeoLegacyNetworkId>): void;
|
|
19
21
|
validateAddress(address: string): boolean;
|
|
@@ -21,8 +23,9 @@ export declare class BSNeoLegacy<BSName extends string = string> implements Bloc
|
|
|
21
23
|
validateKey(key: string): boolean;
|
|
22
24
|
generateAccountFromMnemonic(mnemonic: string[] | string, index: number): Account<BSName>;
|
|
23
25
|
generateAccountFromKey(key: string): Account<BSName>;
|
|
26
|
+
generateAccountFromPublicKey(publicKey: string): Account<BSName>;
|
|
24
27
|
decrypt(encryptedKey: string, password: string): Promise<Account<BSName>>;
|
|
25
28
|
encrypt(key: string, password: string): Promise<string>;
|
|
26
|
-
transfer({ intents, senderAccount, tipIntent, ...params }: TransferParam): Promise<string[]>;
|
|
29
|
+
transfer({ intents, senderAccount, tipIntent, ...params }: TransferParam<BSName>): Promise<string[]>;
|
|
27
30
|
claim(account: Account): Promise<string>;
|
|
28
31
|
}
|
|
@@ -24,7 +24,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
24
24
|
}
|
|
25
25
|
return t;
|
|
26
26
|
};
|
|
27
|
-
var _BSNeoLegacy_instances, _BSNeoLegacy_setTokens;
|
|
27
|
+
var _BSNeoLegacy_instances, _BSNeoLegacy_generateSigningCallback, _BSNeoLegacy_setTokens;
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.BSNeoLegacy = void 0;
|
|
30
30
|
const neon_js_1 = require("@cityofzion/neon-js");
|
|
@@ -34,12 +34,14 @@ const BSNeoLegacyHelper_1 = require("../helpers/BSNeoLegacyHelper");
|
|
|
34
34
|
const CryptoCompareEDSNeoLegacy_1 = require("./exchange-data/CryptoCompareEDSNeoLegacy");
|
|
35
35
|
const DoraBDSNeoLegacy_1 = require("./blockchain-data/DoraBDSNeoLegacy");
|
|
36
36
|
const NeoTubeESNeoLegacy_1 = require("./explorer/NeoTubeESNeoLegacy");
|
|
37
|
+
const NeonJsLedgerServiceNeoLegacy_1 = require("./ledger/NeonJsLedgerServiceNeoLegacy");
|
|
37
38
|
class BSNeoLegacy {
|
|
38
|
-
constructor(name, network) {
|
|
39
|
+
constructor(name, network, getLedgerTransport) {
|
|
39
40
|
_BSNeoLegacy_instances.add(this);
|
|
40
41
|
network = network !== null && network !== void 0 ? network : BSNeoLegacyConstants_1.BSNeoLegacyConstants.DEFAULT_NETWORK;
|
|
41
42
|
this.name = name;
|
|
42
43
|
this.legacyNetwork = BSNeoLegacyConstants_1.BSNeoLegacyConstants.LEGACY_NETWORK_BY_NETWORK_ID[network.id];
|
|
44
|
+
this.ledgerService = new NeonJsLedgerServiceNeoLegacy_1.NeonJsLedgerServiceNeoLegacy(this, getLedgerTransport);
|
|
43
45
|
this.bip44DerivationPath = BSNeoLegacyConstants_1.BSNeoLegacyConstants.DEFAULT_BIP44_DERIVATION_PATH;
|
|
44
46
|
this.setNetwork(network);
|
|
45
47
|
}
|
|
@@ -82,6 +84,17 @@ class BSNeoLegacy {
|
|
|
82
84
|
const { address } = new neon_js_1.wallet.Account(key);
|
|
83
85
|
return { address, key, type, blockchain: this.name };
|
|
84
86
|
}
|
|
87
|
+
generateAccountFromPublicKey(publicKey) {
|
|
88
|
+
if (!neon_js_1.wallet.isPublicKey(publicKey))
|
|
89
|
+
throw new Error('Invalid public key');
|
|
90
|
+
const account = new neon_js_1.wallet.Account(publicKey);
|
|
91
|
+
return {
|
|
92
|
+
address: account.address,
|
|
93
|
+
key: account.publicKey,
|
|
94
|
+
type: 'publicKey',
|
|
95
|
+
blockchain: this.name,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
85
98
|
decrypt(encryptedKey, password) {
|
|
86
99
|
return __awaiter(this, void 0, void 0, function* () {
|
|
87
100
|
const key = yield neon_js_1.wallet.decrypt(encryptedKey, password);
|
|
@@ -95,8 +108,8 @@ class BSNeoLegacy {
|
|
|
95
108
|
var _b, _c;
|
|
96
109
|
var { intents, senderAccount, tipIntent } = _a, params = __rest(_a, ["intents", "senderAccount", "tipIntent"]);
|
|
97
110
|
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
const { neonJsAccount, signingCallback } = yield __classPrivateFieldGet(this, _BSNeoLegacy_instances, "m", _BSNeoLegacy_generateSigningCallback).call(this, senderAccount);
|
|
98
112
|
const apiProvider = new neon_js_1.api.neoCli.instance(this.network.url);
|
|
99
|
-
const account = new neon_js_1.wallet.Account(senderAccount.key);
|
|
100
113
|
const priorityFee = Number((_b = params.priorityFee) !== null && _b !== void 0 ? _b : 0);
|
|
101
114
|
const nativeIntents = [];
|
|
102
115
|
const nep5ScriptBuilder = new neon_js_1.sc.ScriptBuilder();
|
|
@@ -109,7 +122,7 @@ class BSNeoLegacy {
|
|
|
109
122
|
continue;
|
|
110
123
|
}
|
|
111
124
|
nep5ScriptBuilder.emitAppCall(tokenHashFixed, 'transfer', [
|
|
112
|
-
neon_js_1.u.reverseHex(neon_js_1.wallet.getScriptHashFromAddress(
|
|
125
|
+
neon_js_1.u.reverseHex(neon_js_1.wallet.getScriptHashFromAddress(neonJsAccount.address)),
|
|
113
126
|
neon_js_1.u.reverseHex(neon_js_1.wallet.getScriptHashFromAddress(intent.receiverAddress)),
|
|
114
127
|
neon_js_1.sc.ContractParam.integer(new neon_js_1.u.Fixed8(intent.amount)
|
|
115
128
|
.div(Math.pow(10, 8 - ((_c = intent.tokenDecimals) !== null && _c !== void 0 ? _c : 8)))
|
|
@@ -120,21 +133,23 @@ class BSNeoLegacy {
|
|
|
120
133
|
let response;
|
|
121
134
|
if (nep5ScriptBuilder.isEmpty()) {
|
|
122
135
|
response = yield neon_js_1.api.sendAsset({
|
|
123
|
-
account,
|
|
136
|
+
account: neonJsAccount,
|
|
124
137
|
api: apiProvider,
|
|
125
138
|
url: this.network.url,
|
|
126
139
|
intents: nativeIntents,
|
|
127
140
|
fees: priorityFee,
|
|
141
|
+
signingFunction: signingCallback,
|
|
128
142
|
});
|
|
129
143
|
}
|
|
130
144
|
else {
|
|
131
145
|
response = yield neon_js_1.api.doInvoke({
|
|
132
146
|
intents: nativeIntents.length > 0 ? nativeIntents : undefined,
|
|
133
|
-
account,
|
|
147
|
+
account: neonJsAccount,
|
|
134
148
|
api: apiProvider,
|
|
135
149
|
script: nep5ScriptBuilder.str,
|
|
136
150
|
url: this.network.url,
|
|
137
151
|
fees: priorityFee,
|
|
152
|
+
signingFunction: signingCallback,
|
|
138
153
|
});
|
|
139
154
|
}
|
|
140
155
|
if (!response.tx)
|
|
@@ -167,7 +182,25 @@ class BSNeoLegacy {
|
|
|
167
182
|
}
|
|
168
183
|
}
|
|
169
184
|
exports.BSNeoLegacy = BSNeoLegacy;
|
|
170
|
-
_BSNeoLegacy_instances = new WeakSet(),
|
|
185
|
+
_BSNeoLegacy_instances = new WeakSet(), _BSNeoLegacy_generateSigningCallback = function _BSNeoLegacy_generateSigningCallback(account) {
|
|
186
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
187
|
+
const neonJsAccount = new neon_js_1.wallet.Account(account.key);
|
|
188
|
+
if (account.isHardware) {
|
|
189
|
+
if (!this.ledgerService.getLedgerTransport)
|
|
190
|
+
throw new Error('You must provide a getLedgerTransport function to use Ledger');
|
|
191
|
+
if (typeof account.bip44Path !== 'string')
|
|
192
|
+
throw new Error('Your account must have bip44 path to use Ledger');
|
|
193
|
+
const ledgerTransport = yield this.ledgerService.getLedgerTransport(account);
|
|
194
|
+
return {
|
|
195
|
+
neonJsAccount,
|
|
196
|
+
signingCallback: this.ledgerService.getSigningCallback(ledgerTransport, account),
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
return {
|
|
200
|
+
neonJsAccount,
|
|
201
|
+
};
|
|
202
|
+
});
|
|
203
|
+
}, _BSNeoLegacy_setTokens = function _BSNeoLegacy_setTokens(network) {
|
|
171
204
|
const tokens = BSNeoLegacyHelper_1.BSNeoLegacyHelper.getTokens(network);
|
|
172
205
|
this.tokens = tokens;
|
|
173
206
|
this.feeToken = tokens.find(token => token.symbol === 'GAS');
|
|
@@ -13,6 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
13
13
|
var _NeoTubeESNeoLegacy_network;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.NeoTubeESNeoLegacy = void 0;
|
|
16
|
+
const blockchain_service_1 = require("@cityofzion/blockchain-service");
|
|
16
17
|
const BSNeoLegacyHelper_1 = require("../../helpers/BSNeoLegacyHelper");
|
|
17
18
|
class NeoTubeESNeoLegacy {
|
|
18
19
|
constructor(network) {
|
|
@@ -22,7 +23,7 @@ class NeoTubeESNeoLegacy {
|
|
|
22
23
|
buildTransactionUrl(hash) {
|
|
23
24
|
if (!BSNeoLegacyHelper_1.BSNeoLegacyHelper.isMainnet(__classPrivateFieldGet(this, _NeoTubeESNeoLegacy_network, "f")))
|
|
24
25
|
throw new Error('NeoTube is only available on mainnet');
|
|
25
|
-
return `https://neo2.neotube.io/transaction/${hash}`;
|
|
26
|
+
return `https://neo2.neotube.io/transaction/${(0, blockchain_service_1.denormalizeHash)(hash)}`;
|
|
26
27
|
}
|
|
27
28
|
buildContractUrl(contractHash) {
|
|
28
29
|
if (!BSNeoLegacyHelper_1.BSNeoLegacyHelper.isMainnet(__classPrivateFieldGet(this, _NeoTubeESNeoLegacy_network, "f")))
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Account, GetLedgerTransport, LedgerService, LedgerServiceEmitter } from '@cityofzion/blockchain-service';
|
|
2
|
+
import { BSNeoLegacy } from '../BSNeoLegacy';
|
|
3
|
+
import Transport from '@ledgerhq/hw-transport';
|
|
4
|
+
export declare class NeonJsLedgerServiceNeoLegacy<BSName extends string = string> implements LedgerService<BSName> {
|
|
5
|
+
#private;
|
|
6
|
+
emitter: LedgerServiceEmitter;
|
|
7
|
+
getLedgerTransport?: GetLedgerTransport<BSName>;
|
|
8
|
+
constructor(blockchainService: BSNeoLegacy<BSName>, getLedgerTransport?: GetLedgerTransport<BSName>);
|
|
9
|
+
getAccount(transport: Transport, index: number): Promise<Account<BSName>>;
|
|
10
|
+
getAccounts(transport: Transport): Promise<Account<BSName>[]>;
|
|
11
|
+
getSigningCallback(transport: Transport, account: Account): (transaction: string, publicKey: string) => Promise<string | string[]>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
var _NeonJsLedgerServiceNeoLegacy_instances, _NeonJsLedgerServiceNeoLegacy_blockchainService, _NeonJsLedgerServiceNeoLegacy_sendChunk, _NeonJsLedgerServiceNeoLegacy_bip44PathToHex, _NeonJsLedgerServiceNeoLegacy_derSignatureToHex;
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.NeonJsLedgerServiceNeoLegacy = void 0;
|
|
28
|
+
const blockchain_service_1 = require("@cityofzion/blockchain-service");
|
|
29
|
+
const events_1 = __importDefault(require("events"));
|
|
30
|
+
const neon_js_1 = require("@cityofzion/neon-js");
|
|
31
|
+
var LedgerStatus;
|
|
32
|
+
(function (LedgerStatus) {
|
|
33
|
+
LedgerStatus[LedgerStatus["OK"] = 36864] = "OK";
|
|
34
|
+
})(LedgerStatus || (LedgerStatus = {}));
|
|
35
|
+
var LedgerCommand;
|
|
36
|
+
(function (LedgerCommand) {
|
|
37
|
+
LedgerCommand[LedgerCommand["GET_PUBLIC_KEY"] = 4] = "GET_PUBLIC_KEY";
|
|
38
|
+
LedgerCommand[LedgerCommand["SIGN"] = 2] = "SIGN";
|
|
39
|
+
})(LedgerCommand || (LedgerCommand = {}));
|
|
40
|
+
var LedgerParameter;
|
|
41
|
+
(function (LedgerParameter) {
|
|
42
|
+
LedgerParameter[LedgerParameter["MORE_DATA"] = 0] = "MORE_DATA";
|
|
43
|
+
LedgerParameter[LedgerParameter["LAST_DATA"] = 128] = "LAST_DATA";
|
|
44
|
+
})(LedgerParameter || (LedgerParameter = {}));
|
|
45
|
+
class NeonJsLedgerServiceNeoLegacy {
|
|
46
|
+
constructor(blockchainService, getLedgerTransport) {
|
|
47
|
+
_NeonJsLedgerServiceNeoLegacy_instances.add(this);
|
|
48
|
+
_NeonJsLedgerServiceNeoLegacy_blockchainService.set(this, void 0);
|
|
49
|
+
this.emitter = new events_1.default();
|
|
50
|
+
__classPrivateFieldSet(this, _NeonJsLedgerServiceNeoLegacy_blockchainService, blockchainService, "f");
|
|
51
|
+
this.getLedgerTransport = getLedgerTransport;
|
|
52
|
+
}
|
|
53
|
+
getAccount(transport, index) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
const bip44Path = __classPrivateFieldGet(this, _NeonJsLedgerServiceNeoLegacy_blockchainService, "f").bip44DerivationPath.replace('?', index.toString());
|
|
56
|
+
const bip44PathHex = __classPrivateFieldGet(this, _NeonJsLedgerServiceNeoLegacy_instances, "m", _NeonJsLedgerServiceNeoLegacy_bip44PathToHex).call(this, bip44Path);
|
|
57
|
+
const result = yield __classPrivateFieldGet(this, _NeonJsLedgerServiceNeoLegacy_instances, "m", _NeonJsLedgerServiceNeoLegacy_sendChunk).call(this, transport, LedgerCommand.GET_PUBLIC_KEY, LedgerParameter.LAST_DATA, bip44PathHex);
|
|
58
|
+
const publicKey = result.toString('hex').substring(0, 130);
|
|
59
|
+
const { address } = new neon_js_1.wallet.Account(publicKey);
|
|
60
|
+
return {
|
|
61
|
+
address,
|
|
62
|
+
key: publicKey,
|
|
63
|
+
type: 'publicKey',
|
|
64
|
+
bip44Path,
|
|
65
|
+
blockchain: __classPrivateFieldGet(this, _NeonJsLedgerServiceNeoLegacy_blockchainService, "f").name,
|
|
66
|
+
isHardware: true,
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
getAccounts(transport) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
const accountsByBlockchainService = yield (0, blockchain_service_1.fetchAccountsForBlockchainServices)([__classPrivateFieldGet(this, _NeonJsLedgerServiceNeoLegacy_blockchainService, "f")], (_service, index) => __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
return this.getAccount(transport, index);
|
|
74
|
+
}));
|
|
75
|
+
const accounts = accountsByBlockchainService.get(__classPrivateFieldGet(this, _NeonJsLedgerServiceNeoLegacy_blockchainService, "f").name);
|
|
76
|
+
return accounts !== null && accounts !== void 0 ? accounts : [];
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
getSigningCallback(transport, account) {
|
|
80
|
+
return (transaction, publicKey) => __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
try {
|
|
82
|
+
this.emitter.emit('getSignatureStart');
|
|
83
|
+
if (!account.bip44Path) {
|
|
84
|
+
throw new Error('Account must have a bip 44 path to sign with Ledger');
|
|
85
|
+
}
|
|
86
|
+
const neonJsAccount = new neon_js_1.wallet.Account(account.key);
|
|
87
|
+
const witnessScriptHash = neon_js_1.wallet.getScriptHashFromPublicKey(publicKey);
|
|
88
|
+
if (neonJsAccount.scriptHash !== witnessScriptHash) {
|
|
89
|
+
throw new Error('Public key does not match the account key');
|
|
90
|
+
}
|
|
91
|
+
const bip44PathHex = __classPrivateFieldGet(this, _NeonJsLedgerServiceNeoLegacy_instances, "m", _NeonJsLedgerServiceNeoLegacy_bip44PathToHex).call(this, account.bip44Path);
|
|
92
|
+
const payload = transaction + bip44PathHex;
|
|
93
|
+
// Split the serialized transaction into chunks of 510 bytes
|
|
94
|
+
const chunks = payload.match(/.{1,510}/g) || [];
|
|
95
|
+
// Send all chunks except the last one
|
|
96
|
+
for (let i = 0; i < chunks.length - 1; i++) {
|
|
97
|
+
yield __classPrivateFieldGet(this, _NeonJsLedgerServiceNeoLegacy_instances, "m", _NeonJsLedgerServiceNeoLegacy_sendChunk).call(this, transport, LedgerCommand.SIGN, LedgerParameter.MORE_DATA, chunks[i]);
|
|
98
|
+
}
|
|
99
|
+
// Send the last chunk signaling that it is the last one and get the signature
|
|
100
|
+
const response = yield __classPrivateFieldGet(this, _NeonJsLedgerServiceNeoLegacy_instances, "m", _NeonJsLedgerServiceNeoLegacy_sendChunk).call(this, transport, LedgerCommand.SIGN, LedgerParameter.LAST_DATA, chunks[chunks.length - 1]);
|
|
101
|
+
if (response.readUIntBE(0, 2) === LedgerStatus.OK) {
|
|
102
|
+
throw new Error('No more data but Ledger did not return signature!');
|
|
103
|
+
}
|
|
104
|
+
const signature = __classPrivateFieldGet(this, _NeonJsLedgerServiceNeoLegacy_instances, "m", _NeonJsLedgerServiceNeoLegacy_derSignatureToHex).call(this, response.toString('hex'));
|
|
105
|
+
const witness = neon_js_1.tx.Witness.fromSignature(signature, publicKey);
|
|
106
|
+
return witness.serialize();
|
|
107
|
+
}
|
|
108
|
+
finally {
|
|
109
|
+
this.emitter.emit('getSignatureEnd');
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.NeonJsLedgerServiceNeoLegacy = NeonJsLedgerServiceNeoLegacy;
|
|
115
|
+
_NeonJsLedgerServiceNeoLegacy_blockchainService = new WeakMap(), _NeonJsLedgerServiceNeoLegacy_instances = new WeakSet(), _NeonJsLedgerServiceNeoLegacy_sendChunk = function _NeonJsLedgerServiceNeoLegacy_sendChunk(transport, command, parameter, chunk) {
|
|
116
|
+
return transport.send(0x80, command, parameter, 0x00, Buffer.from(chunk, 'hex'), [LedgerStatus.OK]);
|
|
117
|
+
}, _NeonJsLedgerServiceNeoLegacy_bip44PathToHex = function _NeonJsLedgerServiceNeoLegacy_bip44PathToHex(path) {
|
|
118
|
+
let result = '';
|
|
119
|
+
const components = path.split('/');
|
|
120
|
+
components.forEach(element => {
|
|
121
|
+
let number = parseInt(element, 10);
|
|
122
|
+
if (isNaN(number)) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (element.length > 1 && element[element.length - 1] === "'") {
|
|
126
|
+
number += 0x80000000;
|
|
127
|
+
}
|
|
128
|
+
result += number.toString(16).padStart(8, '0');
|
|
129
|
+
});
|
|
130
|
+
return result;
|
|
131
|
+
}, _NeonJsLedgerServiceNeoLegacy_derSignatureToHex = function _NeonJsLedgerServiceNeoLegacy_derSignatureToHex(response) {
|
|
132
|
+
const ss = new neon_js_1.u.StringStream(response);
|
|
133
|
+
// The first byte is format. It is usually 0x30 (SEQ) or 0x31 (SET)
|
|
134
|
+
// The second byte represents the total length of the DER module.
|
|
135
|
+
ss.read(2);
|
|
136
|
+
// Now we read each field off
|
|
137
|
+
// Each field is encoded with a type byte, length byte followed by the data itself
|
|
138
|
+
ss.read(1); // Read and drop the type
|
|
139
|
+
const r = ss.readVarBytes();
|
|
140
|
+
ss.read(1);
|
|
141
|
+
const s = ss.readVarBytes();
|
|
142
|
+
// We will need to ensure both integers are 32 bytes long
|
|
143
|
+
const integers = [r, s].map(i => {
|
|
144
|
+
if (i.length < 64) {
|
|
145
|
+
i = '0'.repeat(i.length - 64) + i;
|
|
146
|
+
}
|
|
147
|
+
if (i.length > 64) {
|
|
148
|
+
i = i.substr(-64);
|
|
149
|
+
}
|
|
150
|
+
return i;
|
|
151
|
+
});
|
|
152
|
+
return integers.join('');
|
|
153
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cityofzion/bs-neo-legacy",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"author": "Coz",
|
|
@@ -11,13 +11,15 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@cityofzion/dora-ts": "0.0.11",
|
|
13
13
|
"@cityofzion/neon-js": "4.8.3",
|
|
14
|
-
"@
|
|
14
|
+
"@ledgerhq/hw-transport": "~6.30.5",
|
|
15
|
+
"@cityofzion/blockchain-service": "1.13.1",
|
|
15
16
|
"@cityofzion/bs-asteroid-sdk": "0.9.0"
|
|
16
17
|
},
|
|
17
18
|
"devDependencies": {
|
|
18
19
|
"@types/jest": "29.5.3",
|
|
19
20
|
"@typescript-eslint/eslint-plugin": "^6.5.0",
|
|
20
21
|
"@typescript-eslint/parser": "^6.5.0",
|
|
22
|
+
"@ledgerhq/hw-transport-node-hid": "~6.28.5",
|
|
21
23
|
"dotenv": "16.3.1",
|
|
22
24
|
"eslint": "^8.48.0",
|
|
23
25
|
"jest": "29.6.2",
|