@cityofzion/bs-neo-legacy 1.13.4 → 1.13.6

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.
@@ -19,23 +19,23 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
19
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
20
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
21
21
  };
22
- var _CryptoCompareEDSNeoLegacy_network;
22
+ var _CryptoCompareEDSNeoLegacy_service;
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
24
  exports.CryptoCompareEDSNeoLegacy = void 0;
25
25
  const blockchain_service_1 = require("@cityofzion/blockchain-service");
26
26
  const BSNeoLegacyHelper_1 = require("../../helpers/BSNeoLegacyHelper");
27
27
  class CryptoCompareEDSNeoLegacy extends blockchain_service_1.CryptoCompareEDS {
28
- constructor(network) {
28
+ constructor(service) {
29
29
  super();
30
- _CryptoCompareEDSNeoLegacy_network.set(this, void 0);
31
- __classPrivateFieldSet(this, _CryptoCompareEDSNeoLegacy_network, network, "f");
30
+ _CryptoCompareEDSNeoLegacy_service.set(this, void 0);
31
+ __classPrivateFieldSet(this, _CryptoCompareEDSNeoLegacy_service, service, "f");
32
32
  }
33
33
  getTokenPriceHistory(params) {
34
34
  const _super = Object.create(null, {
35
35
  getTokenPriceHistory: { get: () => super.getTokenPriceHistory }
36
36
  });
37
37
  return __awaiter(this, void 0, void 0, function* () {
38
- if (!BSNeoLegacyHelper_1.BSNeoLegacyHelper.isMainnet(__classPrivateFieldGet(this, _CryptoCompareEDSNeoLegacy_network, "f")))
38
+ if (!BSNeoLegacyHelper_1.BSNeoLegacyHelper.isMainnetNetwork(__classPrivateFieldGet(this, _CryptoCompareEDSNeoLegacy_service, "f").network))
39
39
  throw new Error('Exchange is only available on mainnet');
40
40
  return yield _super.getTokenPriceHistory.call(this, params);
41
41
  });
@@ -45,11 +45,11 @@ class CryptoCompareEDSNeoLegacy extends blockchain_service_1.CryptoCompareEDS {
45
45
  getTokenPrices: { get: () => super.getTokenPrices }
46
46
  });
47
47
  return __awaiter(this, void 0, void 0, function* () {
48
- if (!BSNeoLegacyHelper_1.BSNeoLegacyHelper.isMainnet(__classPrivateFieldGet(this, _CryptoCompareEDSNeoLegacy_network, "f")))
48
+ if (!BSNeoLegacyHelper_1.BSNeoLegacyHelper.isMainnetNetwork(__classPrivateFieldGet(this, _CryptoCompareEDSNeoLegacy_service, "f").network))
49
49
  throw new Error('Exchange is only available on mainnet');
50
50
  return yield _super.getTokenPrices.call(this, params);
51
51
  });
52
52
  }
53
53
  }
54
54
  exports.CryptoCompareEDSNeoLegacy = CryptoCompareEDSNeoLegacy;
55
- _CryptoCompareEDSNeoLegacy_network = new WeakMap();
55
+ _CryptoCompareEDSNeoLegacy_service = new WeakMap();
@@ -1,11 +1,12 @@
1
- import { BuildNftUrlParams, ExplorerService, Network, TokenService } from '@cityofzion/blockchain-service';
2
- import { BSNeoLegacyNetworkId } from '../../constants/BSNeoLegacyConstants';
3
- export declare class NeoTubeESNeoLegacy implements ExplorerService {
1
+ import { TBuildNftUrlParams, IExplorerService } from '@cityofzion/blockchain-service';
2
+ import { IBSNeoLegacy } from '../../types';
3
+ export declare class NeoTubeESNeoLegacy<N extends string> implements IExplorerService {
4
4
  #private;
5
- constructor(network: Network<BSNeoLegacyNetworkId>, tokenService: TokenService);
5
+ static readonly BASE_URL: string;
6
+ constructor(service: IBSNeoLegacy<N>);
6
7
  buildTransactionUrl(hash: string): string;
7
8
  buildContractUrl(contractHash: string): string;
8
- buildNftUrl(_params: BuildNftUrlParams): string;
9
+ buildNftUrl(_params: TBuildNftUrlParams): string;
9
10
  getAddressTemplateUrl(): string | undefined;
10
11
  getTxTemplateUrl(): string | undefined;
11
12
  getNftTemplateUrl(): undefined;
@@ -10,49 +10,47 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  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");
11
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
12
  };
13
- var _NeoTubeESNeoLegacy_BASE_URL, _NeoTubeESNeoLegacy_network, _NeoTubeESNeoLegacy_tokenService;
13
+ var _NeoTubeESNeoLegacy_service;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.NeoTubeESNeoLegacy = void 0;
16
16
  const BSNeoLegacyHelper_1 = require("../../helpers/BSNeoLegacyHelper");
17
17
  class NeoTubeESNeoLegacy {
18
- constructor(network, tokenService) {
19
- _NeoTubeESNeoLegacy_BASE_URL.set(this, 'https://neo2.neotube.io');
20
- _NeoTubeESNeoLegacy_network.set(this, void 0);
21
- _NeoTubeESNeoLegacy_tokenService.set(this, void 0);
22
- __classPrivateFieldSet(this, _NeoTubeESNeoLegacy_network, network, "f");
23
- __classPrivateFieldSet(this, _NeoTubeESNeoLegacy_tokenService, tokenService, "f");
18
+ constructor(service) {
19
+ _NeoTubeESNeoLegacy_service.set(this, void 0);
20
+ __classPrivateFieldSet(this, _NeoTubeESNeoLegacy_service, service, "f");
24
21
  }
25
22
  buildTransactionUrl(hash) {
26
- if (!BSNeoLegacyHelper_1.BSNeoLegacyHelper.isMainnet(__classPrivateFieldGet(this, _NeoTubeESNeoLegacy_network, "f")))
23
+ if (!BSNeoLegacyHelper_1.BSNeoLegacyHelper.isMainnetNetwork(__classPrivateFieldGet(this, _NeoTubeESNeoLegacy_service, "f").network))
27
24
  throw new Error('NeoTube is only available on mainnet');
28
- return `${__classPrivateFieldGet(this, _NeoTubeESNeoLegacy_BASE_URL, "f")}/transaction/${__classPrivateFieldGet(this, _NeoTubeESNeoLegacy_tokenService, "f").normalizeHash(hash)}`;
25
+ return `${NeoTubeESNeoLegacy.BASE_URL}/transaction/${__classPrivateFieldGet(this, _NeoTubeESNeoLegacy_service, "f").tokenService.normalizeHash(hash)}`;
29
26
  }
30
27
  buildContractUrl(contractHash) {
31
- if (!BSNeoLegacyHelper_1.BSNeoLegacyHelper.isMainnet(__classPrivateFieldGet(this, _NeoTubeESNeoLegacy_network, "f")))
28
+ if (!BSNeoLegacyHelper_1.BSNeoLegacyHelper.isMainnetNetwork(__classPrivateFieldGet(this, _NeoTubeESNeoLegacy_service, "f").network))
32
29
  throw new Error('NeoTube is only available on mainnet');
33
- return `${__classPrivateFieldGet(this, _NeoTubeESNeoLegacy_BASE_URL, "f")}/asset/${__classPrivateFieldGet(this, _NeoTubeESNeoLegacy_tokenService, "f").normalizeHash(contractHash)}/page/1`;
30
+ return `${NeoTubeESNeoLegacy.BASE_URL}/asset/${__classPrivateFieldGet(this, _NeoTubeESNeoLegacy_service, "f").tokenService.normalizeHash(contractHash)}/page/1`;
34
31
  }
35
32
  buildNftUrl(_params) {
36
33
  throw new Error('NeoTube does not support nft');
37
34
  }
38
35
  getAddressTemplateUrl() {
39
- if (!BSNeoLegacyHelper_1.BSNeoLegacyHelper.isMainnet(__classPrivateFieldGet(this, _NeoTubeESNeoLegacy_network, "f")))
36
+ if (!BSNeoLegacyHelper_1.BSNeoLegacyHelper.isMainnetNetwork(__classPrivateFieldGet(this, _NeoTubeESNeoLegacy_service, "f").network))
40
37
  return undefined;
41
- return `${__classPrivateFieldGet(this, _NeoTubeESNeoLegacy_BASE_URL, "f")}/address/{address}`;
38
+ return `${NeoTubeESNeoLegacy.BASE_URL}/address/{address}`;
42
39
  }
43
40
  getTxTemplateUrl() {
44
- if (!BSNeoLegacyHelper_1.BSNeoLegacyHelper.isMainnet(__classPrivateFieldGet(this, _NeoTubeESNeoLegacy_network, "f")))
41
+ if (!BSNeoLegacyHelper_1.BSNeoLegacyHelper.isMainnetNetwork(__classPrivateFieldGet(this, _NeoTubeESNeoLegacy_service, "f").network))
45
42
  return undefined;
46
- return `${__classPrivateFieldGet(this, _NeoTubeESNeoLegacy_BASE_URL, "f")}/transaction/{txId}`;
43
+ return `${NeoTubeESNeoLegacy.BASE_URL}/transaction/{txId}`;
47
44
  }
48
45
  getNftTemplateUrl() {
49
46
  return undefined;
50
47
  }
51
48
  getContractTemplateUrl() {
52
- if (!BSNeoLegacyHelper_1.BSNeoLegacyHelper.isMainnet(__classPrivateFieldGet(this, _NeoTubeESNeoLegacy_network, "f")))
49
+ if (!BSNeoLegacyHelper_1.BSNeoLegacyHelper.isMainnetNetwork(__classPrivateFieldGet(this, _NeoTubeESNeoLegacy_service, "f").network))
53
50
  return undefined;
54
- return `${__classPrivateFieldGet(this, _NeoTubeESNeoLegacy_BASE_URL, "f")}/asset/{hash}/page/1`;
51
+ return `${NeoTubeESNeoLegacy.BASE_URL}/asset/{hash}/page/1`;
55
52
  }
56
53
  }
57
54
  exports.NeoTubeESNeoLegacy = NeoTubeESNeoLegacy;
58
- _NeoTubeESNeoLegacy_BASE_URL = new WeakMap(), _NeoTubeESNeoLegacy_network = new WeakMap(), _NeoTubeESNeoLegacy_tokenService = new WeakMap();
55
+ _NeoTubeESNeoLegacy_service = new WeakMap();
56
+ NeoTubeESNeoLegacy.BASE_URL = 'https://neo2.neotube.io';
@@ -1,12 +1,12 @@
1
- import { Account, GetLedgerTransport, LedgerService, LedgerServiceEmitter, UntilIndexRecord } from '@cityofzion/blockchain-service';
1
+ import { TBSAccount, TGetLedgerTransport, ILedgerService, TLedgerServiceEmitter, TUntilIndexRecord } from '@cityofzion/blockchain-service';
2
2
  import { BSNeoLegacy } from '../../BSNeoLegacy';
3
3
  import Transport from '@ledgerhq/hw-transport';
4
- export declare class NeonJsLedgerServiceNeoLegacy<BSName extends string = string> implements LedgerService<BSName> {
4
+ export declare class NeonJsLedgerServiceNeoLegacy<N extends string = string> implements ILedgerService<N> {
5
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, untilIndexByBlockchainService?: UntilIndexRecord<BSName>): Promise<Account<BSName>[]>;
11
- getSigningCallback(transport: Transport, account: Account): (transaction: string, publicKey: string) => Promise<string | string[]>;
6
+ readonly getLedgerTransport?: TGetLedgerTransport<N>;
7
+ emitter: TLedgerServiceEmitter;
8
+ constructor(blockchainService: BSNeoLegacy<N>, getLedgerTransport?: TGetLedgerTransport<N>);
9
+ getAccount(transport: Transport, index: number): Promise<TBSAccount<N>>;
10
+ getAccounts(transport: Transport, untilIndexByBlockchainService?: TUntilIndexRecord<N>): Promise<TBSAccount<N>[]>;
11
+ getSigningCallback(transport: Transport, account: TBSAccount): (transaction: string, publicKey: string) => Promise<string | string[]>;
12
12
  }
@@ -22,57 +22,45 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
22
22
  var __importDefault = (this && this.__importDefault) || function (mod) {
23
23
  return (mod && mod.__esModule) ? mod : { "default": mod };
24
24
  };
25
- var _NeonJsLedgerServiceNeoLegacy_instances, _NeonJsLedgerServiceNeoLegacy_blockchainService, _NeonJsLedgerServiceNeoLegacy_sendChunk, _NeonJsLedgerServiceNeoLegacy_bip44PathToHex, _NeonJsLedgerServiceNeoLegacy_derSignatureToHex;
25
+ var _NeonJsLedgerServiceNeoLegacy_instances, _NeonJsLedgerServiceNeoLegacy_service, _NeonJsLedgerServiceNeoLegacy_sendChunk, _NeonJsLedgerServiceNeoLegacy_bip44PathToHex, _NeonJsLedgerServiceNeoLegacy_derSignatureToHex;
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
27
  exports.NeonJsLedgerServiceNeoLegacy = void 0;
28
28
  const blockchain_service_1 = require("@cityofzion/blockchain-service");
29
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 = {}));
30
+ const types_1 = require("../../types");
31
+ const BSNeoLegacyNeonJsSingletonHelper_1 = require("../../helpers/BSNeoLegacyNeonJsSingletonHelper");
45
32
  class NeonJsLedgerServiceNeoLegacy {
46
33
  constructor(blockchainService, getLedgerTransport) {
47
34
  _NeonJsLedgerServiceNeoLegacy_instances.add(this);
48
- _NeonJsLedgerServiceNeoLegacy_blockchainService.set(this, void 0);
35
+ _NeonJsLedgerServiceNeoLegacy_service.set(this, void 0);
49
36
  this.emitter = new events_1.default();
50
- __classPrivateFieldSet(this, _NeonJsLedgerServiceNeoLegacy_blockchainService, blockchainService, "f");
37
+ __classPrivateFieldSet(this, _NeonJsLedgerServiceNeoLegacy_service, blockchainService, "f");
51
38
  this.getLedgerTransport = getLedgerTransport;
52
39
  }
53
40
  getAccount(transport, index) {
54
41
  return __awaiter(this, void 0, void 0, function* () {
55
- const bip44Path = __classPrivateFieldGet(this, _NeonJsLedgerServiceNeoLegacy_blockchainService, "f").bip44DerivationPath.replace('?', index.toString());
42
+ const bip44Path = __classPrivateFieldGet(this, _NeonJsLedgerServiceNeoLegacy_service, "f").bip44DerivationPath.replace('?', index.toString());
56
43
  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);
44
+ const result = yield __classPrivateFieldGet(this, _NeonJsLedgerServiceNeoLegacy_instances, "m", _NeonJsLedgerServiceNeoLegacy_sendChunk).call(this, transport, types_1.ENeonJsLedgerServiceNeoLegacyCommand.GET_PUBLIC_KEY, types_1.ENeonJsLedgerServiceNeoLegacyParameter.LAST_DATA, bip44PathHex);
58
45
  const publicKey = result.toString('hex').substring(0, 130);
59
- const { address } = new neon_js_1.wallet.Account(publicKey);
46
+ const { wallet } = BSNeoLegacyNeonJsSingletonHelper_1.BSNeoLegacyNeonJsSingletonHelper.getInstance();
47
+ const { address } = new wallet.Account(publicKey);
60
48
  return {
61
49
  address,
62
50
  key: publicKey,
63
51
  type: 'publicKey',
64
52
  bip44Path,
65
- blockchain: __classPrivateFieldGet(this, _NeonJsLedgerServiceNeoLegacy_blockchainService, "f").name,
53
+ blockchain: __classPrivateFieldGet(this, _NeonJsLedgerServiceNeoLegacy_service, "f").name,
66
54
  isHardware: true,
67
55
  };
68
56
  });
69
57
  }
70
58
  getAccounts(transport, untilIndexByBlockchainService) {
71
59
  return __awaiter(this, void 0, void 0, function* () {
72
- const accountsByBlockchainService = yield (0, blockchain_service_1.generateAccountForBlockchainService)([__classPrivateFieldGet(this, _NeonJsLedgerServiceNeoLegacy_blockchainService, "f")], (_service, index) => __awaiter(this, void 0, void 0, function* () {
60
+ const accountsByBlockchainService = yield (0, blockchain_service_1.generateAccountForBlockchainService)([__classPrivateFieldGet(this, _NeonJsLedgerServiceNeoLegacy_service, "f")], (_service, index) => __awaiter(this, void 0, void 0, function* () {
73
61
  return this.getAccount(transport, index);
74
62
  }), untilIndexByBlockchainService);
75
- const accounts = accountsByBlockchainService.get(__classPrivateFieldGet(this, _NeonJsLedgerServiceNeoLegacy_blockchainService, "f").name);
63
+ const accounts = accountsByBlockchainService.get(__classPrivateFieldGet(this, _NeonJsLedgerServiceNeoLegacy_service, "f").name);
76
64
  return accounts !== null && accounts !== void 0 ? accounts : [];
77
65
  });
78
66
  }
@@ -83,8 +71,9 @@ class NeonJsLedgerServiceNeoLegacy {
83
71
  if (!account.bip44Path) {
84
72
  throw new Error('Account must have a bip 44 path to sign with Ledger');
85
73
  }
86
- const neonJsAccount = new neon_js_1.wallet.Account(account.key);
87
- const witnessScriptHash = neon_js_1.wallet.getScriptHashFromPublicKey(publicKey);
74
+ const { wallet, tx } = BSNeoLegacyNeonJsSingletonHelper_1.BSNeoLegacyNeonJsSingletonHelper.getInstance();
75
+ const neonJsAccount = new wallet.Account(account.key);
76
+ const witnessScriptHash = wallet.getScriptHashFromPublicKey(publicKey);
88
77
  if (neonJsAccount.scriptHash !== witnessScriptHash) {
89
78
  throw new Error('Public key does not match the account key');
90
79
  }
@@ -94,15 +83,15 @@ class NeonJsLedgerServiceNeoLegacy {
94
83
  const chunks = payload.match(/.{1,510}/g) || [];
95
84
  // Send all chunks except the last one
96
85
  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]);
86
+ yield __classPrivateFieldGet(this, _NeonJsLedgerServiceNeoLegacy_instances, "m", _NeonJsLedgerServiceNeoLegacy_sendChunk).call(this, transport, types_1.ENeonJsLedgerServiceNeoLegacyCommand.SIGN, types_1.ENeonJsLedgerServiceNeoLegacyParameter.MORE_DATA, chunks[i]);
98
87
  }
99
88
  // 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) {
89
+ const response = yield __classPrivateFieldGet(this, _NeonJsLedgerServiceNeoLegacy_instances, "m", _NeonJsLedgerServiceNeoLegacy_sendChunk).call(this, transport, types_1.ENeonJsLedgerServiceNeoLegacyCommand.SIGN, types_1.ENeonJsLedgerServiceNeoLegacyParameter.LAST_DATA, chunks[chunks.length - 1]);
90
+ if (response.readUIntBE(0, 2) === types_1.ENeonJsLedgerServiceNeoLegacyStatus.OK) {
102
91
  throw new Error('No more data but Ledger did not return signature!');
103
92
  }
104
93
  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);
94
+ const witness = tx.Witness.fromSignature(signature, publicKey);
106
95
  return witness.serialize();
107
96
  }
108
97
  finally {
@@ -112,8 +101,10 @@ class NeonJsLedgerServiceNeoLegacy {
112
101
  }
113
102
  }
114
103
  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]);
104
+ _NeonJsLedgerServiceNeoLegacy_service = new WeakMap(), _NeonJsLedgerServiceNeoLegacy_instances = new WeakSet(), _NeonJsLedgerServiceNeoLegacy_sendChunk = function _NeonJsLedgerServiceNeoLegacy_sendChunk(transport, command, parameter, chunk) {
105
+ return transport.send(0x80, command, parameter, 0x00, Buffer.from(chunk, 'hex'), [
106
+ types_1.ENeonJsLedgerServiceNeoLegacyStatus.OK,
107
+ ]);
117
108
  }, _NeonJsLedgerServiceNeoLegacy_bip44PathToHex = function _NeonJsLedgerServiceNeoLegacy_bip44PathToHex(path) {
118
109
  let result = '';
119
110
  const components = path.split('/');
@@ -129,7 +120,8 @@ _NeonJsLedgerServiceNeoLegacy_blockchainService = new WeakMap(), _NeonJsLedgerSe
129
120
  });
130
121
  return result;
131
122
  }, _NeonJsLedgerServiceNeoLegacy_derSignatureToHex = function _NeonJsLedgerServiceNeoLegacy_derSignatureToHex(response) {
132
- const ss = new neon_js_1.u.StringStream(response);
123
+ const { u } = BSNeoLegacyNeonJsSingletonHelper_1.BSNeoLegacyNeonJsSingletonHelper.getInstance();
124
+ const ss = new u.StringStream(response);
133
125
  // The first byte is format. It is usually 0x30 (SEQ) or 0x31 (SET)
134
126
  // The second byte represents the total length of the DER module.
135
127
  ss.read(2);
@@ -0,0 +1,16 @@
1
+ import { IBSNeoLegacy, TNeo3NeoLegacyMigrationNeo3Amounts, TNeo3NeoLegacyMigrationNeoLegacyAmounts, TNeo3NeoLegacyMigrateParams, TNeo3NeoLegacyWaitForMigrationParams } from '../../types';
2
+ import { TBalanceResponse } from '@cityofzion/blockchain-service';
3
+ export declare class Neo3NeoLegacyMigrationService<N extends string> {
4
+ #private;
5
+ constructor(service: IBSNeoLegacy<N>);
6
+ migrate({ account, neo3Address, neoLegacyMigrationAmounts }: TNeo3NeoLegacyMigrateParams<N>): Promise<string>;
7
+ /**
8
+ * Reference: https://github.com/CityOfZion/legacy-n3-swap-service/blob/master/policy/policy.go
9
+ */
10
+ calculateNeo3MigrationAmounts(neoLegacyMigrationAmounts: TNeo3NeoLegacyMigrationNeoLegacyAmounts): TNeo3NeoLegacyMigrationNeo3Amounts;
11
+ calculateNeoLegacyMigrationAmounts(balance: TBalanceResponse[]): TNeo3NeoLegacyMigrationNeoLegacyAmounts;
12
+ static waitForMigration(params: TNeo3NeoLegacyWaitForMigrationParams): Promise<{
13
+ isTransactionConfirmed: boolean;
14
+ isNeo3TransactionConfirmed: boolean;
15
+ }>;
16
+ }
@@ -0,0 +1,173 @@
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 _Neo3NeoLegacyMigrationService_service;
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.Neo3NeoLegacyMigrationService = void 0;
25
+ const BSNeoLegacyHelper_1 = require("../../helpers/BSNeoLegacyHelper");
26
+ const BSNeoLegacyConstants_1 = require("../../constants/BSNeoLegacyConstants");
27
+ const blockchain_service_1 = require("@cityofzion/blockchain-service");
28
+ const BSNeoLegacyNeonJsSingletonHelper_1 = require("../../helpers/BSNeoLegacyNeonJsSingletonHelper");
29
+ class Neo3NeoLegacyMigrationService {
30
+ constructor(service) {
31
+ _Neo3NeoLegacyMigrationService_service.set(this, void 0);
32
+ __classPrivateFieldSet(this, _Neo3NeoLegacyMigrationService_service, service, "f");
33
+ }
34
+ migrate(_a) {
35
+ return __awaiter(this, arguments, void 0, function* ({ account, neo3Address, neoLegacyMigrationAmounts }) {
36
+ if (!BSNeoLegacyHelper_1.BSNeoLegacyHelper.isMainnetNetwork(__classPrivateFieldGet(this, _Neo3NeoLegacyMigrationService_service, "f").network)) {
37
+ throw new Error('Must use Mainnet network');
38
+ }
39
+ if ((!neoLegacyMigrationAmounts.hasEnoughGasBalance && !neoLegacyMigrationAmounts.hasEnoughNeoBalance) ||
40
+ (!neoLegacyMigrationAmounts.gasBalance && !neoLegacyMigrationAmounts.neoBalance)) {
41
+ throw new Error('Must have at least 0.1 GAS or 2 NEO');
42
+ }
43
+ const { neonJsAccount, signingCallback } = yield __classPrivateFieldGet(this, _Neo3NeoLegacyMigrationService_service, "f").generateSigningCallback(account);
44
+ const { api, tx, u } = BSNeoLegacyNeonJsSingletonHelper_1.BSNeoLegacyNeonJsSingletonHelper.getInstance();
45
+ const provider = new api.neoCli.instance(__classPrivateFieldGet(this, _Neo3NeoLegacyMigrationService_service, "f").network.url);
46
+ const intents = [];
47
+ if (neoLegacyMigrationAmounts.hasEnoughGasBalance && neoLegacyMigrationAmounts.gasBalance)
48
+ intents.push(...api.makeIntent({ [BSNeoLegacyConstants_1.BSNeoLegacyConstants.GAS_ASSET.symbol]: Number(neoLegacyMigrationAmounts.gasBalance.amount) }, BSNeoLegacyConstants_1.BSNeoLegacyConstants.MIGRATION_COZ_LEGACY_ADDRESS));
49
+ if (neoLegacyMigrationAmounts.hasEnoughNeoBalance && neoLegacyMigrationAmounts.neoBalance)
50
+ intents.push(...api.makeIntent({ [BSNeoLegacyConstants_1.BSNeoLegacyConstants.NEO_ASSET.symbol]: Number(neoLegacyMigrationAmounts.neoBalance.amount) }, BSNeoLegacyConstants_1.BSNeoLegacyConstants.MIGRATION_COZ_LEGACY_ADDRESS));
51
+ return yield __classPrivateFieldGet(this, _Neo3NeoLegacyMigrationService_service, "f").sendTransfer({
52
+ url: __classPrivateFieldGet(this, _Neo3NeoLegacyMigrationService_service, "f").network.url,
53
+ api: provider,
54
+ account: neonJsAccount,
55
+ intents,
56
+ signingFunction: signingCallback,
57
+ override: {
58
+ attributes: [
59
+ new tx.TransactionAttribute({
60
+ usage: tx.TxAttrUsage.Remark14,
61
+ data: u.str2hexstring(neo3Address),
62
+ }),
63
+ new tx.TransactionAttribute({
64
+ usage: tx.TxAttrUsage.Remark15,
65
+ data: u.str2hexstring('Neon Desktop Migration'),
66
+ }),
67
+ ],
68
+ },
69
+ });
70
+ });
71
+ }
72
+ /**
73
+ * Reference: https://github.com/CityOfZion/legacy-n3-swap-service/blob/master/policy/policy.go
74
+ */
75
+ calculateNeo3MigrationAmounts(neoLegacyMigrationAmounts) {
76
+ const response = {
77
+ gasMigrationReceiveAmount: undefined,
78
+ gasMigrationTotalFees: undefined,
79
+ neoMigrationReceiveAmount: undefined,
80
+ neoMigrationTotalFees: undefined,
81
+ };
82
+ if (neoLegacyMigrationAmounts.gasBalance && neoLegacyMigrationAmounts.hasEnoughGasBalance) {
83
+ // Two transfers fee and one transfer fee left over
84
+ const allNep17TransfersFee = BSNeoLegacyConstants_1.BSNeoLegacyConstants.MIGRATION_NEP_17_TRANSFER_FEE * 3;
85
+ const gasMigrationAmountNumber = Number(neoLegacyMigrationAmounts.gasBalance.amount);
86
+ // Necessary to calculate the COZ fee
87
+ const gasAmountNumberLessAllNep17TransfersFee = gasMigrationAmountNumber - allNep17TransfersFee;
88
+ // Example: ~0.06635710 * 0.01 = ~0.00066357
89
+ const cozFee = gasAmountNumberLessAllNep17TransfersFee * BSNeoLegacyConstants_1.BSNeoLegacyConstants.MIGRATION_COZ_FEE;
90
+ // Example: ~0.06635710 - ~0.00066357 = ~0.06569352
91
+ const gasAmountNumberLessCozFee = gasAmountNumberLessAllNep17TransfersFee - cozFee;
92
+ const allGasFeeNumberThatUserWillPay = cozFee + BSNeoLegacyConstants_1.BSNeoLegacyConstants.MIGRATION_NEP_17_TRANSFER_FEE * 2;
93
+ const allGasAmountNumberThatUserWillReceive = gasAmountNumberLessCozFee + BSNeoLegacyConstants_1.BSNeoLegacyConstants.MIGRATION_NEP_17_TRANSFER_FEE;
94
+ response.gasMigrationTotalFees = blockchain_service_1.BSBigNumberHelper.format(allGasFeeNumberThatUserWillPay, {
95
+ decimals: BSNeoLegacyConstants_1.BSNeoLegacyConstants.GAS_ASSET.decimals,
96
+ });
97
+ response.gasMigrationReceiveAmount = blockchain_service_1.BSBigNumberHelper.format(allGasAmountNumberThatUserWillReceive, {
98
+ decimals: BSNeoLegacyConstants_1.BSNeoLegacyConstants.GAS_ASSET.decimals,
99
+ });
100
+ }
101
+ if (neoLegacyMigrationAmounts.neoBalance && neoLegacyMigrationAmounts.hasEnoughNeoBalance) {
102
+ const neoMigrationAmountNumber = Number(neoLegacyMigrationAmounts.neoBalance.amount);
103
+ response.neoMigrationTotalFees = blockchain_service_1.BSBigNumberHelper.format(Math.ceil(neoMigrationAmountNumber * BSNeoLegacyConstants_1.BSNeoLegacyConstants.MIGRATION_COZ_FEE), { decimals: BSNeoLegacyConstants_1.BSNeoLegacyConstants.NEO_ASSET.decimals });
104
+ response.neoMigrationReceiveAmount = blockchain_service_1.BSBigNumberHelper.format(neoMigrationAmountNumber - Number(response.neoMigrationTotalFees), { decimals: BSNeoLegacyConstants_1.BSNeoLegacyConstants.NEO_ASSET.decimals });
105
+ }
106
+ return response;
107
+ }
108
+ calculateNeoLegacyMigrationAmounts(balance) {
109
+ const gasBalance = balance.find(({ token }) => __classPrivateFieldGet(this, _Neo3NeoLegacyMigrationService_service, "f").tokenService.predicateByHash(BSNeoLegacyConstants_1.BSNeoLegacyConstants.GAS_ASSET, token));
110
+ const neoBalance = balance.find(({ token }) => __classPrivateFieldGet(this, _Neo3NeoLegacyMigrationService_service, "f").tokenService.predicateByHash(BSNeoLegacyConstants_1.BSNeoLegacyConstants.NEO_ASSET, token));
111
+ let hasEnoughGasBalance = false;
112
+ let hasEnoughNeoBalance = false;
113
+ if (gasBalance) {
114
+ const gasBalanceNumber = blockchain_service_1.BSBigNumberHelper.fromNumber(gasBalance.amount);
115
+ hasEnoughGasBalance = gasBalanceNumber.isGreaterThanOrEqualTo(BSNeoLegacyConstants_1.BSNeoLegacyConstants.MIGRATION_MIN_GAS);
116
+ }
117
+ if (neoBalance) {
118
+ const neoBalanceNumber = blockchain_service_1.BSBigNumberHelper.fromNumber(neoBalance.amount);
119
+ hasEnoughNeoBalance = neoBalanceNumber.isGreaterThanOrEqualTo(BSNeoLegacyConstants_1.BSNeoLegacyConstants.MIGRATION_MIN_NEO);
120
+ }
121
+ return {
122
+ gasBalance,
123
+ neoBalance,
124
+ hasEnoughGasBalance,
125
+ hasEnoughNeoBalance,
126
+ };
127
+ }
128
+ static waitForMigration(params) {
129
+ return __awaiter(this, void 0, void 0, function* () {
130
+ const { neo3Address, neo3Service, transactionHash, neoLegacyService } = params;
131
+ const MAX_ATTEMPTS = 10;
132
+ const NEO3_MAX_ATTEMPTS = 20;
133
+ const response = {
134
+ isTransactionConfirmed: false,
135
+ isNeo3TransactionConfirmed: false,
136
+ };
137
+ let transactionResponse;
138
+ for (let i = 0; i < MAX_ATTEMPTS; i++) {
139
+ yield blockchain_service_1.BSUtilsHelper.wait(30000);
140
+ try {
141
+ transactionResponse = yield neoLegacyService.blockchainDataService.getTransaction(transactionHash);
142
+ response.isTransactionConfirmed = true;
143
+ break;
144
+ }
145
+ catch (_a) {
146
+ // Empty block
147
+ }
148
+ }
149
+ if (!response.isTransactionConfirmed)
150
+ return response;
151
+ for (let i = 0; i < NEO3_MAX_ATTEMPTS; i++) {
152
+ yield blockchain_service_1.BSUtilsHelper.wait(60000);
153
+ try {
154
+ const neo3Response = yield neo3Service.blockchainDataService.getTransactionsByAddress({
155
+ address: neo3Address,
156
+ });
157
+ const isTransactionConfirmed = neo3Response.transactions.some(transaction => transaction.time > transactionResponse.time &&
158
+ transaction.transfers.some(transfer => transfer.from === BSNeoLegacyConstants_1.BSNeoLegacyConstants.MIGRATION_COZ_NEO3_ADDRESS));
159
+ if (isTransactionConfirmed) {
160
+ response.isNeo3TransactionConfirmed = true;
161
+ break;
162
+ }
163
+ }
164
+ catch (_b) {
165
+ // Empty block
166
+ }
167
+ }
168
+ return response;
169
+ });
170
+ }
171
+ }
172
+ exports.Neo3NeoLegacyMigrationService = Neo3NeoLegacyMigrationService;
173
+ _Neo3NeoLegacyMigrationService_service = new WeakMap();
@@ -0,0 +1,44 @@
1
+ import { TBSAccount, TBalanceResponse, IBlockchainService, IBSWithClaim, IBSWithEncryption, IBSWithExplorer, IBSWithLedger, TBSNetworkId } from '@cityofzion/blockchain-service';
2
+ export type TBSNeoLegacyNetworkId = TBSNetworkId<'mainnet' | 'testnet'>;
3
+ export type TSigningCallback = (transaction: string, publicKey: string) => Promise<string | string[]>;
4
+ export interface IBSNeoLegacy<N extends string = string> extends IBlockchainService<N, TBSNeoLegacyNetworkId>, IBSWithClaim<N>, IBSWithExplorer, IBSWithLedger<N>, IBSWithEncryption<N> {
5
+ generateSigningCallback(account: TBSAccount<N>): Promise<{
6
+ neonJsAccount: any;
7
+ signingCallback: TSigningCallback;
8
+ }>;
9
+ sendTransfer(config: any, nep5ScriptBuilder?: any): Promise<string>;
10
+ }
11
+ export type TNeo3NeoLegacyWaitForMigrationParams = {
12
+ transactionHash: string;
13
+ neo3Address: string;
14
+ neo3Service: IBlockchainService;
15
+ neoLegacyService: IBlockchainService;
16
+ };
17
+ export type TNeo3NeoLegacyMigrateParams<N extends string = string> = {
18
+ account: TBSAccount<N>;
19
+ neo3Address: string;
20
+ neoLegacyMigrationAmounts: TNeo3NeoLegacyMigrationNeoLegacyAmounts;
21
+ };
22
+ export type TNeo3NeoLegacyMigrationNeo3Amounts = {
23
+ gasMigrationTotalFees?: string;
24
+ neoMigrationTotalFees?: string;
25
+ gasMigrationReceiveAmount?: string;
26
+ neoMigrationReceiveAmount?: string;
27
+ };
28
+ export type TNeo3NeoLegacyMigrationNeoLegacyAmounts = {
29
+ hasEnoughGasBalance: boolean;
30
+ hasEnoughNeoBalance: boolean;
31
+ gasBalance?: TBalanceResponse;
32
+ neoBalance?: TBalanceResponse;
33
+ };
34
+ export declare enum ENeonJsLedgerServiceNeoLegacyStatus {
35
+ OK = 36864
36
+ }
37
+ export declare enum ENeonJsLedgerServiceNeoLegacyCommand {
38
+ GET_PUBLIC_KEY = 4,
39
+ SIGN = 2
40
+ }
41
+ export declare enum ENeonJsLedgerServiceNeoLegacyParameter {
42
+ MORE_DATA = 0,
43
+ LAST_DATA = 128
44
+ }
package/dist/types.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ENeonJsLedgerServiceNeoLegacyParameter = exports.ENeonJsLedgerServiceNeoLegacyCommand = exports.ENeonJsLedgerServiceNeoLegacyStatus = void 0;
4
+ var ENeonJsLedgerServiceNeoLegacyStatus;
5
+ (function (ENeonJsLedgerServiceNeoLegacyStatus) {
6
+ ENeonJsLedgerServiceNeoLegacyStatus[ENeonJsLedgerServiceNeoLegacyStatus["OK"] = 36864] = "OK";
7
+ })(ENeonJsLedgerServiceNeoLegacyStatus || (exports.ENeonJsLedgerServiceNeoLegacyStatus = ENeonJsLedgerServiceNeoLegacyStatus = {}));
8
+ var ENeonJsLedgerServiceNeoLegacyCommand;
9
+ (function (ENeonJsLedgerServiceNeoLegacyCommand) {
10
+ ENeonJsLedgerServiceNeoLegacyCommand[ENeonJsLedgerServiceNeoLegacyCommand["GET_PUBLIC_KEY"] = 4] = "GET_PUBLIC_KEY";
11
+ ENeonJsLedgerServiceNeoLegacyCommand[ENeonJsLedgerServiceNeoLegacyCommand["SIGN"] = 2] = "SIGN";
12
+ })(ENeonJsLedgerServiceNeoLegacyCommand || (exports.ENeonJsLedgerServiceNeoLegacyCommand = ENeonJsLedgerServiceNeoLegacyCommand = {}));
13
+ var ENeonJsLedgerServiceNeoLegacyParameter;
14
+ (function (ENeonJsLedgerServiceNeoLegacyParameter) {
15
+ ENeonJsLedgerServiceNeoLegacyParameter[ENeonJsLedgerServiceNeoLegacyParameter["MORE_DATA"] = 0] = "MORE_DATA";
16
+ ENeonJsLedgerServiceNeoLegacyParameter[ENeonJsLedgerServiceNeoLegacyParameter["LAST_DATA"] = 128] = "LAST_DATA";
17
+ })(ENeonJsLedgerServiceNeoLegacyParameter || (exports.ENeonJsLedgerServiceNeoLegacyParameter = ENeonJsLedgerServiceNeoLegacyParameter = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityofzion/bs-neo-legacy",
3
- "version": "1.13.4",
3
+ "version": "1.13.6",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "author": "Coz",
@@ -9,30 +9,28 @@
9
9
  "/dist"
10
10
  ],
11
11
  "dependencies": {
12
- "@cityofzion/dora-ts": "0.5.1",
12
+ "@cityofzion/dora-ts": "~0.5.1",
13
13
  "@cityofzion/neon-js": "4.8.3",
14
- "@ledgerhq/hw-transport": "~6.31.8",
15
- "axios": "~1.8.2",
16
- "date-fns": "~4.1.0",
17
- "@cityofzion/blockchain-service": "1.21.2",
18
- "@cityofzion/bs-asteroid-sdk": "0.9.1"
14
+ "axios": "~1.12.2",
15
+ "@cityofzion/blockchain-service": "1.22.1"
19
16
  },
20
17
  "devDependencies": {
21
- "@types/jest": "29.5.3",
22
- "@typescript-eslint/eslint-plugin": "^6.5.0",
23
- "@typescript-eslint/parser": "^6.5.0",
24
- "@ledgerhq/hw-transport-node-hid": "~6.28.5",
25
- "dotenv": "16.3.1",
26
- "eslint": "^8.48.0",
27
- "jest": "29.6.2",
28
- "ts-jest": "~29.4.0",
18
+ "@types/jest": "~30.0.0",
19
+ "@ledgerhq/hw-transport": "~6.31.11",
20
+ "@ledgerhq/hw-transport-node-hid": "~6.29.12",
21
+ "date-fns": "~4.1.0",
22
+ "dotenv": "~17.2.2",
23
+ "eslint": "~9.36.0",
24
+ "jest": "~30.1.3",
25
+ "ts-jest": "~29.4.4",
29
26
  "ts-node": "~10.9.2",
30
- "typescript": "4.9.5"
27
+ "typescript": "~5.9.2"
31
28
  },
32
29
  "scripts": {
33
- "build": "tsc --project tsconfig.build.json",
30
+ "build": "rm -rf ./dist && tsc --project tsconfig.build.json",
34
31
  "test": "jest --config jest.config.ts",
35
32
  "lint": "eslint .",
36
- "format": "eslint --fix"
33
+ "format": "eslint . --fix",
34
+ "package": "npm run build && npm pack"
37
35
  }
38
36
  }