diff --git a/.gitignore b/.gitignore
index 0c85a11..03aa311 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,5 @@
tsconfig.json
.history/
/dist
+/bulid
+/lib
diff --git a/__tests__/client.test.js b/__tests__/client.test.js
index 3ce5796..d4a1d20 100644
--- a/__tests__/client.test.js
+++ b/__tests__/client.test.js
@@ -6,11 +6,11 @@ import * as crypto from "../src/crypto"
const mnemonic = "total lottery arena when pudding best candy until army spoil drill pool"
const privateKey_996 = "29892b64003fc5c8c89dc795a2ae82aa84353bb4352f28707c2ed32aa1011884"
const privateKey = "828e61f969a7369f3340b07dd2080740d8445d7f802899ddacf9bc4db8608997"
-const from_996 = "okexchain1pt7xrmxul7sx54ml44lvv403r06clrdkgmvr9g"
-const from = "okexchain1ya7dn2rr8nx07tx9ksq8gvz5utvarrh03cen3l"
+const from_996 = "ex1jjvpmgwwgs99nhlje3aag0lackunqgj7pcgnd4"
+const from = "ex1ya7dn2rr8nx07tx9ksq8gvz5utvarrh0knjnjn"
const serverUrl = "https://exchaintest.okexcn.com"
// const serverUrl = "https://exchaintest.okexcn.com"
-const userAddress = "okexchain1jjvpmgwwgs99nhlje3aag0lackunqgj7xnrnwe"
+const userAddress = "ex1ya7dn2rr8nx07tx9ksq8gvz5utvarrh0knjnjn"
const chainId = "okexchain-65" // -testnet1
const baseCoin = "okt"
const testCoin = "xxb-781"
@@ -120,7 +120,7 @@ describe("OKEXChainClient test", async () => {
it("send sendRegisterDexOperatorTransaction", async () => {
jest.setTimeout(10000)
const data = await prepareAccount()
- const res = await data.okclient.sendRegisterDexOperatorTransaction("http://test.json", "okexchain14zg88reaad4czrcnf93esftwe44gpev9cqhkny", "add deposit", data.sequence)
+ const res = await data.okclient.sendRegisterDexOperatorTransaction("http://test.json", "ex1ya7dn2rr8nx07tx9ksq8gvz5utvarrh0knjnjn", "add deposit", data.sequence)
console.log(JSON.stringify(res))
expect(res.status).toBe(200)
})
diff --git a/__tests__/crypto.test.js b/__tests__/crypto.test.js
index 40e7257..2ccbfc7 100644
--- a/__tests__/crypto.test.js
+++ b/__tests__/crypto.test.js
@@ -8,19 +8,19 @@ describe("crypto", () => {
it("getAddressFromPrivateKey", () => {
const address = crypto.getAddressFromPrivateKey(privateKey)
- expect(address).toBe("okexchain1jjvpmgwwgs99nhlje3aag0lackunqgj7xnrnwe")
- expect(address.length).toBe(48)
+ expect(address).toBe("ex1jjvpmgwwgs99nhlje3aag0lackunqgj7pcgnd4")
+ expect(address.length).toBe(41)
})
it("getAddressFromPubKey", () => {
const publicKey = crypto.getPubKeyHexFromPrivateKey(privateKey)
const address = crypto.getAddressFromPubKey(publicKey)
- expect(address).toBe("okexchain1jjvpmgwwgs99nhlje3aag0lackunqgj7xnrnwe")
+ expect(address).toBe("ex1jjvpmgwwgs99nhlje3aag0lackunqgj7pcgnd4")
})
it("getPrivateKeyFromKeyStore", () => {
- const keyStore = crypto.generateKeyStore(privateKey, "okexchain")
- const pk = crypto.getPrivateKeyFromKeyStore(keyStore, "okexchain")
+ const keyStore = crypto.generateKeyStore(privateKey, "ex")
+ const pk = crypto.getPrivateKeyFromKeyStore(keyStore, "ex")
expect(pk).toBe(privateKey)
})
@@ -41,9 +41,10 @@ describe("crypto", () => {
})
it("decodeAddressToBuffer", ()=>{
- let address = "okexchain1g7c3nvac7mjgn2m9mqllgat8wwd3aptddw77gw"
+ let address = "ex1ya7dn2rr8nx07tx9ksq8gvz5utvarrh0knjnjn"
const decod = crypto.decodeAddressToBuffer(address)
- expect(decod.toString("hex")).toBe("47b119b3b8f6e489ab65d83ff47567739b1e856d")
+ console.log(decod.toString("hex"));
+ expect(decod.toString("hex")).toBe("277cd9a8633cccff2cc5b400743054e2d9d18eef")
})
it("sign", () => {
@@ -60,9 +61,11 @@ describe("crypto", () => {
})
it("bech32 and hex", () => {
- let bech32Address = "okexchain1g7c3nvac7mjgn2m9mqllgat8wwd3aptddw77gw"
+ let bech32Address = "ex1ya7dn2rr8nx07tx9ksq8gvz5utvarrh0knjnjn"
let hexAddress = crypto.convertBech32ToHex(bech32Address)
console.log('hexAddress', hexAddress);
+
+ // let hexAddress = "0x277CD9a8633ccCFF2Cc5B400743054e2d9d18eEf"
let newBech32Address = crypto.convertHexToBech32(hexAddress)
console.log('newBech32Address', newBech32Address)
expect(bech32Address).toBe(newBech32Address)
diff --git a/docs/okexchain-jssdk-doc-crypto.md b/docs/okexchain-jssdk-doc-crypto.md
index 6c73db4..fbc42ba 100644
--- a/docs/okexchain-jssdk-doc-crypto.md
+++ b/docs/okexchain-jssdk-doc-crypto.md
@@ -81,7 +81,7 @@ Encodes address from hex to bech32 format.
### crypto.convertBech32ToHex ⇒ String
-covert okexchain address to 0x address
+covert ex address to 0x address
**Kind**: static constant of [crypto](#module_crypto)
@@ -92,7 +92,7 @@ covert okexchain address to 0x address
### crypto.convertHexToBech32 ⇒ string
-covert 0x address to okexchain address
+covert 0x address to ex address
**Kind**: static constant of [crypto](#module_crypto)
diff --git a/package.json b/package.json
index fc2627f..9f8b3f3 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "@okexchain/javascript-sdk",
- "version": "0.0.32",
+ "version": "0.16.1",
"license": "Apache-2.0",
"main": "lib/index.js",
"scripts": {
diff --git a/src/client.js b/src/client.js
index 3dbd421..6835d99 100644
--- a/src/client.js
+++ b/src/client.js
@@ -11,7 +11,7 @@ import * as wallet from './wallet'
const defaultChainId = "okexchain-66"
const defaultRelativePath = "/okexchain/v1"
-const bech32Head = "okexchain"
+const bech32Head = "ex"
const mode = "block"
const nativeDenom = "okt"
const defaultTestnetFee = {
diff --git a/src/crypto/index.js b/src/crypto/index.js
index 4d0337f..b5d92fa 100644
--- a/src/crypto/index.js
+++ b/src/crypto/index.js
@@ -52,7 +52,7 @@ export const decodeAddressToBuffer = (addr) => {
export const validateAddress = (addr) => {
try {
const decodeAddress = bech32.decode(addr)
- if(decodeAddress.prefix === "okexchain") {
+ if(decodeAddress.prefix === "ex") {
return true
}
@@ -68,7 +68,7 @@ export const validateAddress = (addr) => {
* @param {string} prefix address prefix
* @return {string} address with bech32 format
*/
-export const encodeAddressToBech32 = (hexAddr, prefix = "okexchain") => {
+export const encodeAddressToBech32 = (hexAddr, prefix = "ex") => {
hexAddr = hexAddr.slice(0, 2) === '0x' ? hexAddr.slice(2) : hexAddr
const words = bech32.toWords(Buffer.from(hexAddr, "hex"))
return bech32.encode(prefix, words)
@@ -79,7 +79,7 @@ function buf2hex(buffer) { // buffer is an ArrayBuffer
}
/**
- * covert okexchain address to 0x address
+ * covert ex address to 0x address
* @param bech32Address
* @returns {String}
*/
@@ -88,7 +88,7 @@ export const convertBech32ToHex = (bech32Address) => {
return toChecksumAddress("0x"+buf2hex(address))
}
/**
- * covert 0x address to okexchain address
+ * covert 0x address to ex address
* @param hexAddress
* @returns {string}
*/
diff --git a/src/wallet/connector.js b/src/wallet/connector.js
index 04acc20..267634a 100644
--- a/src/wallet/connector.js
+++ b/src/wallet/connector.js
@@ -10,7 +10,7 @@ const GET_SIGN = {
method: 'okt_signTransaction'
};
-const OKEXCHAIN = 'okexchain';
+const EXCHAIN = 'ex';
// const DURING = 5000;
@@ -48,7 +48,7 @@ class Connector {
onDisconnect() {
this.killSession();
}
-
+
async getAccounts() {
const walletConnector = this.walletConnector;
if(!walletConnector) return '';
@@ -65,7 +65,7 @@ class Connector {
console.log('get address params: ' + JSON.stringify(params));
walletConnector.sendCustomRequest(params).then((res) => {
const okexchainAccount = res.find((account) => {
- return account.address.startsWith(OKEXCHAIN);
+ return account.address.startsWith(EXCHAIN);
});
if (okexchainAccount) {
address = okexchainAccount.address;
@@ -172,7 +172,7 @@ class Connector {
doCallback(type,params) {
if(typeof this.callback[type] === 'function' )this.callback[type](params);
}
-
+
async getSession(callback) {
this.setCallback(callback);
let session = '';