Skip to content

Commit 03e4a7e

Browse files
authored
convert prefix okexchain to ex (#49)
* convert prefix okexchain to ex * update npm version
1 parent bc9989f commit 03e4a7e

File tree

8 files changed

+29
-24
lines changed

8 files changed

+29
-24
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@
88
tsconfig.json
99
.history/
1010
/dist
11+
/bulid
12+
/lib

__tests__/client.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import * as crypto from "../src/crypto"
66
const mnemonic = "total lottery arena when pudding best candy until army spoil drill pool"
77
const privateKey_996 = "29892b64003fc5c8c89dc795a2ae82aa84353bb4352f28707c2ed32aa1011884"
88
const privateKey = "828e61f969a7369f3340b07dd2080740d8445d7f802899ddacf9bc4db8608997"
9-
const from_996 = "okexchain1pt7xrmxul7sx54ml44lvv403r06clrdkgmvr9g"
10-
const from = "okexchain1ya7dn2rr8nx07tx9ksq8gvz5utvarrh03cen3l"
9+
const from_996 = "ex1jjvpmgwwgs99nhlje3aag0lackunqgj7pcgnd4"
10+
const from = "ex1ya7dn2rr8nx07tx9ksq8gvz5utvarrh0knjnjn"
1111
const serverUrl = "https://exchaintest.okexcn.com"
1212
// const serverUrl = "https://exchaintest.okexcn.com"
13-
const userAddress = "okexchain1jjvpmgwwgs99nhlje3aag0lackunqgj7xnrnwe"
13+
const userAddress = "ex1ya7dn2rr8nx07tx9ksq8gvz5utvarrh0knjnjn"
1414
const chainId = "okexchain-65" // -testnet1
1515
const baseCoin = "okt"
1616
const testCoin = "xxb-781"
@@ -120,7 +120,7 @@ describe("OKEXChainClient test", async () => {
120120
it("send sendRegisterDexOperatorTransaction", async () => {
121121
jest.setTimeout(10000)
122122
const data = await prepareAccount()
123-
const res = await data.okclient.sendRegisterDexOperatorTransaction("http://test.json", "okexchain14zg88reaad4czrcnf93esftwe44gpev9cqhkny", "add deposit", data.sequence)
123+
const res = await data.okclient.sendRegisterDexOperatorTransaction("http://test.json", "ex1ya7dn2rr8nx07tx9ksq8gvz5utvarrh0knjnjn", "add deposit", data.sequence)
124124
console.log(JSON.stringify(res))
125125
expect(res.status).toBe(200)
126126
})

__tests__/crypto.test.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ describe("crypto", () => {
88

99
it("getAddressFromPrivateKey", () => {
1010
const address = crypto.getAddressFromPrivateKey(privateKey)
11-
expect(address).toBe("okexchain1jjvpmgwwgs99nhlje3aag0lackunqgj7xnrnwe")
12-
expect(address.length).toBe(48)
11+
expect(address).toBe("ex1jjvpmgwwgs99nhlje3aag0lackunqgj7pcgnd4")
12+
expect(address.length).toBe(41)
1313
})
1414

1515
it("getAddressFromPubKey", () => {
1616
const publicKey = crypto.getPubKeyHexFromPrivateKey(privateKey)
1717
const address = crypto.getAddressFromPubKey(publicKey)
18-
expect(address).toBe("okexchain1jjvpmgwwgs99nhlje3aag0lackunqgj7xnrnwe")
18+
expect(address).toBe("ex1jjvpmgwwgs99nhlje3aag0lackunqgj7pcgnd4")
1919
})
2020

2121
it("getPrivateKeyFromKeyStore", () => {
22-
const keyStore = crypto.generateKeyStore(privateKey, "okexchain")
23-
const pk = crypto.getPrivateKeyFromKeyStore(keyStore, "okexchain")
22+
const keyStore = crypto.generateKeyStore(privateKey, "ex")
23+
const pk = crypto.getPrivateKeyFromKeyStore(keyStore, "ex")
2424
expect(pk).toBe(privateKey)
2525
})
2626

@@ -41,9 +41,10 @@ describe("crypto", () => {
4141
})
4242

4343
it("decodeAddressToBuffer", ()=>{
44-
let address = "okexchain1g7c3nvac7mjgn2m9mqllgat8wwd3aptddw77gw"
44+
let address = "ex1ya7dn2rr8nx07tx9ksq8gvz5utvarrh0knjnjn"
4545
const decod = crypto.decodeAddressToBuffer(address)
46-
expect(decod.toString("hex")).toBe("47b119b3b8f6e489ab65d83ff47567739b1e856d")
46+
console.log(decod.toString("hex"));
47+
expect(decod.toString("hex")).toBe("277cd9a8633cccff2cc5b400743054e2d9d18eef")
4748
})
4849

4950
it("sign", () => {
@@ -60,9 +61,11 @@ describe("crypto", () => {
6061
})
6162

6263
it("bech32 and hex", () => {
63-
let bech32Address = "okexchain1g7c3nvac7mjgn2m9mqllgat8wwd3aptddw77gw"
64+
let bech32Address = "ex1ya7dn2rr8nx07tx9ksq8gvz5utvarrh0knjnjn"
6465
let hexAddress = crypto.convertBech32ToHex(bech32Address)
6566
console.log('hexAddress', hexAddress);
67+
68+
// let hexAddress = "0x277CD9a8633ccCFF2Cc5B400743054e2d9d18eEf"
6669
let newBech32Address = crypto.convertHexToBech32(hexAddress)
6770
console.log('newBech32Address', newBech32Address)
6871
expect(bech32Address).toBe(newBech32Address)

docs/okexchain-jssdk-doc-crypto.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Encodes address from hex to bech32 format.
8181
<a name="module_crypto.convertBech32ToHex"></a>
8282

8383
### crypto.convertBech32ToHex ⇒ <code>String</code>
84-
covert okexchain address to 0x address
84+
covert ex address to 0x address
8585

8686
**Kind**: static constant of [<code>crypto</code>](#module_crypto)
8787

@@ -92,7 +92,7 @@ covert okexchain address to 0x address
9292
<a name="module_crypto.convertHexToBech32"></a>
9393

9494
### crypto.convertHexToBech32 ⇒ <code>string</code>
95-
covert 0x address to okexchain address
95+
covert 0x address to ex address
9696

9797
**Kind**: static constant of [<code>crypto</code>](#module_crypto)
9898

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@okexchain/javascript-sdk",
3-
"version": "0.0.32",
3+
"version": "0.16.1",
44
"license": "Apache-2.0",
55
"main": "lib/index.js",
66
"scripts": {

src/client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import * as wallet from './wallet'
1111

1212
const defaultChainId = "okexchain-66"
1313
const defaultRelativePath = "/okexchain/v1"
14-
const bech32Head = "okexchain"
14+
const bech32Head = "ex"
1515
const mode = "block"
1616
const nativeDenom = "okt"
1717
const defaultTestnetFee = {

src/crypto/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const decodeAddressToBuffer = (addr) => {
5252
export const validateAddress = (addr) => {
5353
try {
5454
const decodeAddress = bech32.decode(addr)
55-
if(decodeAddress.prefix === "okexchain") {
55+
if(decodeAddress.prefix === "ex") {
5656
return true
5757
}
5858

@@ -68,7 +68,7 @@ export const validateAddress = (addr) => {
6868
* @param {string} prefix address prefix
6969
* @return {string} address with bech32 format
7070
*/
71-
export const encodeAddressToBech32 = (hexAddr, prefix = "okexchain") => {
71+
export const encodeAddressToBech32 = (hexAddr, prefix = "ex") => {
7272
hexAddr = hexAddr.slice(0, 2) === '0x' ? hexAddr.slice(2) : hexAddr
7373
const words = bech32.toWords(Buffer.from(hexAddr, "hex"))
7474
return bech32.encode(prefix, words)
@@ -79,7 +79,7 @@ function buf2hex(buffer) { // buffer is an ArrayBuffer
7979
}
8080

8181
/**
82-
* covert okexchain address to 0x address
82+
* covert ex address to 0x address
8383
* @param bech32Address
8484
* @returns {String}
8585
*/
@@ -88,7 +88,7 @@ export const convertBech32ToHex = (bech32Address) => {
8888
return toChecksumAddress("0x"+buf2hex(address))
8989
}
9090
/**
91-
* covert 0x address to okexchain address
91+
* covert 0x address to ex address
9292
* @param hexAddress
9393
* @returns {string}
9494
*/

src/wallet/connector.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const GET_SIGN = {
1010
method: 'okt_signTransaction'
1111
};
1212

13-
const OKEXCHAIN = 'okexchain';
13+
const EXCHAIN = 'ex';
1414

1515
// const DURING = 5000;
1616

@@ -48,7 +48,7 @@ class Connector {
4848
onDisconnect() {
4949
this.killSession();
5050
}
51-
51+
5252
async getAccounts() {
5353
const walletConnector = this.walletConnector;
5454
if(!walletConnector) return '';
@@ -65,7 +65,7 @@ class Connector {
6565
console.log('get address params: ' + JSON.stringify(params));
6666
walletConnector.sendCustomRequest(params).then((res) => {
6767
const okexchainAccount = res.find((account) => {
68-
return account.address.startsWith(OKEXCHAIN);
68+
return account.address.startsWith(EXCHAIN);
6969
});
7070
if (okexchainAccount) {
7171
address = okexchainAccount.address;
@@ -172,7 +172,7 @@ class Connector {
172172
doCallback(type,params) {
173173
if(typeof this.callback[type] === 'function' )this.callback[type](params);
174174
}
175-
175+
176176
async getSession(callback) {
177177
this.setCallback(callback);
178178
let session = '';

0 commit comments

Comments
 (0)