@cityofzion/bs-neo3 0.3.2 → 0.4.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/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 +55 -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 +3 -5
- package/src/BSNeo3.ts +59 -64
- 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,62 @@
|
|
|
1
|
-
import { BlockchainDataService, BlockchainService, CalculateTransferFeeDetails, SendTransactionParam, Claimable, Account, Exchange, BDSClaimable, exchangeOptions, Token, IntentTransactionParam, NeoNameService, NNSRecordTypes, CalculateTransferFeeResponse } from '@cityofzion/blockchain-service'
|
|
1
|
+
import { BlockchainDataService, keychain, 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 * as AsteroidSDK from '@moonlight-io/asteroid-sdk-js'
|
|
4
3
|
import { gasInfoNeo3, neoInfoNeo3 } from './constants'
|
|
5
4
|
import { claimGasExceptions } from './exceptions'
|
|
6
5
|
import { explorerOptions } from './explorer'
|
|
7
6
|
import tokens from './assets/tokens.json'
|
|
8
7
|
import { NeonInvoker } from '@cityofzion/neon-invoker'
|
|
9
8
|
import {NeonParser} from "@cityofzion/neon-parser"
|
|
10
|
-
import { ABI_TYPES
|
|
9
|
+
import { ABI_TYPES } from '@cityofzion/neo3-parser'
|
|
11
10
|
|
|
12
11
|
const NEO_NS_HASH = "0x50ac1c37690cc2cfc594472833cf57505d5f46de";
|
|
13
12
|
|
|
14
13
|
export class BSNeo3<BSCustomName extends string = string> implements BlockchainService, Claimable, NeoNameService {
|
|
15
14
|
blockchainName: BSCustomName
|
|
16
15
|
dataService: BlockchainDataService & BDSClaimable = explorerOptions.dora
|
|
17
|
-
|
|
18
|
-
feeToken: { hash: string; symbol: string; decimals: number; } = gasInfoNeo3
|
|
16
|
+
feeToken: TokenInfo = gasInfoNeo3
|
|
19
17
|
exchange: Exchange = exchangeOptions.flamingo
|
|
20
|
-
tokenClaim:
|
|
18
|
+
tokenClaim: TokenInfo = neoInfoNeo3
|
|
21
19
|
tokens: Token[] = tokens
|
|
22
|
-
|
|
20
|
+
|
|
21
|
+
private derivationPath: string = "m/44'/888'/0'/0/?"
|
|
22
|
+
|
|
23
23
|
constructor(blockchainName: BSCustomName) {
|
|
24
24
|
this.blockchainName = blockchainName
|
|
25
25
|
}
|
|
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
|
-
}
|
|
26
|
+
validateAddress(address: string): boolean {
|
|
27
|
+
return wallet.isAddress(address)
|
|
38
28
|
}
|
|
39
|
-
|
|
40
|
-
|
|
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
|
|
29
|
+
validateEncryptedKey(encryptedKey: string): boolean {
|
|
30
|
+
return wallet.isNEP2(encryptedKey)
|
|
52
31
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const result: api.signingConfig = {
|
|
56
|
-
signingCallback: api.signWithAccount(neoAccount)
|
|
57
|
-
}
|
|
58
|
-
return result
|
|
32
|
+
validateWif(wif: string): boolean {
|
|
33
|
+
return wallet.isWIF(wif)
|
|
59
34
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (!list) throw new Error("Failed to generate mnemonic");
|
|
64
|
-
return list
|
|
35
|
+
validateNNSFormat(domainName: string): boolean {
|
|
36
|
+
if (!domainName.endsWith('.neo')) return false
|
|
37
|
+
return true
|
|
65
38
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return
|
|
39
|
+
generateMnemonic(): string[] {
|
|
40
|
+
keychain.generateMnemonic(128)
|
|
41
|
+
if (!keychain.mnemonic) throw new Error("Failed to generate mnemonic")
|
|
42
|
+
return keychain.mnemonic.toString().split(' ')
|
|
70
43
|
}
|
|
71
|
-
generateAccount(mnemonic: string, index: number): Account {
|
|
72
|
-
|
|
44
|
+
generateAccount(mnemonic: string[], index: number): Account {
|
|
45
|
+
keychain.importMnemonic(mnemonic.join(' '))
|
|
46
|
+
const childKey = keychain.generateChildKey("neo", this.derivationPath.replace('?', index.toString()))
|
|
47
|
+
const wif = childKey.getWIF()
|
|
73
48
|
const { address } = new wallet.Account(wif)
|
|
74
49
|
return { address, wif }
|
|
75
50
|
}
|
|
76
|
-
generateAccountFromWif(wif: string):
|
|
51
|
+
generateAccountFromWif(wif: string): Account {
|
|
77
52
|
const { address } = new wallet.Account(wif)
|
|
78
|
-
return address
|
|
53
|
+
return { address, wif }
|
|
79
54
|
}
|
|
80
55
|
async decryptKey(encryptedKey: string, password: string): Promise<Account> {
|
|
81
56
|
const wif = await wallet.decrypt(encryptedKey, password)
|
|
82
57
|
const { address } = new wallet.Account(wif)
|
|
83
58
|
return { address, wif }
|
|
84
59
|
}
|
|
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
60
|
async calculateTransferFee(param: SendTransactionParam): Promise<CalculateTransferFeeResponse> {
|
|
95
61
|
const node = await this.dataService.getHigherNode()
|
|
96
62
|
const url = node.url
|
|
@@ -145,6 +111,19 @@ export class BSNeo3<BSCustomName extends string = string> implements BlockchainS
|
|
|
145
111
|
}
|
|
146
112
|
return result
|
|
147
113
|
}
|
|
114
|
+
async sendTransaction(param: SendTransactionParam): Promise<string> {
|
|
115
|
+
try {
|
|
116
|
+
const { senderAccount, transactionIntents } = param
|
|
117
|
+
const node = await this.dataService.getHigherNode()
|
|
118
|
+
const facade = await api.NetworkFacade.fromConfig({ node: node.url })
|
|
119
|
+
const intents = this.buildTransfer(transactionIntents, senderAccount)
|
|
120
|
+
const signing = this.signTransfer(senderAccount)
|
|
121
|
+
const result = await facade.transferToken(intents, signing)
|
|
122
|
+
return result;
|
|
123
|
+
} catch (error) {
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
148
127
|
//Claimable interface implementation
|
|
149
128
|
async claim(account: Account): Promise<{ txid: string; symbol: string; hash: string; }> {
|
|
150
129
|
const balance = await this.dataService.getBalance(account.address)
|
|
@@ -220,9 +199,25 @@ export class BSNeo3<BSCustomName extends string = string> implements BlockchainS
|
|
|
220
199
|
const address = parser.accountInputToAddress(parsed.replace("0x", ""))
|
|
221
200
|
return address
|
|
222
201
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
202
|
+
private buildTransfer(transactionIntents: IntentTransactionParam[], account: Account) {
|
|
203
|
+
const intents: api.Nep17TransferIntent[] = []
|
|
204
|
+
const neoAccount = new wallet.Account(account.wif)
|
|
205
|
+
for (const transactionIntent of transactionIntents) {
|
|
206
|
+
const { amount, receiverAddress, tokenHash } = transactionIntent
|
|
207
|
+
intents.push({
|
|
208
|
+
to: receiverAddress,
|
|
209
|
+
contractHash: tokenHash,
|
|
210
|
+
from: neoAccount,
|
|
211
|
+
decimalAmt: amount,
|
|
212
|
+
})
|
|
213
|
+
}
|
|
214
|
+
return intents
|
|
215
|
+
}
|
|
216
|
+
private signTransfer(account: Account) {
|
|
217
|
+
const neoAccount = new wallet.Account(account.address)
|
|
218
|
+
const result: api.signingConfig = {
|
|
219
|
+
signingCallback: api.signWithAccount(neoAccount)
|
|
220
|
+
}
|
|
221
|
+
return result
|
|
227
222
|
}
|
|
228
223
|
}
|
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
|
-
}
|