@cityofzion/bs-neo3 1.1.2 → 1.2.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/BSNeo3.js CHANGED
@@ -195,7 +195,7 @@ _BSNeo3_instances = new WeakSet(), _BSNeo3_setTokens = function _BSNeo3_setToken
195
195
  ? neon_js_1.u.BigInteger.fromDecimal(intent.amount, intent.tokenDecimals).toString()
196
196
  : intent.amount,
197
197
  },
198
- { type: 'Any', value: '' },
198
+ { type: 'Any', value: null },
199
199
  ],
200
200
  };
201
201
  });
@@ -4,7 +4,7 @@ import { BSNeo3NetworkId } from './BSNeo3Helper';
4
4
  export declare class DoraBDSNeo3 extends RPCBDSNeo3 {
5
5
  constructor(network: Network<BSNeo3NetworkId>, feeToken: Token, claimToken: Token, tokens: Token[]);
6
6
  getTransaction(hash: string): Promise<TransactionResponse>;
7
- getTransactionsByAddress({ address, page, }: TransactionsByAddressParams): Promise<TransactionsByAddressResponse>;
7
+ getTransactionsByAddress({ address, nextPageParams, }: TransactionsByAddressParams): Promise<TransactionsByAddressResponse>;
8
8
  getContract(contractHash: string): Promise<ContractResponse>;
9
9
  getTokenInfo(tokenHash: string): Promise<Token>;
10
10
  getBalance(address: string): Promise<BalanceResponse[]>;
@@ -49,15 +49,15 @@ class DoraBDSNeo3 extends RpcBDSNeo3_1.RPCBDSNeo3 {
49
49
  }
50
50
  });
51
51
  }
52
- getTransactionsByAddress({ address, page = 1, }) {
52
+ getTransactionsByAddress({ address, nextPageParams = 1, }) {
53
53
  const _super = Object.create(null, {
54
54
  getTransactionsByAddress: { get: () => super.getTransactionsByAddress }
55
55
  });
56
56
  return __awaiter(this, void 0, void 0, function* () {
57
57
  if (BSNeo3Helper_1.BSNeo3Helper.isCustomNet(this._network)) {
58
- return yield _super.getTransactionsByAddress.call(this, { address, page });
58
+ return yield _super.getTransactionsByAddress.call(this, { address, nextPageParams });
59
59
  }
60
- const data = yield NeoRest.addressTXFull(address, page, this._network.id);
60
+ const data = yield NeoRest.addressTXFull(address, nextPageParams, this._network.id);
61
61
  const promises = data.items.map((item) => __awaiter(this, void 0, void 0, function* () {
62
62
  var _a, _b;
63
63
  const transferPromises = [];
@@ -111,10 +111,11 @@ class DoraBDSNeo3 extends RpcBDSNeo3_1.RPCBDSNeo3 {
111
111
  };
112
112
  }));
113
113
  const transactions = yield Promise.all(promises);
114
+ const limit = 15;
115
+ const totalPages = Math.ceil(data.totalCount / limit);
114
116
  return {
115
- totalCount: data.totalCount,
117
+ nextPageParams: nextPageParams < totalPages ? nextPageParams + 1 : undefined,
116
118
  transactions,
117
- limit: 15,
118
119
  };
119
120
  });
120
121
  }
@@ -2,6 +2,7 @@ import { Account, LedgerService, LedgerServiceEmitter } from '@cityofzion/blockc
2
2
  import Transport from '@ledgerhq/hw-transport';
3
3
  import { api } from '@cityofzion/neon-js';
4
4
  export declare class NeonDappKitLedgerServiceNeo3 implements LedgerService {
5
+ #private;
5
6
  getLedgerTransport?: ((account: Account) => Promise<Transport>) | undefined;
6
7
  emitter: LedgerServiceEmitter;
7
8
  constructor(getLedgerTransport?: ((account: Account) => Promise<Transport>) | undefined);
@@ -9,7 +10,4 @@ export declare class NeonDappKitLedgerServiceNeo3 implements LedgerService {
9
10
  getSigningCallback(transport: Transport): api.SigningFunction;
10
11
  getSignature(transport: Transport, serializedTransaction: string, networkMagic: number, addressIndex?: number): Promise<string>;
11
12
  getPublicKey(transport: Transport, addressIndex?: number): Promise<string>;
12
- private toBip44Buffer;
13
- private to8BitHex;
14
- private derSignatureToHex;
15
13
  }
@@ -8,17 +8,38 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
+ 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");
14
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
+ };
11
16
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
18
  };
19
+ var _NeonDappKitLedgerServiceNeo3_instances, _NeonDappKitLedgerServiceNeo3_sendChunk, _NeonDappKitLedgerServiceNeo3_toBip44, _NeonDappKitLedgerServiceNeo3_to8BitHex, _NeonDappKitLedgerServiceNeo3_derSignatureToHex;
14
20
  Object.defineProperty(exports, "__esModule", { value: true });
15
21
  exports.NeonDappKitLedgerServiceNeo3 = void 0;
16
22
  const neon_js_1 = require("@cityofzion/neon-js");
17
23
  const neon_dappkit_1 = require("@cityofzion/neon-dappkit");
18
24
  const events_1 = __importDefault(require("events"));
25
+ var LedgerStatus;
26
+ (function (LedgerStatus) {
27
+ LedgerStatus[LedgerStatus["OK"] = 36864] = "OK";
28
+ })(LedgerStatus || (LedgerStatus = {}));
29
+ var LedgerCommand;
30
+ (function (LedgerCommand) {
31
+ LedgerCommand[LedgerCommand["GET_PUBLIC_KEY"] = 4] = "GET_PUBLIC_KEY";
32
+ LedgerCommand[LedgerCommand["SIGN"] = 2] = "SIGN";
33
+ })(LedgerCommand || (LedgerCommand = {}));
34
+ var LedgerSecondParameter;
35
+ (function (LedgerSecondParameter) {
36
+ LedgerSecondParameter[LedgerSecondParameter["MORE_DATA"] = 128] = "MORE_DATA";
37
+ LedgerSecondParameter[LedgerSecondParameter["LAST_DATA"] = 0] = "LAST_DATA";
38
+ })(LedgerSecondParameter || (LedgerSecondParameter = {}));
19
39
  class NeonDappKitLedgerServiceNeo3 {
20
40
  constructor(getLedgerTransport) {
21
41
  this.getLedgerTransport = getLedgerTransport;
42
+ _NeonDappKitLedgerServiceNeo3_instances.add(this);
22
43
  this.emitter = new events_1.default();
23
44
  }
24
45
  getAddress(transport) {
@@ -44,20 +65,24 @@ class NeonDappKitLedgerServiceNeo3 {
44
65
  return __awaiter(this, void 0, void 0, function* () {
45
66
  try {
46
67
  this.emitter.emit('getSignatureStart');
47
- const bip44Buffer = this.toBip44Buffer(addressIndex);
48
- yield transport.send(0x80, 0x02, 0, 0x80, bip44Buffer, [0x9000]);
49
- yield transport.send(0x80, 0x02, 1, 0x80, Buffer.from(neon_dappkit_1.NeonParser.numToHex(networkMagic, 4, true), 'hex'), [
50
- 0x9000,
51
- ]);
68
+ const bip44 = __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_toBip44).call(this, addressIndex);
69
+ // Send the BIP44 account as first chunk
70
+ yield __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_sendChunk).call(this, transport, LedgerCommand.SIGN, 0, LedgerSecondParameter.MORE_DATA, bip44);
71
+ // Send the network magic as second chunk
72
+ yield __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_sendChunk).call(this, transport, LedgerCommand.SIGN, 1, LedgerSecondParameter.MORE_DATA, neon_dappkit_1.NeonParser.numToHex(networkMagic, 4, true));
52
73
  const chunks = serializedTransaction.match(/.{1,510}/g) || [];
53
74
  for (let i = 0; i < chunks.length - 1; i++) {
54
- yield transport.send(0x80, 0x02, 2 + i, 0x80, Buffer.from(chunks[i], 'hex'), [0x9000]);
75
+ // We plus 2 because we already sent 2 chunks before
76
+ const commandIndex = 2 + i;
77
+ yield __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_sendChunk).call(this, transport, LedgerCommand.SIGN, commandIndex, LedgerSecondParameter.MORE_DATA, chunks[i]);
55
78
  }
56
- const response = yield transport.send(0x80, 0x02, 2 + chunks.length, 0x00, Buffer.from(chunks[chunks.length - 1], 'hex'), [0x9000]);
79
+ // Again we plus 2 because we already sent 2 chunks before getting the chunks
80
+ const lastChunkIndex = 2 + chunks.length;
81
+ const response = yield __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_sendChunk).call(this, transport, LedgerCommand.SIGN, lastChunkIndex, LedgerSecondParameter.LAST_DATA, chunks[chunks.length - 1]);
57
82
  if (response.length <= 2) {
58
83
  throw new Error(`No more data but Ledger did not return signature!`);
59
84
  }
60
- const signature = this.derSignatureToHex(response.toString('hex'));
85
+ const signature = __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_derSignatureToHex).call(this, response.toString('hex'));
61
86
  return signature;
62
87
  }
63
88
  finally {
@@ -67,44 +92,44 @@ class NeonDappKitLedgerServiceNeo3 {
67
92
  }
68
93
  getPublicKey(transport, addressIndex = 0) {
69
94
  return __awaiter(this, void 0, void 0, function* () {
70
- const bip44Buffer = this.toBip44Buffer(addressIndex);
71
- const result = yield transport.send(0x80, 0x04, 0x00, 0x00, bip44Buffer, [0x9000]);
95
+ const bip44 = __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_toBip44).call(this, addressIndex);
96
+ const result = yield __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_sendChunk).call(this, transport, LedgerCommand.GET_PUBLIC_KEY, 0x00, LedgerSecondParameter.LAST_DATA, bip44);
72
97
  const publicKey = result.toString('hex').substring(0, 130);
73
98
  return publicKey;
74
99
  });
75
100
  }
76
- toBip44Buffer(addressIndex = 0, changeIndex = 0, accountIndex = 0) {
77
- const accountHex = this.to8BitHex(accountIndex + 0x80000000);
78
- const changeHex = this.to8BitHex(changeIndex);
79
- const addressHex = this.to8BitHex(addressIndex);
80
- return Buffer.from('8000002C' + '80000378' + accountHex + changeHex + addressHex, 'hex');
81
- }
82
- to8BitHex(num) {
83
- const hex = num.toString(16);
84
- return '0'.repeat(8 - hex.length) + hex;
85
- }
86
- derSignatureToHex(response) {
87
- const ss = new neon_js_1.u.StringStream(response);
88
- // The first byte is format. It is usually 0x30 (SEQ) or 0x31 (SET)
89
- // The second byte represents the total length of the DER module.
90
- ss.read(2);
91
- // Now we read each field off
92
- // Each field is encoded with a type byte, length byte followed by the data itself
93
- ss.read(1); // Read and drop the type
94
- const r = ss.readVarBytes();
95
- ss.read(1);
96
- const s = ss.readVarBytes();
97
- // We will need to ensure both integers are 32 bytes long
98
- const integers = [r, s].map(i => {
99
- if (i.length < 64) {
100
- i = '0'.repeat(i.length - 64) + i;
101
- }
102
- if (i.length > 64) {
103
- i = i.substr(-64);
104
- }
105
- return i;
106
- });
107
- return integers.join('');
108
- }
109
101
  }
110
102
  exports.NeonDappKitLedgerServiceNeo3 = NeonDappKitLedgerServiceNeo3;
103
+ _NeonDappKitLedgerServiceNeo3_instances = new WeakSet(), _NeonDappKitLedgerServiceNeo3_sendChunk = function _NeonDappKitLedgerServiceNeo3_sendChunk(transport, command, commandIndex, secondParameter, chunk) {
104
+ return transport.send(0x80, command, commandIndex, secondParameter, Buffer.from(chunk, 'hex'), [LedgerStatus.OK]);
105
+ }, _NeonDappKitLedgerServiceNeo3_toBip44 = function _NeonDappKitLedgerServiceNeo3_toBip44(addressIndex = 0, changeIndex = 0, accountIndex = 0) {
106
+ const accountHex = __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_to8BitHex).call(this, accountIndex + 0x80000000);
107
+ const changeHex = __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_to8BitHex).call(this, changeIndex);
108
+ const addressHex = __classPrivateFieldGet(this, _NeonDappKitLedgerServiceNeo3_instances, "m", _NeonDappKitLedgerServiceNeo3_to8BitHex).call(this, addressIndex);
109
+ return '8000002C' + '80000378' + accountHex + changeHex + addressHex;
110
+ }, _NeonDappKitLedgerServiceNeo3_to8BitHex = function _NeonDappKitLedgerServiceNeo3_to8BitHex(num) {
111
+ const hex = num.toString(16);
112
+ return '0'.repeat(8 - hex.length) + hex;
113
+ }, _NeonDappKitLedgerServiceNeo3_derSignatureToHex = function _NeonDappKitLedgerServiceNeo3_derSignatureToHex(response) {
114
+ const ss = new neon_js_1.u.StringStream(response);
115
+ // The first byte is format. It is usually 0x30 (SEQ) or 0x31 (SET)
116
+ // The second byte represents the total length of the DER module.
117
+ ss.read(2);
118
+ // Now we read each field off
119
+ // Each field is encoded with a type byte, length byte followed by the data itself
120
+ ss.read(1); // Read and drop the type
121
+ const r = ss.readVarBytes();
122
+ ss.read(1);
123
+ const s = ss.readVarBytes();
124
+ // We will need to ensure both integers are 32 bytes long
125
+ const integers = [r, s].map(i => {
126
+ if (i.length < 64) {
127
+ i = '0'.repeat(i.length - 64) + i;
128
+ }
129
+ if (i.length > 64) {
130
+ i = i.substr(-64);
131
+ }
132
+ return i;
133
+ });
134
+ return integers.join('');
135
+ };
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
+ export * from './flamingo-swap/FlamingoSwapControllerService';
2
+ export * from './flamingo-swap/FlamingoSwapHelper';
3
+ export * from './flamingo-swap/FlamingoSwapNeonDappKitInvocationBuilder';
1
4
  export * from './BSNeo3';
2
5
  export * from './BSNeo3Helper';
3
6
  export * from './DoraBDSNeo3';
4
- export * from './RpcBDSNeo3';
5
7
  export * from './DoraESNeo3';
6
8
  export * from './FlamingoEDSNeo3';
7
9
  export * from './GhostMarketNDSNeo3';
8
- export * from './RpcNDSNeo3';
9
10
  export * from './NeonDappKitLedgerServiceNeo3';
10
- export * from './flamingo-swap/FlamingoSwapControllerService';
11
- export * from './flamingo-swap/FlamingoSwapHelper';
12
- export * from './flamingo-swap/FlamingoSwapNeonDappKitInvocationBuilder';
11
+ export * from './RpcBDSNeo3';
12
+ export * from './RpcNDSNeo3';
package/dist/index.js CHANGED
@@ -14,15 +14,15 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./flamingo-swap/FlamingoSwapControllerService"), exports);
18
+ __exportStar(require("./flamingo-swap/FlamingoSwapHelper"), exports);
19
+ __exportStar(require("./flamingo-swap/FlamingoSwapNeonDappKitInvocationBuilder"), exports);
17
20
  __exportStar(require("./BSNeo3"), exports);
18
21
  __exportStar(require("./BSNeo3Helper"), exports);
19
22
  __exportStar(require("./DoraBDSNeo3"), exports);
20
- __exportStar(require("./RpcBDSNeo3"), exports);
21
23
  __exportStar(require("./DoraESNeo3"), exports);
22
24
  __exportStar(require("./FlamingoEDSNeo3"), exports);
23
25
  __exportStar(require("./GhostMarketNDSNeo3"), exports);
24
- __exportStar(require("./RpcNDSNeo3"), exports);
25
26
  __exportStar(require("./NeonDappKitLedgerServiceNeo3"), exports);
26
- __exportStar(require("./flamingo-swap/FlamingoSwapControllerService"), exports);
27
- __exportStar(require("./flamingo-swap/FlamingoSwapHelper"), exports);
28
- __exportStar(require("./flamingo-swap/FlamingoSwapNeonDappKitInvocationBuilder"), exports);
27
+ __exportStar(require("./RpcBDSNeo3"), exports);
28
+ __exportStar(require("./RpcNDSNeo3"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityofzion/bs-neo3",
3
- "version": "1.1.2",
3
+ "version": "1.2.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": "https://github.com/CityOfZion/blockchain-services",
@@ -19,8 +19,8 @@
19
19
  "@cityofzion/neon-dappkit": "0.4.1",
20
20
  "bignumber.js": "~9.1.2",
21
21
  "isomorphic-ws": "~5.0.0",
22
- "@cityofzion/blockchain-service": "1.1.0",
23
- "@cityofzion/bs-asteroid-sdk": "0.9.0"
22
+ "@cityofzion/bs-asteroid-sdk": "0.9.0",
23
+ "@cityofzion/blockchain-service": "1.2.0"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@cityofzion/neon-dappkit-types": "~0.3.1",