@cityofzion/bs-neo3 0.8.0 → 0.9.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.
@@ -1,3 +1,3 @@
1
1
  {
2
- "nonCachedDurationMs": 2137.4206459999987
2
+ "nonCachedDurationMs": 2202.782708999992
3
3
  }
@@ -1,16 +1,18 @@
1
1
  {
2
2
  "files": {
3
+ "packages/bs-neo3/CHANGELOG.json": "3f3d2b73b8c94585680bd6eea606e773f1cfebd4",
4
+ "packages/bs-neo3/CHANGELOG.md": "b151fbc882d1607cdba6f031e47199ffc331ff04",
3
5
  "packages/bs-neo3/jest.config.ts": "d944475db93cbe41a9339187fd94b9962e411c43",
4
6
  "packages/bs-neo3/jest.setup.ts": "9a1976a32050616d4d2ee95b1aa21041bc4daca3",
5
- "packages/bs-neo3/package.json": "73982aa01341d1bfca928b3ad79fafeddb8fe5eb",
6
- "packages/bs-neo3/src/BSNeo3.ts": "ac017ee69800b8bf170face0e9e38bb72d8ad2a3",
7
- "packages/bs-neo3/src/DoraBDSNeo3.ts": "7891be397db816f811631e56c1abf32bbd0b2a36",
7
+ "packages/bs-neo3/package.json": "ae7b212ffc3e029c08d9770feb0ca8b82bca2a77",
8
+ "packages/bs-neo3/src/BSNeo3.ts": "e7235ac3cb4cef569443b4fbef6cb787972de25b",
9
+ "packages/bs-neo3/src/DoraBDSNeo3.ts": "97e90b38cc18fa6376f4c7bb5996d88c57efa5bc",
8
10
  "packages/bs-neo3/src/DoraESNeo3.ts": "c3d36ee5c38cda45c08f517c49976af6d69c5711",
9
11
  "packages/bs-neo3/src/FlamingoEDSNeo3.ts": "041aa79e04b2fafb6da71178e7bcc7011f416c1d",
10
12
  "packages/bs-neo3/src/GhostMarketNDSNeo3.ts": "d7db2a624cf099fe550fa4a906f6127ca4815cac",
11
13
  "packages/bs-neo3/src/RpcBDSNeo3.ts": "11a7425844ab09a11c631281e103d1edeab4a63f",
12
- "packages/bs-neo3/src/__tests__/BDSNeo3.spec.ts": "14bd204f3d4546c81b6ea37e16f3fe6e70102dd1",
13
- "packages/bs-neo3/src/__tests__/BSNeo3.spec.ts": "edf56afc2efaa15d252eaaca0325cee364191699",
14
+ "packages/bs-neo3/src/__tests__/BDSNeo3.spec.ts": "ac5f20eac558af993c97a8d0d214e2865c916d44",
15
+ "packages/bs-neo3/src/__tests__/BSNeo3.spec.ts": "b1a3d7fca99e984f32bfe0b0a6aed3a25b5de375",
14
16
  "packages/bs-neo3/src/__tests__/DoraESNeo3.spec.ts": "450e087014c22b1a289e64dd80ff3e6ddfd8c932",
15
17
  "packages/bs-neo3/src/__tests__/FlamingoEDSNeo3.spec.ts": "473b1aafe03031a28a8414dfa681b06f843acdf6",
16
18
  "packages/bs-neo3/src/__tests__/GhostMarketNDSNeo3.spec.ts": "1d583380b60112fb99426b4bf140c92898177b1e",
@@ -21,9 +23,7 @@
21
23
  "packages/bs-neo3/src/index.ts": "bad314a9ba14b57075684c9b823a934863bac6b2",
22
24
  "packages/bs-neo3/tsconfig.build.json": "4dc23fb9c4c5e4d19a9bc3947a47c523f4bd967c",
23
25
  "packages/bs-neo3/tsconfig.json": "77cf2b789e9c665b62792f9992cc81ae86296ef7",
24
- "packages/bs-neo3/.rush/temp/shrinkwrap-deps.json": "7348b8936da22d117d50dfb8445815a3fabc42cb",
25
- "packages/bs-neo3/CHANGELOG.json": "4342936f2b30b621d5e4d5a5132fb78671f03c58",
26
- "packages/bs-neo3/CHANGELOG.md": "0966cf0340002b2d3b964d6b1f88995bf0bf53bd"
26
+ "packages/bs-neo3/.rush/temp/shrinkwrap-deps.json": "7348b8936da22d117d50dfb8445815a3fabc42cb"
27
27
  },
28
28
  "arguments": "tsc --project tsconfig.build.json "
29
29
  }
package/CHANGELOG.json CHANGED
@@ -2,9 +2,21 @@
2
2
  "name": "@cityofzion/bs-neo3",
3
3
  "entries": [
4
4
  {
5
- "version": "0.8.0",
6
- "tag": "@cityofzion/bs-neo3_v0.8.0",
7
- "date": "Mon, 27 Nov 2023 22:13:46 GMT",
5
+ "version": "0.9.1",
6
+ "tag": "@cityofzion/bs-neo3_v0.9.1",
7
+ "date": "Wed, 06 Dec 2023 21:51:30 GMT",
8
+ "comments": {
9
+ "patch": [
10
+ {
11
+ "comment": "Prevent the getAllTransaction method from breaking when Dora returns data from v1"
12
+ }
13
+ ]
14
+ }
15
+ },
16
+ {
17
+ "version": "0.9.0",
18
+ "tag": "@cityofzion/bs-neo3_v0.9.0",
19
+ "date": "Tue, 05 Dec 2023 18:42:10 GMT",
8
20
  "comments": {
9
21
  "minor": [
10
22
  {
@@ -13,7 +25,7 @@
13
25
  ],
14
26
  "dependency": [
15
27
  {
16
- "comment": "Updating dependency \"@cityofzion/blockchain-service\" to `0.8.0`"
28
+ "comment": "Updating dependency \"@cityofzion/blockchain-service\" to `0.9.0`"
17
29
  }
18
30
  ]
19
31
  }
package/CHANGELOG.md CHANGED
@@ -1,9 +1,16 @@
1
1
  # Change Log - @cityofzion/bs-neo3
2
2
 
3
- This log was last generated on Mon, 27 Nov 2023 22:13:46 GMT and should not be manually modified.
3
+ This log was last generated on Wed, 06 Dec 2023 21:51:30 GMT and should not be manually modified.
4
4
 
5
- ## 0.8.0
6
- Mon, 27 Nov 2023 22:13:46 GMT
5
+ ## 0.9.1
6
+ Wed, 06 Dec 2023 21:51:30 GMT
7
+
8
+ ### Patches
9
+
10
+ - Prevent the getAllTransaction method from breaking when Dora returns data from v1
11
+
12
+ ## 0.9.0
13
+ Tue, 05 Dec 2023 18:42:10 GMT
7
14
 
8
15
  ### Minor changes
9
16
 
package/dist/BSNeo3.d.ts CHANGED
@@ -20,6 +20,7 @@ export declare class BSNeo3<BSCustomName extends string = string> implements Blo
20
20
  generateAccountFromMnemonic(mnemonic: string[] | string, index: number): AccountWithDerivationPath;
21
21
  generateAccountFromKey(key: string): Account;
22
22
  decrypt(encryptedKey: string, password: string): Promise<Account>;
23
+ encrypt(key: string, password: string): Promise<string>;
23
24
  calculateTransferFee(param: TransferParam): Promise<string>;
24
25
  transfer(param: TransferParam): Promise<string>;
25
26
  claim(account: Account): Promise<string>;
package/dist/BSNeo3.js CHANGED
@@ -95,6 +95,9 @@ class BSNeo3 {
95
95
  return this.generateAccountFromKey(privateKey);
96
96
  });
97
97
  }
98
+ encrypt(key, password) {
99
+ return neon_js_1.wallet.encrypt(key, password);
100
+ }
98
101
  calculateTransferFee(param) {
99
102
  return __awaiter(this, void 0, void 0, function* () {
100
103
  const account = new neon_js_1.wallet.Account(param.senderAccount.key);
@@ -50,36 +50,42 @@ class DoraBDSNeo3 extends RpcBDSNeo3_1.RPCBDSNeo3 {
50
50
  getTransactionsByAddress({ address, page = 1, }) {
51
51
  return __awaiter(this, void 0, void 0, function* () {
52
52
  const data = yield NeoRest.addressTXFull(address, page, this.network.type);
53
- const transactions = yield Promise.all(data.items.map((item) => __awaiter(this, void 0, void 0, function* () {
53
+ const promises = data.items.map((item) => __awaiter(this, void 0, void 0, function* () {
54
54
  var _a, _b;
55
- const filteredTransfers = item.notifications.filter(item => item.event_name === 'Transfer' && (item.state.value.length === 3 || item.state.value.length === 4));
56
- const transferPromises = filteredTransfers.map(({ contract: contractHash, state: { value: properties } }) => __awaiter(this, void 0, void 0, function* () {
57
- var _c;
58
- const isAsset = properties.length === 3;
59
- const from = properties[0].value;
60
- const to = properties[1].value;
61
- const convertedFrom = from ? this.convertByteStringToAddress(from) : 'Mint';
62
- const convertedTo = to ? this.convertByteStringToAddress(to) : 'Burn';
63
- if (isAsset) {
64
- const token = yield this.getTokenInfo(contractHash);
65
- const [, , { value: amount }] = properties;
55
+ const transferPromises = [];
56
+ item.notifications.forEach(({ contract: contractHash, state, event_name: eventName }) => {
57
+ const properties = Array.isArray(state) ? state : state.value;
58
+ if (eventName !== 'Transfer' || (properties.length !== 3 && properties.length !== 4))
59
+ return;
60
+ const promise = () => __awaiter(this, void 0, void 0, function* () {
61
+ var _a;
62
+ const isAsset = properties.length === 3;
63
+ const from = properties[0].value;
64
+ const to = properties[1].value;
65
+ const convertedFrom = from ? this.convertByteStringToAddress(from) : 'Mint';
66
+ const convertedTo = to ? this.convertByteStringToAddress(to) : 'Burn';
67
+ if (isAsset) {
68
+ const token = yield this.getTokenInfo(contractHash);
69
+ const [, , { value: amount }] = properties;
70
+ return {
71
+ amount: neon_js_1.u.BigInteger.fromNumber(amount).toDecimal((_a = token.decimals) !== null && _a !== void 0 ? _a : 0),
72
+ from: convertedFrom,
73
+ to: convertedTo,
74
+ contractHash,
75
+ type: 'token',
76
+ token,
77
+ };
78
+ }
66
79
  return {
67
- amount: neon_js_1.u.BigInteger.fromNumber(amount).toDecimal((_c = token.decimals) !== null && _c !== void 0 ? _c : 0),
68
80
  from: convertedFrom,
69
81
  to: convertedTo,
82
+ tokenId: properties[3].value,
70
83
  contractHash,
71
- type: 'token',
72
- token,
84
+ type: 'nft',
73
85
  };
74
- }
75
- return {
76
- from: convertedFrom,
77
- to: convertedTo,
78
- tokenId: properties[3].value,
79
- contractHash,
80
- type: 'nft',
81
- };
82
- }));
86
+ });
87
+ transferPromises.push(promise());
88
+ });
83
89
  const transfers = yield Promise.all(transferPromises);
84
90
  const notifications = item.notifications.map(notification => ({
85
91
  eventName: notification.event_name,
@@ -95,7 +101,8 @@ class DoraBDSNeo3 extends RpcBDSNeo3_1.RPCBDSNeo3 {
95
101
  transfers,
96
102
  notifications,
97
103
  };
98
- })));
104
+ }));
105
+ const transactions = yield Promise.all(promises);
99
106
  return {
100
107
  totalCount: data.totalCount,
101
108
  transactions,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityofzion/bs-neo3",
3
- "version": "0.8.0",
3
+ "version": "0.9.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": "https://github.com/CityOfZion/blockchain-services",
@@ -16,7 +16,7 @@
16
16
  "@cityofzion/dora-ts": "0.0.11",
17
17
  "axios": "1.5.1",
18
18
  "query-string": "7.1.3",
19
- "@cityofzion/blockchain-service": "0.8.0",
19
+ "@cityofzion/blockchain-service": "0.9.0",
20
20
  "@cityofzion/bs-asteroid-sdk": "0.7.3"
21
21
  },
22
22
  "devDependencies": {
package/src/BSNeo3.ts CHANGED
@@ -130,6 +130,10 @@ export class BSNeo3<BSCustomName extends string = string>
130
130
  return this.generateAccountFromKey(privateKey)
131
131
  }
132
132
 
133
+ encrypt(key: string, password: string): Promise<string> {
134
+ return wallet.encrypt(key, password)
135
+ }
136
+
133
137
  async calculateTransferFee(param: TransferParam): Promise<string> {
134
138
  const account = new wallet.Account(param.senderAccount.key)
135
139
  const invoker = await NeonInvoker.init({
@@ -55,61 +55,67 @@ export class DoraBDSNeo3 extends RPCBDSNeo3 {
55
55
  page = 1,
56
56
  }: TransactionsByAddressParams): Promise<TransactionsByAddressResponse> {
57
57
  const data = await NeoRest.addressTXFull(address, page, this.network.type)
58
- const transactions = await Promise.all(
59
- data.items.map(async (item): Promise<TransactionResponse> => {
60
- const filteredTransfers = item.notifications.filter(
61
- item => item.event_name === 'Transfer' && (item.state.value.length === 3 || item.state.value.length === 4)
62
- )
63
- const transferPromises = filteredTransfers.map<Promise<TransactionTransferAsset | TransactionTransferNft>>(
64
- async ({ contract: contractHash, state: { value: properties } }) => {
65
- const isAsset = properties.length === 3
66
-
67
- const from = properties[0].value
68
- const to = properties[1].value
69
- const convertedFrom = from ? this.convertByteStringToAddress(from) : 'Mint'
70
- const convertedTo = to ? this.convertByteStringToAddress(to) : 'Burn'
71
-
72
- if (isAsset) {
73
- const token = await this.getTokenInfo(contractHash)
74
- const [, , { value: amount }] = properties
75
- return {
76
- amount: u.BigInteger.fromNumber(amount).toDecimal(token.decimals ?? 0),
77
- from: convertedFrom,
78
- to: convertedTo,
79
- contractHash,
80
- type: 'token',
81
- token,
82
- }
83
- }
84
58
 
59
+ const promises = data.items.map(async (item): Promise<TransactionResponse> => {
60
+ const transferPromises: Promise<TransactionTransferAsset | TransactionTransferNft>[] = []
61
+
62
+ item.notifications.forEach(({ contract: contractHash, state, event_name: eventName }) => {
63
+ const properties = Array.isArray(state) ? state : state.value
64
+ if (eventName !== 'Transfer' || (properties.length !== 3 && properties.length !== 4)) return
65
+
66
+ const promise = async (): Promise<TransactionTransferAsset | TransactionTransferNft> => {
67
+ const isAsset = properties.length === 3
68
+
69
+ const from = properties[0].value
70
+ const to = properties[1].value
71
+ const convertedFrom = from ? this.convertByteStringToAddress(from) : 'Mint'
72
+ const convertedTo = to ? this.convertByteStringToAddress(to) : 'Burn'
73
+
74
+ if (isAsset) {
75
+ const token = await this.getTokenInfo(contractHash)
76
+ const [, , { value: amount }] = properties
85
77
  return {
78
+ amount: u.BigInteger.fromNumber(amount).toDecimal(token.decimals ?? 0),
86
79
  from: convertedFrom,
87
80
  to: convertedTo,
88
- tokenId: properties[3].value,
89
81
  contractHash,
90
- type: 'nft',
82
+ type: 'token',
83
+ token,
91
84
  }
92
85
  }
93
- )
94
- const transfers = await Promise.all(transferPromises)
95
86
 
96
- const notifications = item.notifications.map<TransactionNotifications>(notification => ({
97
- eventName: notification.event_name,
98
- state: notification.state as any,
99
- }))
100
-
101
- return {
102
- block: item.block,
103
- time: Number(item.time),
104
- hash: item.hash,
105
- fee: u.BigInteger.fromNumber(item.netfee ?? 0)
106
- .add(u.BigInteger.fromNumber(item.sysfee ?? 0))
107
- .toDecimal(this.feeToken.decimals),
108
- transfers,
109
- notifications,
87
+ return {
88
+ from: convertedFrom,
89
+ to: convertedTo,
90
+ tokenId: properties[3].value,
91
+ contractHash,
92
+ type: 'nft',
93
+ }
110
94
  }
95
+
96
+ transferPromises.push(promise())
111
97
  })
112
- )
98
+
99
+ const transfers = await Promise.all(transferPromises)
100
+
101
+ const notifications = item.notifications.map<TransactionNotifications>(notification => ({
102
+ eventName: notification.event_name,
103
+ state: notification.state as any,
104
+ }))
105
+
106
+ return {
107
+ block: item.block,
108
+ time: Number(item.time),
109
+ hash: item.hash,
110
+ fee: u.BigInteger.fromNumber(item.netfee ?? 0)
111
+ .add(u.BigInteger.fromNumber(item.sysfee ?? 0))
112
+ .toDecimal(this.feeToken.decimals),
113
+ transfers,
114
+ notifications,
115
+ }
116
+ })
117
+
118
+ const transactions = await Promise.all(promises)
113
119
 
114
120
  return {
115
121
  totalCount: data.totalCount,
@@ -27,43 +27,41 @@ describe('BDSNeo3', () => {
27
27
  }
28
28
  )
29
29
 
30
- it.each([doraBDSNeo3, rpcBDSNeo3])(
30
+ it.each([doraBDSNeo3])(
31
31
  'Should be able to get transactions of address - %s',
32
32
  async (bdsNeo3: BlockchainDataService) => {
33
33
  const address = 'NNmTVFrSPhe7zjgN6iq9cLgXJwLZziUKV6'
34
- try {
35
- const response = await bdsNeo3.getTransactionsByAddress({ address, page: 1 })
34
+ const response = await bdsNeo3.getTransactionsByAddress({ address, page: 1 })
36
35
 
37
- response.transactions.forEach(transaction => {
38
- expect(transaction).toEqual(
39
- expect.objectContaining({
40
- block: expect.any(Number),
41
- hash: expect.any(String),
42
- notifications: expect.arrayContaining([
43
- expect.objectContaining({
44
- eventName: expect.any(String),
45
- state: expect.arrayContaining([
46
- {
47
- type: expect.any(String),
48
- value: expect.any(String),
49
- },
50
- ]),
51
- }),
52
- ]),
53
- transfers: expect.arrayContaining([
54
- expect.objectContaining({
55
- amount: expect.any(String),
56
- from: expect.any(String),
57
- to: expect.any(String),
58
- type: 'asset',
59
- }),
60
- ]),
61
- time: expect.any(Number),
62
- fee: expect.any(String),
63
- })
64
- )
65
- })
66
- } catch {}
36
+ response.transactions.forEach(transaction => {
37
+ expect(transaction).toEqual(
38
+ expect.objectContaining({
39
+ block: expect.any(Number),
40
+ hash: expect.any(String),
41
+ time: expect.any(Number),
42
+ fee: expect.any(String),
43
+ notifications: expect.arrayContaining([
44
+ expect.objectContaining({
45
+ eventName: expect.any(String),
46
+ state: expect.arrayContaining([
47
+ {
48
+ type: expect.any(String),
49
+ value: expect.any(String),
50
+ },
51
+ ]),
52
+ }),
53
+ ]),
54
+ transfers: expect.arrayContaining([
55
+ expect.objectContaining({
56
+ amount: expect.any(String),
57
+ from: expect.any(String),
58
+ to: expect.any(String),
59
+ type: 'token',
60
+ }),
61
+ ]),
62
+ })
63
+ )
64
+ })
67
65
  }
68
66
  )
69
67
 
@@ -69,11 +69,19 @@ describe('BSNeo3', () => {
69
69
  const mnemonic = generateMnemonic()
70
70
  const account = bsNeo3.generateAccountFromMnemonic(mnemonic, 0)
71
71
  const password = 'TestPassword'
72
- const encryptedKey = await wallet.encrypt(account.key, password)
72
+ const encryptedKey = await bsNeo3.encrypt(account.key, password)
73
73
  const decryptedAccount = await bsNeo3.decrypt(encryptedKey, password)
74
74
  expect(account).toEqual(expect.objectContaining(decryptedAccount))
75
75
  }, 20000)
76
76
 
77
+ it('Should be able to encrypt a key', async () => {
78
+ const mnemonic = generateMnemonic()
79
+ const account = bsNeo3.generateAccountFromMnemonic(mnemonic, 0)
80
+ const password = 'TestPassword'
81
+ const encryptedKey = await bsNeo3.encrypt(account.key, password)
82
+ expect(encryptedKey).toEqual(expect.any(String))
83
+ })
84
+
77
85
  it.skip('Should be able to calculate transfer fee', async () => {
78
86
  const account = bsNeo3.generateAccountFromKey(process.env.TESTNET_PRIVATE_KEY as string)
79
87