@cityofzion/bs-neo-legacy 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.
@@ -3,11 +3,9 @@ export declare const TOKENS: Record<NetworkType, Token[]>;
3
3
  export declare const LEGACY_NETWORK_BY_NETWORK_TYPE: Record<Exclude<NetworkType, 'custom'>, string>;
4
4
  export declare const NATIVE_ASSETS: {
5
5
  symbol: string;
6
- type: string;
7
6
  name: string;
8
7
  hash: string;
9
8
  decimals: number;
10
- blockchain: string;
11
9
  }[];
12
10
  export declare const DEFAULT_URL_BY_NETWORK_TYPE: Record<Exclude<NetworkType, 'custom'>, string>;
13
11
  export declare const DERIVATION_PATH = "m/44'/888'/0'/0/?";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityofzion/bs-neo-legacy",
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
  "author": "Coz",
@@ -9,19 +9,24 @@
9
9
  "@cityofzion/dora-ts": "0.0.11",
10
10
  "@cityofzion/neon-js": "4.8.3",
11
11
  "axios": "1.5.1",
12
- "@cityofzion/blockchain-service": "0.8.0",
12
+ "@cityofzion/blockchain-service": "0.9.0",
13
13
  "@cityofzion/bs-asteroid-sdk": "0.7.3"
14
14
  },
15
15
  "devDependencies": {
16
- "ts-node": "10.9.1",
17
- "typescript": "4.9.5",
16
+ "@types/jest": "29.5.3",
17
+ "@typescript-eslint/eslint-plugin": "^6.5.0",
18
+ "@typescript-eslint/parser": "^6.5.0",
19
+ "dotenv": "16.3.1",
20
+ "eslint": "^8.48.0",
18
21
  "jest": "29.6.2",
19
22
  "ts-jest": "29.1.1",
20
- "@types/jest": "29.5.3",
21
- "dotenv": "16.3.1"
23
+ "ts-node": "10.9.1",
24
+ "typescript": "4.9.5"
22
25
  },
23
26
  "scripts": {
24
27
  "build": "tsc --project tsconfig.build.json",
25
- "test": "jest --config jest.config.ts"
28
+ "test": "jest --config jest.config.ts",
29
+ "lint": "eslint .",
30
+ "format": "eslint --fix"
26
31
  }
27
32
  }
@@ -27,8 +27,7 @@ import { keychain } from '@cityofzion/bs-asteroid-sdk'
27
27
  import { DoraESNeoLegacy } from './DoraESNeoLegacy'
28
28
 
29
29
  export class BSNeoLegacy<BSCustomName extends string = string>
30
- implements BlockchainService, BSClaimable, BSWithExplorerService
31
- {
30
+ implements BlockchainService, BSClaimable, BSWithExplorerService {
32
31
  readonly blockchainName: BSCustomName
33
32
  readonly feeToken: Token
34
33
  readonly claimToken: Token
@@ -103,19 +102,23 @@ export class BSNeoLegacy<BSCustomName extends string = string>
103
102
  try {
104
103
  const { NativeModules } = require('react-native')
105
104
  BsReactNativeDecrypt = NativeModules.BsReactNativeDecrypt
105
+
106
+ if (!BsReactNativeDecrypt) {
107
+ throw new Error('@CityOfZion/bs-react-native-decrypt is not installed')
108
+ }
106
109
  } catch {
107
110
  const key = await wallet.decrypt(encryptedKey, password)
108
111
  return this.generateAccountFromKey(key)
109
112
  }
110
113
 
111
- if (!BsReactNativeDecrypt) {
112
- throw new Error('@CityOfZion/bs-react-native-decrypt is not installed')
113
- }
114
-
115
114
  const privateKey = await BsReactNativeDecrypt.decryptNeoLegacy(encryptedKey, password)
116
115
  return this.generateAccountFromKey(privateKey)
117
116
  }
118
117
 
118
+ encrypt(key: string, password: string): Promise<string> {
119
+ return wallet.encrypt(key, password)
120
+ }
121
+
119
122
  async transfer({ intent: transferIntent, senderAccount, tipIntent, ...params }: TransferParam): Promise<string> {
120
123
  const apiProvider = new api.neoCli.instance(this.network.url)
121
124
  const account = new wallet.Account(senderAccount.key)
@@ -8,7 +8,6 @@ import {
8
8
  BDSClaimable,
9
9
  TransactionTransferAsset,
10
10
  Token,
11
- NetworkType,
12
11
  Network,
13
12
  } from '@cityofzion/blockchain-service'
14
13
  import { api } from '@cityofzion/dora-ts'
@@ -124,7 +123,7 @@ export class DoraBDSNeoLegacy implements BlockchainDataService, BDSClaimable {
124
123
  if (!data || 'error' in data) throw new Error(`Token ${tokenHash} not found`)
125
124
 
126
125
  const token = {
127
- decimals: data.decimals,
126
+ decimals: Number(data.decimals),
128
127
  symbol: data.symbol,
129
128
  hash: data.scripthash,
130
129
  name: data.name,
@@ -139,16 +138,20 @@ export class DoraBDSNeoLegacy implements BlockchainDataService, BDSClaimable {
139
138
  const data = await api.NeoLegacyREST.balance(address, this.network.type)
140
139
 
141
140
  const promises = data.map<Promise<BalanceResponse>>(async balance => {
141
+ const hash = balance.asset.replace('0x', '')
142
+
142
143
  let token: Token = {
143
- hash: balance.asset,
144
+ hash,
144
145
  name: balance.asset_name,
145
146
  symbol: balance.symbol,
146
147
  decimals: 8,
147
148
  }
148
149
 
149
150
  try {
150
- token = await this.getTokenInfo(balance.asset)
151
- } catch {}
151
+ token = await this.getTokenInfo(hash)
152
+ } catch {
153
+ // Empty block
154
+ }
152
155
 
153
156
  return {
154
157
  amount: Number(balance.balance).toFixed(token.decimals),
@@ -3,7 +3,7 @@ import { DoraBDSNeoLegacy } from '../DoraBDSNeoLegacy'
3
3
  import { DEFAULT_URL_BY_NETWORK_TYPE, TOKENS } from '../constants'
4
4
 
5
5
  const gasToken = TOKENS.testnet.find(t => t.symbol === 'GAS')!
6
- let doraBDSNeoLegacy = new DoraBDSNeoLegacy(
6
+ const doraBDSNeoLegacy = new DoraBDSNeoLegacy(
7
7
  { type: 'testnet', url: DEFAULT_URL_BY_NETWORK_TYPE.testnet },
8
8
  gasToken,
9
9
  gasToken
@@ -67,7 +67,9 @@ describe('BDSNeoLegacy', () => {
67
67
  })
68
68
  )
69
69
  })
70
- } catch {}
70
+ } catch {
71
+ // Empty block
72
+ }
71
73
  }
72
74
  )
73
75
 
@@ -106,6 +108,7 @@ describe('BDSNeoLegacy', () => {
106
108
  decimals: expect.any(Number),
107
109
  },
108
110
  })
111
+ expect(balance.token.hash.startsWith("0x")).toBeFalsy()
109
112
  })
110
113
  })
111
114
 
@@ -1,5 +1,4 @@
1
1
  import { BSNeoLegacy } from '../BSNeoLegacy'
2
- import { wallet } from '@cityofzion/neon-js'
3
2
  import { generateMnemonic } from '@cityofzion/bs-asteroid-sdk'
4
3
 
5
4
  let bsNeoLegacy: BSNeoLegacy
@@ -53,11 +52,19 @@ describe('BSNeoLegacy', () => {
53
52
  const mnemonic = generateMnemonic()
54
53
  const account = bsNeoLegacy.generateAccountFromMnemonic(mnemonic, 0)
55
54
  const password = 'TestPassword'
56
- const encryptedKey = await wallet.encrypt(account.key, password)
55
+ const encryptedKey = await bsNeoLegacy.encrypt(account.key, password)
57
56
  const decryptedAccount = await bsNeoLegacy.decrypt(encryptedKey, password)
58
57
  expect(account).toEqual(expect.objectContaining(decryptedAccount))
59
58
  }, 10000)
60
59
 
60
+ it('Should be able to encrypt a key', async () => {
61
+ const mnemonic = generateMnemonic()
62
+ const account = bsNeoLegacy.generateAccountFromMnemonic(mnemonic, 0)
63
+ const password = 'TestPassword'
64
+ const encryptedKey = await bsNeoLegacy.encrypt(account.key, password)
65
+ expect(encryptedKey).toEqual(expect.any(String))
66
+ })
67
+
61
68
  it.skip('Should be able to transfer a native asset', async () => {
62
69
  const account = bsNeoLegacy.generateAccountFromKey(process.env.TESTNET_PRIVATE_KEY as string)
63
70
  const balance = await bsNeoLegacy.blockchainDataService.getBalance(account.address)
@@ -1,18 +1,14 @@
1
1
  [
2
2
  {
3
3
  "symbol": "GAS",
4
- "type": "UtilityToken",
5
4
  "name": "GAS",
6
5
  "hash": "602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7",
7
- "decimals": 8,
8
- "blockchain": "neoLegacy"
6
+ "decimals": 8
9
7
  },
10
8
  {
11
9
  "symbol": "NEO",
12
- "type": "GoverningToken",
13
10
  "name": "NEO",
14
11
  "hash": "c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b",
15
- "decimals": 0,
16
- "blockchain": "neoLegacy"
12
+ "decimals": 0
17
13
  }
18
14
  ]