@cityofzion/bs-neo3 0.3.2 → 0.4.0
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/bs-neo3.build.error.log +84 -0
- package/bs-neo3.build.log +86 -1
- package/dist/BSNeo3.d.ts +12 -22
- package/dist/BSNeo3.js +58 -85
- package/dist/constants.d.ts +3 -10
- package/docs/assets/search.js +1 -1
- package/docs/classes/BDSNeo3.html +13 -13
- package/docs/classes/BSNeo3.html +36 -80
- package/docs/interfaces/DoraNeo3Abi.html +6 -6
- package/docs/interfaces/DoraNeo3Asset.html +9 -9
- package/docs/interfaces/DoraNeo3AssetState.html +6 -6
- package/docs/interfaces/DoraNeo3Balance.html +5 -5
- package/docs/interfaces/DoraNeo3ConsensusNode.html +3 -3
- package/docs/interfaces/DoraNeo3Contract.html +8 -8
- package/docs/interfaces/DoraNeo3Event.html +3 -3
- package/docs/interfaces/DoraNeo3Features.html +1 -1
- package/docs/interfaces/DoraNeo3HistoryState.html +3 -3
- package/docs/interfaces/DoraNeo3Invocation.html +3 -3
- package/docs/interfaces/DoraNeo3Item.html +11 -11
- package/docs/interfaces/DoraNeo3Manifest.html +9 -9
- package/docs/interfaces/DoraNeo3Metadata.html +12 -12
- package/docs/interfaces/DoraNeo3Method.html +12 -12
- package/docs/interfaces/DoraNeo3Nef.html +7 -7
- package/docs/interfaces/DoraNeo3Notification.html +4 -4
- package/docs/interfaces/DoraNeo3Parameter.html +3 -3
- package/docs/interfaces/DoraNeo3Permission.html +3 -3
- package/docs/interfaces/DoraNeo3Signer.html +3 -3
- package/docs/interfaces/DoraNeo3Token.html +6 -6
- package/docs/interfaces/DoraNeo3Transaction.html +16 -16
- package/docs/interfaces/DoraNeo3TransactionHistory.html +3 -3
- package/docs/interfaces/DoraNeo3Transfer.html +9 -9
- package/docs/interfaces/DoraNeo3Witness.html +3 -3
- package/docs/variables/DORA_ASSET.html +1 -1
- package/docs/variables/DORA_BALANCE.html +1 -1
- package/docs/variables/DORA_CONTRACT.html +1 -1
- package/docs/variables/DORA_NODES.html +1 -1
- package/docs/variables/DORA_TRANSACTION.html +1 -1
- package/docs/variables/DORA_TRANSACTIONS.html +1 -1
- package/docs/variables/explorerOptions.html +1 -1
- package/docs/variables/gasInfoNeo3.html +2 -11
- package/docs/variables/neoInfoNeo3.html +2 -11
- package/package.json +6 -7
- package/src/BSNeo3.ts +63 -65
- package/src/constants.ts +4 -2
- package/tsconfig.json +6 -1
- package/.rush/temp/package-deps_build.json +0 -20
package/src/BSNeo3.ts
CHANGED
|
@@ -1,96 +1,65 @@
|
|
|
1
|
-
import { BlockchainDataService, BlockchainService, CalculateTransferFeeDetails, SendTransactionParam, Claimable, Account, Exchange, BDSClaimable, exchangeOptions, Token, IntentTransactionParam, NeoNameService, NNSRecordTypes, CalculateTransferFeeResponse } from '@cityofzion/blockchain-service'
|
|
1
|
+
import { BlockchainDataService, BlockchainService, CalculateTransferFeeDetails, SendTransactionParam, TokenInfo, Claimable, Account, Exchange, BDSClaimable, exchangeOptions, Token, IntentTransactionParam, NeoNameService, NNSRecordTypes, CalculateTransferFeeResponse } from '@cityofzion/blockchain-service'
|
|
2
2
|
import { api, rpc, tx, u, wallet } from '@cityofzion/neon-js'
|
|
3
|
-
import
|
|
3
|
+
import {BIP39Encoded} from '@cityofzion/wallet-sdk'
|
|
4
4
|
import { gasInfoNeo3, neoInfoNeo3 } from './constants'
|
|
5
5
|
import { claimGasExceptions } from './exceptions'
|
|
6
6
|
import { explorerOptions } from './explorer'
|
|
7
7
|
import tokens from './assets/tokens.json'
|
|
8
8
|
import { NeonInvoker } from '@cityofzion/neon-invoker'
|
|
9
9
|
import {NeonParser} from "@cityofzion/neon-parser"
|
|
10
|
-
import { ABI_TYPES
|
|
10
|
+
import { ABI_TYPES } from '@cityofzion/neo3-parser'
|
|
11
11
|
|
|
12
12
|
const NEO_NS_HASH = "0x50ac1c37690cc2cfc594472833cf57505d5f46de";
|
|
13
13
|
|
|
14
14
|
export class BSNeo3<BSCustomName extends string = string> implements BlockchainService, Claimable, NeoNameService {
|
|
15
15
|
blockchainName: BSCustomName
|
|
16
16
|
dataService: BlockchainDataService & BDSClaimable = explorerOptions.dora
|
|
17
|
-
|
|
18
|
-
feeToken: { hash: string; symbol: string; decimals: number; } = gasInfoNeo3
|
|
17
|
+
feeToken: TokenInfo = gasInfoNeo3
|
|
19
18
|
exchange: Exchange = exchangeOptions.flamingo
|
|
20
|
-
tokenClaim:
|
|
19
|
+
tokenClaim: TokenInfo = neoInfoNeo3
|
|
21
20
|
tokens: Token[] = tokens
|
|
22
|
-
|
|
21
|
+
|
|
22
|
+
private derivationPath: string = "m/44'/888'/0'/0/?"
|
|
23
|
+
|
|
23
24
|
constructor(blockchainName: BSCustomName) {
|
|
24
25
|
this.blockchainName = blockchainName
|
|
25
26
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const { senderAccount, transactionIntents } = param
|
|
29
|
-
const node = await this.dataService.getHigherNode()
|
|
30
|
-
const facade = await api.NetworkFacade.fromConfig({ node: node.url })
|
|
31
|
-
const intents = this.buildTransfer(transactionIntents, senderAccount)
|
|
32
|
-
const signing = this.signTransfer(senderAccount)
|
|
33
|
-
const result = await facade.transferToken(intents, signing)
|
|
34
|
-
return result;
|
|
35
|
-
} catch (error) {
|
|
36
|
-
throw error;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
private buildTransfer(transactionIntents: IntentTransactionParam[], account: Account) {
|
|
40
|
-
const intents: api.Nep17TransferIntent[] = []
|
|
41
|
-
const neoAccount = new wallet.Account(account.wif)
|
|
42
|
-
for (const transactionIntent of transactionIntents) {
|
|
43
|
-
const { amount, receiverAddress, tokenHash } = transactionIntent
|
|
44
|
-
intents.push({
|
|
45
|
-
to: receiverAddress,
|
|
46
|
-
contractHash: tokenHash,
|
|
47
|
-
from: neoAccount,
|
|
48
|
-
decimalAmt: amount,
|
|
49
|
-
})
|
|
50
|
-
}
|
|
51
|
-
return intents
|
|
27
|
+
validateAddress(address: string): boolean {
|
|
28
|
+
return wallet.isAddress(address)
|
|
52
29
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const result: api.signingConfig = {
|
|
56
|
-
signingCallback: api.signWithAccount(neoAccount)
|
|
57
|
-
}
|
|
58
|
-
return result
|
|
30
|
+
validateEncryptedKey(encryptedKey: string): boolean {
|
|
31
|
+
return wallet.isNEP2(encryptedKey)
|
|
59
32
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const list = this.keychain.mnemonic?.toString()
|
|
63
|
-
if (!list) throw new Error("Failed to generate mnemonic");
|
|
64
|
-
return list
|
|
33
|
+
validateWif(wif: string): boolean {
|
|
34
|
+
return wallet.isWIF(wif)
|
|
65
35
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return childKey.getWIF()
|
|
36
|
+
validateNNSFormat(domainName: string): boolean {
|
|
37
|
+
if (!domainName.endsWith('.neo')) return false
|
|
38
|
+
return true
|
|
70
39
|
}
|
|
71
|
-
|
|
72
|
-
const
|
|
40
|
+
generateMnemonic(): string[] {
|
|
41
|
+
const bip39 = new BIP39Encoded()
|
|
42
|
+
const {phonetic} = bip39.generateMnemonic({length: 12})
|
|
43
|
+
if (!phonetic) throw new Error("Failed to generate mnemonic");
|
|
44
|
+
return phonetic
|
|
45
|
+
}
|
|
46
|
+
generateAccount(mnemonic: string[], index: number): Account {
|
|
47
|
+
const bip39 = new BIP39Encoded({ mnemonic })
|
|
48
|
+
const keychain = bip39.getKeychain('neo')
|
|
49
|
+
const childKey = keychain.generateChildKey(this.derivationPath.replace('?', index.toString()))
|
|
50
|
+
const wif = childKey.getWIF()
|
|
73
51
|
const { address } = new wallet.Account(wif)
|
|
74
52
|
return { address, wif }
|
|
75
53
|
}
|
|
76
|
-
generateAccountFromWif(wif: string):
|
|
54
|
+
generateAccountFromWif(wif: string): Account {
|
|
77
55
|
const { address } = new wallet.Account(wif)
|
|
78
|
-
return address
|
|
56
|
+
return { address, wif }
|
|
79
57
|
}
|
|
80
58
|
async decryptKey(encryptedKey: string, password: string): Promise<Account> {
|
|
81
59
|
const wif = await wallet.decrypt(encryptedKey, password)
|
|
82
60
|
const { address } = new wallet.Account(wif)
|
|
83
61
|
return { address, wif }
|
|
84
62
|
}
|
|
85
|
-
validateAddress(address: string): boolean {
|
|
86
|
-
return wallet.isAddress(address)
|
|
87
|
-
}
|
|
88
|
-
validateEncryptedKey(encryptedKey: string): boolean {
|
|
89
|
-
return wallet.isNEP2(encryptedKey)
|
|
90
|
-
}
|
|
91
|
-
validateWif(wif: string): boolean {
|
|
92
|
-
return wallet.isWIF(wif)
|
|
93
|
-
}
|
|
94
63
|
async calculateTransferFee(param: SendTransactionParam): Promise<CalculateTransferFeeResponse> {
|
|
95
64
|
const node = await this.dataService.getHigherNode()
|
|
96
65
|
const url = node.url
|
|
@@ -145,6 +114,19 @@ export class BSNeo3<BSCustomName extends string = string> implements BlockchainS
|
|
|
145
114
|
}
|
|
146
115
|
return result
|
|
147
116
|
}
|
|
117
|
+
async sendTransaction(param: SendTransactionParam): Promise<string> {
|
|
118
|
+
try {
|
|
119
|
+
const { senderAccount, transactionIntents } = param
|
|
120
|
+
const node = await this.dataService.getHigherNode()
|
|
121
|
+
const facade = await api.NetworkFacade.fromConfig({ node: node.url })
|
|
122
|
+
const intents = this.buildTransfer(transactionIntents, senderAccount)
|
|
123
|
+
const signing = this.signTransfer(senderAccount)
|
|
124
|
+
const result = await facade.transferToken(intents, signing)
|
|
125
|
+
return result;
|
|
126
|
+
} catch (error) {
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
148
130
|
//Claimable interface implementation
|
|
149
131
|
async claim(account: Account): Promise<{ txid: string; symbol: string; hash: string; }> {
|
|
150
132
|
const balance = await this.dataService.getBalance(account.address)
|
|
@@ -220,9 +202,25 @@ export class BSNeo3<BSCustomName extends string = string> implements BlockchainS
|
|
|
220
202
|
const address = parser.accountInputToAddress(parsed.replace("0x", ""))
|
|
221
203
|
return address
|
|
222
204
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
205
|
+
private buildTransfer(transactionIntents: IntentTransactionParam[], account: Account) {
|
|
206
|
+
const intents: api.Nep17TransferIntent[] = []
|
|
207
|
+
const neoAccount = new wallet.Account(account.wif)
|
|
208
|
+
for (const transactionIntent of transactionIntents) {
|
|
209
|
+
const { amount, receiverAddress, tokenHash } = transactionIntent
|
|
210
|
+
intents.push({
|
|
211
|
+
to: receiverAddress,
|
|
212
|
+
contractHash: tokenHash,
|
|
213
|
+
from: neoAccount,
|
|
214
|
+
decimalAmt: amount,
|
|
215
|
+
})
|
|
216
|
+
}
|
|
217
|
+
return intents
|
|
218
|
+
}
|
|
219
|
+
private signTransfer(account: Account) {
|
|
220
|
+
const neoAccount = new wallet.Account(account.address)
|
|
221
|
+
const result: api.signingConfig = {
|
|
222
|
+
signingCallback: api.signWithAccount(neoAccount)
|
|
223
|
+
}
|
|
224
|
+
return result
|
|
227
225
|
}
|
|
228
226
|
}
|
package/src/constants.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import { TokenInfo } from '@cityofzion/blockchain-service'
|
|
2
|
+
|
|
3
|
+
export const gasInfoNeo3: TokenInfo = {
|
|
2
4
|
hash: '0xd2a4cff31913016155e38e474a2c06d08be276cf',
|
|
3
5
|
symbol: 'GAS',
|
|
4
6
|
decimals: 8
|
|
5
7
|
}
|
|
6
8
|
|
|
7
|
-
export const neoInfoNeo3 = {
|
|
9
|
+
export const neoInfoNeo3: TokenInfo = {
|
|
8
10
|
hash: '0xef4073a0f2b305a38ec4050e4d3d28bc40ea63f5',
|
|
9
11
|
symbol: 'NEO',
|
|
10
12
|
decimals: 0
|
package/tsconfig.json
CHANGED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"files": {
|
|
3
|
-
"packages/bs-neo3/package.json": "13ff208146fbc764d375e0da5ea67a544e028eba",
|
|
4
|
-
"packages/bs-neo3/src/BDSNeo3.ts": "6de6c505219ad5404357ba195b9b59b368fc574f",
|
|
5
|
-
"packages/bs-neo3/src/BSNeo3.ts": "39c473d9be67c3cd0ccf253fd037d1c9ea881027",
|
|
6
|
-
"packages/bs-neo3/src/assets/blockchain_icon_neo.png": "3b3c8c019cc3ab191648acd69b07663006abf495",
|
|
7
|
-
"packages/bs-neo3/src/assets/blockchain_icon_neo_white.png": "feaec214f1374496e428254d8d014a8aa39b7067",
|
|
8
|
-
"packages/bs-neo3/src/assets/tokens.json": "33d65a4a123ae414a95b0caf031c6d62eb715349",
|
|
9
|
-
"packages/bs-neo3/src/constants.ts": "39993e77862b88d771441980cf39a091ae5dee3a",
|
|
10
|
-
"packages/bs-neo3/src/exceptions.ts": "c7b6401d197e363dca8241b92a4304c227e7800f",
|
|
11
|
-
"packages/bs-neo3/src/explorer/dora/DoraNeo3Responses.ts": "6ccd07c95af63d966ef370ae8861cb37783cc4da",
|
|
12
|
-
"packages/bs-neo3/src/explorer/dora/DoraNeo3Routes.ts": "b6b4b85492e1a9611f0f88c2d9836371f1fba20b",
|
|
13
|
-
"packages/bs-neo3/src/explorer/index.ts": "4e892cff669a805bf2f9cc29554bdfc4e43af6c1",
|
|
14
|
-
"packages/bs-neo3/src/index.ts": "53f10ade66205f959dca69e06c4d2b73d045424a",
|
|
15
|
-
"packages/bs-neo3/tsconfig.json": "9c0d05b4a1620310c7310c1d18e7b1afb1977ff9",
|
|
16
|
-
"packages/bs-neo3/yarn.lock": "5bb25dd89095cbb23ce0906458c1234eb7da3ba2",
|
|
17
|
-
"packages/bs-neo3/.rush/temp/shrinkwrap-deps.json": "9600269a799443762d941100f09b78f5879f9de4"
|
|
18
|
-
},
|
|
19
|
-
"arguments": "tsc && typedoc src/index.ts "
|
|
20
|
-
}
|