From 9cb2f2448803e0bbffba8d4473c9415a043a17d7 Mon Sep 17 00:00:00 2001 From: zhengchao Date: Sat, 27 Feb 2021 19:30:54 +0800 Subject: [PATCH 1/9] support eth address transfer --- src/client.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/client.js b/src/client.js index 10ed29d..92d8a97 100644 --- a/src/client.js +++ b/src/client.js @@ -132,6 +132,10 @@ export class OKEXChainClient { async sendSendTransaction(to, amount, denom, memo = "", sequenceNumber = null) { + if (to.slice(0, 2) === '0x') { + to = crypto.encodeAddressToBech32(to) + } + const coin = { amount: this.formatNumber(amount), denom: denom, From 22fb8b6559bcf0d5fd4bde61c564578ab213a488 Mon Sep 17 00:00:00 2001 From: zhengchao Date: Sat, 27 Feb 2021 20:56:13 +0800 Subject: [PATCH 2/9] support eth address transfer version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b3a4d85..fba42f6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@okexchain/javascript-sdk", - "version": "0.0.29", + "version": "0.0.30", "license": "Apache-2.0", "main": "lib/index.js", "scripts": { From a4a302cbdae5bdd5fa9e6e03d9391c4ccbc85378 Mon Sep 17 00:00:00 2001 From: zhengchao Date: Mon, 1 Mar 2021 15:52:51 +0800 Subject: [PATCH 3/9] mv eth-lib to dependencies --- package-lock.json | 320 ++++++++++++++++------------------------------ package.json | 4 +- 2 files changed, 110 insertions(+), 214 deletions(-) diff --git a/package-lock.json b/package-lock.json index b7075c2..3ff539a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@okexchain/javascript-sdk", - "version": "0.0.29", + "version": "0.0.31", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -824,7 +824,6 @@ "version": "1.3.7", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz", "integrity": "sha512-Il80Qs2WjYlJIBNzNkK6KYqlVMTbZLXgHx2oT0pU/fjRHyEp+PEfEPY0R3WCwAGVOtauxh1hOxNgIf5bv7dQpA==", - "dev": true, "requires": { "mime-types": "~2.1.24", "negotiator": "0.6.2" @@ -833,14 +832,12 @@ "mime-db": { "version": "1.45.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.45.0.tgz", - "integrity": "sha512-CkqLUxUk15hofLoLyljJSrukZi8mAtgd+yE5uO4tqRZsdsAJKv0O+rFMhVDRJgozy+yG6md5KwuXhD4ocIoP+w==", - "dev": true + "integrity": "sha512-CkqLUxUk15hofLoLyljJSrukZi8mAtgd+yE5uO4tqRZsdsAJKv0O+rFMhVDRJgozy+yG6md5KwuXhD4ocIoP+w==" }, "mime-types": { "version": "2.1.28", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.28.tgz", "integrity": "sha512-0TO2yJ5YHYr7M2zzT7gDU1tbwHxEUWBCLt0lscSNpcdAfFyJOVEpRYNS7EXVcTLNj/25QO8gulHC5JtTzSE2UQ==", - "dev": true, "requires": { "mime-db": "1.45.0" } @@ -897,7 +894,6 @@ "version": "6.10.0", "resolved": "http://registry.npm.taobao.org/ajv/download/ajv-6.10.0.tgz", "integrity": "sha1-kNDVRDnaWHzX6EO/twRfUL0ivfE=", - "dev": true, "requires": { "fast-deep-equal": "^2.0.1", "fast-json-stable-stringify": "^2.0.0", @@ -1024,8 +1020,7 @@ "array-flatten": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", - "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=", - "dev": true + "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" }, "array-map": { "version": "0.0.0", @@ -1055,7 +1050,6 @@ "version": "0.2.4", "resolved": "http://registry.npm.taobao.org/asn1/download/asn1-0.2.4.tgz", "integrity": "sha1-jSR136tVO7M+d7VOWeiAu4ziMTY=", - "dev": true, "requires": { "safer-buffer": "~2.1.0" } @@ -1099,8 +1093,7 @@ "assert-plus": { "version": "1.0.0", "resolved": "http://registry.npm.taobao.org/assert-plus/download/assert-plus-1.0.0.tgz", - "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=", - "dev": true + "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=" }, "assign-symbols": { "version": "1.0.0", @@ -1135,8 +1128,7 @@ "asynckit": { "version": "0.4.0", "resolved": "http://registry.npm.taobao.org/asynckit/download/asynckit-0.4.0.tgz", - "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=", - "dev": true + "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" }, "atob": { "version": "2.1.2", @@ -1147,14 +1139,12 @@ "aws-sign2": { "version": "0.7.0", "resolved": "http://registry.npm.taobao.org/aws-sign2/download/aws-sign2-0.7.0.tgz", - "integrity": "sha1-tG6JCTSpWR8tL2+G1+ap8bP+dqg=", - "dev": true + "integrity": "sha1-tG6JCTSpWR8tL2+G1+ap8bP+dqg=" }, "aws4": { "version": "1.8.0", "resolved": "http://registry.npm.taobao.org/aws4/download/aws4-1.8.0.tgz", - "integrity": "sha1-8OAD2cqef1nHpQiUXXsu+aBKVC8=", - "dev": true + "integrity": "sha1-8OAD2cqef1nHpQiUXXsu+aBKVC8=" }, "axios": { "version": "0.18.0", @@ -1792,7 +1782,6 @@ "version": "1.0.2", "resolved": "http://registry.npm.taobao.org/bcrypt-pbkdf/download/bcrypt-pbkdf-1.0.2.tgz", "integrity": "sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4=", - "dev": true, "requires": { "tweetnacl": "^0.14.3" } @@ -1862,7 +1851,6 @@ "version": "1.19.0", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz", "integrity": "sha512-dhEPs72UPbDnAQJ9ZKMNTP6ptJaionhP5cBb541nXPlW60Jepo9RV/a4fX4XWW9CuFNK22krhrj1+rgzifNCsw==", - "dev": true, "requires": { "bytes": "3.1.0", "content-type": "~1.0.4", @@ -1880,7 +1868,6 @@ "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "dev": true, "requires": { "ms": "2.0.0" } @@ -1888,14 +1875,12 @@ "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", - "dev": true + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" }, "qs": { "version": "6.7.0", "resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz", - "integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==", - "dev": true + "integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==" } } }, @@ -2167,8 +2152,7 @@ "buffer-to-arraybuffer": { "version": "0.0.5", "resolved": "https://registry.npmjs.org/buffer-to-arraybuffer/-/buffer-to-arraybuffer-0.0.5.tgz", - "integrity": "sha1-YGSkD6dutDxyOrqe+PbhIW0QURo=", - "dev": true + "integrity": "sha1-YGSkD6dutDxyOrqe+PbhIW0QURo=" }, "buffer-xor": { "version": "1.0.3", @@ -2184,8 +2168,7 @@ "bytes": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz", - "integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==", - "dev": true + "integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==" }, "cache-base": { "version": "1.0.1", @@ -2276,8 +2259,7 @@ "caseless": { "version": "0.12.0", "resolved": "http://registry.npm.taobao.org/caseless/download/caseless-0.12.0.tgz", - "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=", - "dev": true + "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" }, "catharsis": { "version": "0.8.9", @@ -2500,7 +2482,6 @@ "version": "1.0.7", "resolved": "http://registry.npm.taobao.org/combined-stream/download/combined-stream-1.0.7.tgz", "integrity": "sha1-LR0kMXr7ir6V1tLAsHtXgTU52Cg=", - "dev": true, "requires": { "delayed-stream": "~1.0.0" } @@ -2628,7 +2609,6 @@ "version": "0.5.3", "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.3.tgz", "integrity": "sha512-ExO0774ikEObIAEV9kDo50o+79VCUdEB6n6lzKgGwupcVeRlhrj3qGAfwq8G6uBJjkqLrhT0qEYFcWng8z1z0g==", - "dev": true, "requires": { "safe-buffer": "5.1.2" } @@ -2636,8 +2616,7 @@ "content-type": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz", - "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==", - "dev": true + "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==" }, "convert-source-map": { "version": "1.6.0", @@ -2651,14 +2630,12 @@ "cookie": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.0.tgz", - "integrity": "sha512-+Hp8fLp57wnUSt0tY0tHEXh4voZRDnoIrZPqlo3DPiI4y9lwg/jqx+1Om94/W6ZaPDOUbnjOt/99w66zk+l1Xg==", - "dev": true + "integrity": "sha512-+Hp8fLp57wnUSt0tY0tHEXh4voZRDnoIrZPqlo3DPiI4y9lwg/jqx+1Om94/W6ZaPDOUbnjOt/99w66zk+l1Xg==" }, "cookie-signature": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", - "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=", - "dev": true + "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" }, "copy-descriptor": { "version": "0.1.1", @@ -2712,7 +2689,6 @@ "version": "2.8.5", "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", - "dev": true, "requires": { "object-assign": "^4", "vary": "^1" @@ -2869,7 +2845,6 @@ "version": "1.14.1", "resolved": "http://registry.npm.taobao.org/dashdash/download/dashdash-1.14.1.tgz", "integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=", - "dev": true, "requires": { "assert-plus": "^1.0.0" } @@ -2922,14 +2897,12 @@ "decode-uri-component": { "version": "0.2.0", "resolved": "http://registry.npm.taobao.org/decode-uri-component/download/decode-uri-component-0.2.0.tgz", - "integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=", - "dev": true + "integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=" }, "decompress-response": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-3.3.0.tgz", "integrity": "sha1-gKTdMjdIOEv6JICDYirt7Jgq3/M=", - "dev": true, "requires": { "mimic-response": "^1.0.0" } @@ -3020,14 +2993,12 @@ "delayed-stream": { "version": "1.0.0", "resolved": "http://registry.npm.taobao.org/delayed-stream/download/delayed-stream-1.0.0.tgz", - "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=", - "dev": true + "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" }, "depd": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", - "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=", - "dev": true + "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=" }, "deps-sort": { "version": "2.0.0", @@ -3053,8 +3024,7 @@ "destroy": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", - "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=", - "dev": true + "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" }, "detect-indent": { "version": "4.0.0", @@ -3130,8 +3100,7 @@ "dom-walk": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/dom-walk/-/dom-walk-0.1.2.tgz", - "integrity": "sha512-6QvTW9mrGeIegrFXdtQi9pk7O/nSK6lSdXW2eqUspN5LWD7UTji2Fqw5V2YLjBpHEoU9Xl/eUWNpDeZvoyOv2w==", - "dev": true + "integrity": "sha512-6QvTW9mrGeIegrFXdtQi9pk7O/nSK6lSdXW2eqUspN5LWD7UTji2Fqw5V2YLjBpHEoU9Xl/eUWNpDeZvoyOv2w==" }, "domain-browser": { "version": "1.2.0", @@ -3172,7 +3141,6 @@ "version": "0.1.2", "resolved": "http://registry.npm.taobao.org/ecc-jsbn/download/ecc-jsbn-0.1.2.tgz", "integrity": "sha1-OoOpBOVDUyh4dMVkt1SThoSamMk=", - "dev": true, "requires": { "jsbn": "~0.1.0", "safer-buffer": "^2.1.0" @@ -3193,8 +3161,7 @@ "ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", - "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=", - "dev": true + "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" }, "electron-to-chromium": { "version": "1.3.124", @@ -3225,8 +3192,7 @@ "encodeurl": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", - "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=", - "dev": true + "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=" }, "end-of-stream": { "version": "1.4.1", @@ -3273,8 +3239,7 @@ "escape-html": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", - "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=", - "dev": true + "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=" }, "escape-string-regexp": { "version": "1.0.5", @@ -3453,14 +3418,12 @@ "etag": { "version": "1.8.1", "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", - "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=", - "dev": true + "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=" }, "eth-lib": { "version": "0.1.29", "resolved": "https://registry.npmjs.org/eth-lib/-/eth-lib-0.1.29.tgz", "integrity": "sha512-bfttrr3/7gG4E02HoWTDUcDDslN003OlOoBxk9virpAZQ1ja/jDgwkWB8QfJF7ojuEowrqy+lzp9VcJG7/k5bQ==", - "dev": true, "requires": { "bn.js": "^4.11.6", "elliptic": "^6.4.0", @@ -3474,7 +3437,6 @@ "version": "3.3.3", "resolved": "https://registry.npmjs.org/ws/-/ws-3.3.3.tgz", "integrity": "sha512-nnWLa/NwZSt4KQJu51MYlCcSQ5g7INpOrOMt4XV8j4dqTXdmlUmSHQ8/oLC069ckre0fRsgfvsKwbTdtKLCDkA==", - "dev": true, "requires": { "async-limiter": "~1.0.0", "safe-buffer": "~5.1.0", @@ -3665,7 +3627,6 @@ "version": "4.17.1", "resolved": "https://registry.npmjs.org/express/-/express-4.17.1.tgz", "integrity": "sha512-mHJ9O79RqluphRrcw2X/GTh3k9tVv8YcoyY4Kkh4WDMUYKRZUq0h1o0w2rrrxBqM7VoeUVqgb27xlEMXTnYt4g==", - "dev": true, "requires": { "accepts": "~1.3.7", "array-flatten": "1.1.1", @@ -3703,7 +3664,6 @@ "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "dev": true, "requires": { "ms": "2.0.0" } @@ -3711,22 +3671,19 @@ "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", - "dev": true + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" }, "qs": { "version": "6.7.0", "resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz", - "integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==", - "dev": true + "integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ==" } } }, "extend": { "version": "3.0.2", "resolved": "http://registry.npm.taobao.org/extend/download/extend-3.0.2.tgz", - "integrity": "sha1-+LETa0Bx+9jrFAr/hYsQGewpFfo=", - "dev": true + "integrity": "sha1-+LETa0Bx+9jrFAr/hYsQGewpFfo=" }, "extend-shallow": { "version": "3.0.2", @@ -3828,20 +3785,17 @@ "extsprintf": { "version": "1.3.0", "resolved": "http://registry.npm.taobao.org/extsprintf/download/extsprintf-1.3.0.tgz", - "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=", - "dev": true + "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=" }, "fast-deep-equal": { "version": "2.0.1", "resolved": "http://registry.npm.taobao.org/fast-deep-equal/download/fast-deep-equal-2.0.1.tgz", - "integrity": "sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=", - "dev": true + "integrity": "sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=" }, "fast-json-stable-stringify": { "version": "2.0.0", "resolved": "http://registry.npm.taobao.org/fast-json-stable-stringify/download/fast-json-stable-stringify-2.0.0.tgz", - "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=", - "dev": true + "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=" }, "fast-levenshtein": { "version": "2.0.6", @@ -3934,7 +3888,6 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz", "integrity": "sha512-aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA==", - "dev": true, "requires": { "debug": "2.6.9", "encodeurl": "~1.0.2", @@ -3949,7 +3902,6 @@ "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "dev": true, "requires": { "ms": "2.0.0" } @@ -3957,8 +3909,7 @@ "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", - "dev": true + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" } } }, @@ -4041,14 +3992,12 @@ "forever-agent": { "version": "0.6.1", "resolved": "http://registry.npm.taobao.org/forever-agent/download/forever-agent-0.6.1.tgz", - "integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=", - "dev": true + "integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=" }, "form-data": { "version": "2.3.3", "resolved": "http://registry.npm.taobao.org/form-data/download/form-data-2.3.3.tgz", "integrity": "sha1-3M5SwF9kTymManq5Nr1yTO/786Y=", - "dev": true, "requires": { "asynckit": "^0.4.0", "combined-stream": "^1.0.6", @@ -4058,8 +4007,7 @@ "forwarded": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", - "integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ=", - "dev": true + "integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ=" }, "fragment-cache": { "version": "0.2.1", @@ -4073,8 +4021,7 @@ "fresh": { "version": "0.5.2", "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", - "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=", - "dev": true + "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" }, "fs-readdir-recursive": { "version": "1.1.0", @@ -4114,7 +4061,8 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -4135,12 +4083,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -4155,17 +4105,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -4282,7 +4235,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -4294,6 +4248,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -4308,6 +4263,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -4315,12 +4271,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -4339,6 +4297,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -4419,7 +4378,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -4431,6 +4391,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -4516,7 +4477,8 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -4552,6 +4514,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -4571,6 +4534,7 @@ "version": "3.0.1", "bundled": true, "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -4614,12 +4578,14 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true } } }, @@ -4669,7 +4635,6 @@ "version": "0.1.7", "resolved": "http://registry.npm.taobao.org/getpass/download/getpass-0.1.7.tgz", "integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=", - "dev": true, "requires": { "assert-plus": "^1.0.0" } @@ -4751,7 +4716,6 @@ "version": "4.4.0", "resolved": "https://registry.npmjs.org/global/-/global-4.4.0.tgz", "integrity": "sha512-wv/LAoHdRE3BeTGz53FAamhGlPLhlssK45usmGFThIi4XqnBmjKQ16u+RNbP7WvigRZDxUsM0J3gcQ5yicaL0w==", - "dev": true, "requires": { "min-document": "^2.19.0", "process": "^0.11.10" @@ -4798,14 +4762,12 @@ "har-schema": { "version": "2.0.0", "resolved": "http://registry.npm.taobao.org/har-schema/download/har-schema-2.0.0.tgz", - "integrity": "sha1-qUwiJOvKwEeCoNkDVSHyRzW37JI=", - "dev": true + "integrity": "sha1-qUwiJOvKwEeCoNkDVSHyRzW37JI=" }, "har-validator": { "version": "5.1.3", "resolved": "http://registry.npm.taobao.org/har-validator/download/har-validator-5.1.3.tgz", "integrity": "sha1-HvievT5JllV2de7ZiTEQ3DUPoIA=", - "dev": true, "requires": { "ajv": "^6.5.5", "har-schema": "^2.0.0" @@ -4942,7 +4904,6 @@ "version": "1.7.2", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz", "integrity": "sha512-uUQBt3H/cSIVfch6i1EuPNy/YsRSOUBXTVfZ+yR7Zjez3qjBz6i9+i4zjNaoqcoFVI4lQJ5plg63TvGfRSDCRg==", - "dev": true, "requires": { "depd": "~1.1.2", "inherits": "2.0.3", @@ -4982,7 +4943,6 @@ "version": "1.2.0", "resolved": "http://registry.npm.taobao.org/http-signature/download/http-signature-1.2.0.tgz", "integrity": "sha1-muzZJRFHcvPZW2WmCruPfBj7rOE=", - "dev": true, "requires": { "assert-plus": "^1.0.0", "jsprim": "^1.2.2", @@ -5157,7 +5117,6 @@ "version": "0.4.24", "resolved": "http://registry.npm.taobao.org/iconv-lite/download/iconv-lite-0.4.24.tgz", "integrity": "sha1-ICK0sl+93CHS9SSXSkdKr+czkIs=", - "dev": true, "requires": { "safer-buffer": ">= 2.1.2 < 3" } @@ -5338,8 +5297,7 @@ "ipaddr.js": { "version": "1.9.1", "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", - "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", - "dev": true + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==" }, "is-accessor-descriptor": { "version": "0.1.6", @@ -5473,7 +5431,8 @@ "version": "2.1.1", "resolved": "http://registry.npm.taobao.org/is-extglob/download/is-extglob-2.1.1.tgz", "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=", - "dev": true + "dev": true, + "optional": true }, "is-finite": { "version": "1.0.2", @@ -5496,8 +5455,7 @@ "is-function": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/is-function/-/is-function-1.0.2.tgz", - "integrity": "sha512-lw7DUp0aWXYg+CBCN+JKkcE0Q2RayZnSvnZBlwgxHBQhqt5pZNVy4Ri7H9GmmXkdu7LUthszM+Tor1u/2iBcpQ==", - "dev": true + "integrity": "sha512-lw7DUp0aWXYg+CBCN+JKkcE0Q2RayZnSvnZBlwgxHBQhqt5pZNVy4Ri7H9GmmXkdu7LUthszM+Tor1u/2iBcpQ==" }, "is-generator-fn": { "version": "1.0.0", @@ -5595,8 +5553,7 @@ "is-typedarray": { "version": "1.0.0", "resolved": "http://registry.npm.taobao.org/is-typedarray/download/is-typedarray-1.0.0.tgz", - "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=", - "dev": true + "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=" }, "is-utf8": { "version": "0.2.1", @@ -5641,8 +5598,7 @@ "isstream": { "version": "0.1.2", "resolved": "http://registry.npm.taobao.org/isstream/download/isstream-0.1.2.tgz", - "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=", - "dev": true + "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=" }, "istanbul-api": { "version": "1.3.7", @@ -6852,8 +6808,7 @@ "jsbn": { "version": "0.1.1", "resolved": "http://registry.npm.taobao.org/jsbn/download/jsbn-0.1.1.tgz", - "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=", - "dev": true + "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=" }, "jsdoc": { "version": "3.5.5", @@ -6992,14 +6947,12 @@ "json-schema": { "version": "0.2.3", "resolved": "http://registry.npm.taobao.org/json-schema/download/json-schema-0.2.3.tgz", - "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=", - "dev": true + "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM=" }, "json-schema-traverse": { "version": "0.4.1", "resolved": "http://registry.npm.taobao.org/json-schema-traverse/download/json-schema-traverse-0.4.1.tgz", - "integrity": "sha1-afaofZUTq4u4/mO9sJecRI5oRmA=", - "dev": true + "integrity": "sha1-afaofZUTq4u4/mO9sJecRI5oRmA=" }, "json-stable-stringify": { "version": "0.0.1", @@ -7046,7 +6999,6 @@ "version": "1.4.1", "resolved": "http://registry.npm.taobao.org/jsprim/download/jsprim-1.4.1.tgz", "integrity": "sha1-MT5mvB5cwG5Di8G3SZwuXFastqI=", - "dev": true, "requires": { "assert-plus": "1.0.0", "extsprintf": "1.3.0", @@ -7280,8 +7232,7 @@ "media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", - "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=", - "dev": true + "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=" }, "mem": { "version": "1.1.0", @@ -7301,8 +7252,7 @@ "merge-descriptors": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", - "integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=", - "dev": true + "integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=" }, "merge-stream": { "version": "1.0.1", @@ -7316,8 +7266,7 @@ "methods": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", - "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=", - "dev": true + "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=" }, "micromatch": { "version": "3.1.10", @@ -7352,20 +7301,17 @@ "mime": { "version": "1.6.0", "resolved": "http://registry.npm.taobao.org/mime/download/mime-1.6.0.tgz", - "integrity": "sha1-Ms2eXGRVO9WNGaVor0Uqz/BJgbE=", - "dev": true + "integrity": "sha1-Ms2eXGRVO9WNGaVor0Uqz/BJgbE=" }, "mime-db": { "version": "1.38.0", "resolved": "http://registry.npm.taobao.org/mime-db/download/mime-db-1.38.0.tgz", - "integrity": "sha1-GiqrFtqesWe0nG5N8tnGjWPY4q0=", - "dev": true + "integrity": "sha1-GiqrFtqesWe0nG5N8tnGjWPY4q0=" }, "mime-types": { "version": "2.1.22", "resolved": "http://registry.npm.taobao.org/mime-types/download/mime-types-2.1.22.tgz", "integrity": "sha1-/ms1WhkJJqt2mMmgVWoRGZshmb0=", - "dev": true, "requires": { "mime-db": "~1.38.0" } @@ -7379,14 +7325,12 @@ "mimic-response": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz", - "integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==", - "dev": true + "integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==" }, "min-document": { "version": "2.19.0", "resolved": "https://registry.npmjs.org/min-document/-/min-document-2.19.0.tgz", "integrity": "sha1-e9KC4/WELtKVu3SM3Z8f+iyCRoU=", - "dev": true, "requires": { "dom-walk": "^0.1.0" } @@ -7501,8 +7445,7 @@ "nano-json-stream-parser": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/nano-json-stream-parser/-/nano-json-stream-parser-0.1.2.tgz", - "integrity": "sha1-DMj20OK2IrR5xA1JnEbWS3Vcb18=", - "dev": true + "integrity": "sha1-DMj20OK2IrR5xA1JnEbWS3Vcb18=" }, "nanomatch": { "version": "1.2.13", @@ -7543,8 +7486,7 @@ "negotiator": { "version": "0.6.2", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz", - "integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw==", - "dev": true + "integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw==" }, "neo-async": { "version": "2.6.0", @@ -7645,14 +7587,12 @@ "oauth-sign": { "version": "0.9.0", "resolved": "http://registry.npm.taobao.org/oauth-sign/download/oauth-sign-0.9.0.tgz", - "integrity": "sha1-R6ewFrqmi1+g7PPe4IqFxnmsZFU=", - "dev": true + "integrity": "sha1-R6ewFrqmi1+g7PPe4IqFxnmsZFU=" }, "object-assign": { "version": "4.1.1", "resolved": "http://registry.npm.taobao.org/object-assign/download/object-assign-4.1.1.tgz", - "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", - "dev": true + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" }, "object-copy": { "version": "0.1.0", @@ -7745,7 +7685,6 @@ "version": "2.3.0", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=", - "dev": true, "requires": { "ee-first": "1.1.1" } @@ -7956,8 +7895,7 @@ "parse-headers": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/parse-headers/-/parse-headers-2.0.3.tgz", - "integrity": "sha512-QhhZ+DCCit2Coi2vmAKbq5RGTRcQUOE2+REgv8vdyu7MnYx2eZztegqtTx99TZ86GTIwqiy3+4nQTWZ2tgmdCA==", - "dev": true + "integrity": "sha512-QhhZ+DCCit2Coi2vmAKbq5RGTRcQUOE2+REgv8vdyu7MnYx2eZztegqtTx99TZ86GTIwqiy3+4nQTWZ2tgmdCA==" }, "parse-json": { "version": "2.2.0", @@ -7977,8 +7915,7 @@ "parseurl": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", - "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", - "dev": true + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==" }, "pascalcase": { "version": "0.1.1", @@ -8038,8 +7975,7 @@ "path-to-regexp": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", - "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=", - "dev": true + "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=" }, "path-type": { "version": "1.1.0", @@ -8067,8 +8003,7 @@ "performance-now": { "version": "2.1.0", "resolved": "http://registry.npm.taobao.org/performance-now/download/performance-now-2.1.0.tgz", - "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=", - "dev": true + "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=" }, "pify": { "version": "2.3.0", @@ -8188,8 +8123,7 @@ "process": { "version": "0.11.10", "resolved": "http://registry.npm.taobao.org/process/download/process-0.11.10.tgz", - "integrity": "sha1-czIwDoQBYb2j5podHZGn1LwW8YI=", - "dev": true + "integrity": "sha1-czIwDoQBYb2j5podHZGn1LwW8YI=" }, "process-nextick-args": { "version": "2.0.0", @@ -8225,7 +8159,6 @@ "version": "2.0.6", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.6.tgz", "integrity": "sha512-dh/frvCBVmSsDYzw6n926jv974gddhkFPfiN8hPOi30Wax25QZyZEGveluCgliBnqmuM+UJmBErbAUFIoDbjOw==", - "dev": true, "requires": { "forwarded": "~0.1.2", "ipaddr.js": "1.9.1" @@ -8240,8 +8173,7 @@ "psl": { "version": "1.1.31", "resolved": "http://registry.npm.taobao.org/psl/download/psl-1.1.31.tgz", - "integrity": "sha1-6aqG0BAbWxBcvpOsa3hM1UcnYYQ=", - "dev": true + "integrity": "sha1-6aqG0BAbWxBcvpOsa3hM1UcnYYQ=" }, "public-encrypt": { "version": "4.0.3", @@ -8278,8 +8210,7 @@ "punycode": { "version": "1.4.1", "resolved": "http://registry.npm.taobao.org/punycode/download/punycode-1.4.1.tgz", - "integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=", - "dev": true + "integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=" }, "qs": { "version": "2.3.3", @@ -8291,7 +8222,6 @@ "version": "5.1.1", "resolved": "https://registry.npmjs.org/query-string/-/query-string-5.1.1.tgz", "integrity": "sha512-gjWOsm2SoGlgLEdAGt7a6slVOk9mGiXmPFMqrEhLQ68rhQuBnpfs3+EmlvqKyxnCo9/PPlF+9MtY02S1aFg+Jw==", - "dev": true, "requires": { "decode-uri-component": "^0.2.0", "object-assign": "^4.1.0", @@ -8378,14 +8308,12 @@ "range-parser": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", - "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", - "dev": true + "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==" }, "raw-body": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.4.0.tgz", "integrity": "sha512-4Oz8DUIwdvoa5qMJelxipzi/iJIi40O5cGV1wNYp5hvZP8ZN0T+jiNkL0QepXs+EsQ9XJ8ipEDoiH70ySUJP3Q==", - "dev": true, "requires": { "bytes": "3.1.0", "http-errors": "1.7.2", @@ -8679,7 +8607,6 @@ "version": "2.88.0", "resolved": "http://registry.npm.taobao.org/request/download/request-2.88.0.tgz", "integrity": "sha1-nC/KT301tZLv5Xx/ClXoEFIST+8=", - "dev": true, "requires": { "aws-sign2": "~0.7.0", "aws4": "^1.8.0", @@ -8706,14 +8633,12 @@ "qs": { "version": "6.5.2", "resolved": "http://registry.npm.taobao.org/qs/download/qs-6.5.2.tgz", - "integrity": "sha1-yzroBuh0BERYTvFUzo7pjUA/PjY=", - "dev": true + "integrity": "sha1-yzroBuh0BERYTvFUzo7pjUA/PjY=" }, "tough-cookie": { "version": "2.4.3", "resolved": "http://registry.npm.taobao.org/tough-cookie/download/tough-cookie-2.4.3.tgz", "integrity": "sha1-U/Nto/R3g7CSWvoG/587FlKA94E=", - "dev": true, "requires": { "psl": "^1.1.24", "punycode": "^1.4.1" @@ -8895,8 +8820,7 @@ "safer-buffer": { "version": "2.1.2", "resolved": "http://registry.npm.taobao.org/safer-buffer/download/safer-buffer-2.1.2.tgz", - "integrity": "sha1-RPoWGwGHuVSd2Eu5GAL5vYOFzWo=", - "dev": true + "integrity": "sha1-RPoWGwGHuVSd2Eu5GAL5vYOFzWo=" }, "sane": { "version": "2.5.2", @@ -8973,7 +8897,6 @@ "version": "0.17.1", "resolved": "https://registry.npmjs.org/send/-/send-0.17.1.tgz", "integrity": "sha512-BsVKsiGcQMFwT8UxypobUKyv7irCNRHk1T0G680vk88yf6LBByGcZJOTJCrTP2xVN6yI+XjPJcNuE3V4fT9sAg==", - "dev": true, "requires": { "debug": "2.6.9", "depd": "~1.1.2", @@ -8994,7 +8917,6 @@ "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "dev": true, "requires": { "ms": "2.0.0" }, @@ -9002,8 +8924,7 @@ "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", - "dev": true + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" } } } @@ -9013,7 +8934,6 @@ "version": "1.14.1", "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.14.1.tgz", "integrity": "sha512-JMrvUwE54emCYWlTI+hGrGv5I8dEwmco/00EvkzIIsR7MqrHonbD9pO2MOfFnpFntl7ecpZs+3mW+XbQZu9QCg==", - "dev": true, "requires": { "encodeurl": "~1.0.2", "escape-html": "~1.0.3", @@ -9025,7 +8945,6 @@ "version": "0.1.12", "resolved": "https://registry.npmjs.org/servify/-/servify-0.1.12.tgz", "integrity": "sha512-/xE6GvsKKqyo1BAY+KxOWXcLpPsUUyji7Qg3bVD7hh1eRze5bR1uYiuDA/k3Gof1s9BTzQZEJK8sNcNGFIzeWw==", - "dev": true, "requires": { "body-parser": "^1.16.0", "cors": "^2.8.1", @@ -9066,8 +8985,7 @@ "setprototypeof": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz", - "integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw==", - "dev": true + "integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw==" }, "sha.js": { "version": "2.4.11", @@ -9138,14 +9056,12 @@ "simple-concat": { "version": "1.0.0", "resolved": "http://registry.npm.taobao.org/simple-concat/download/simple-concat-1.0.0.tgz", - "integrity": "sha1-c0TLuLbib7J9ZrL8hvn21Zl1IcY=", - "dev": true + "integrity": "sha1-c0TLuLbib7J9ZrL8hvn21Zl1IcY=" }, "simple-get": { "version": "2.8.1", "resolved": "https://registry.npmjs.org/simple-get/-/simple-get-2.8.1.tgz", "integrity": "sha512-lSSHRSw3mQNUGPAYRqo7xy9dhKmxFXIjLjp4KHpf99GEH2VH7C3AM+Qfx6du6jhfUi6Vm7XnbEVEf7Wb6N8jRw==", - "dev": true, "requires": { "decompress-response": "^3.3.0", "once": "^1.3.1", @@ -9420,7 +9336,6 @@ "version": "1.16.1", "resolved": "http://registry.npm.taobao.org/sshpk/download/sshpk-1.16.1.tgz", "integrity": "sha1-+2YcC+8ps520B2nuOfpwCT1vaHc=", - "dev": true, "requires": { "asn1": "~0.2.3", "assert-plus": "^1.0.0", @@ -9463,8 +9378,7 @@ "statuses": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", - "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=", - "dev": true + "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=" }, "stealthy-require": { "version": "1.1.1", @@ -9549,8 +9463,7 @@ "strict-uri-encode": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz", - "integrity": "sha1-J5siXfHVgrH1TmWt3UNS4Y+qBxM=", - "dev": true + "integrity": "sha1-J5siXfHVgrH1TmWt3UNS4Y+qBxM=" }, "string-length": { "version": "2.0.0", @@ -9885,8 +9798,7 @@ "timed-out": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/timed-out/-/timed-out-4.0.1.tgz", - "integrity": "sha1-8y6srFoXW+ol1/q1Zas+2HQe9W8=", - "dev": true + "integrity": "sha1-8y6srFoXW+ol1/q1Zas+2HQe9W8=" }, "timers-browserify": { "version": "1.4.2", @@ -9981,8 +9893,7 @@ "toidentifier": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz", - "integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==", - "dev": true + "integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==" }, "tough-cookie": { "version": "2.5.0", @@ -10041,7 +9952,6 @@ "version": "0.6.0", "resolved": "http://registry.npm.taobao.org/tunnel-agent/download/tunnel-agent-0.6.0.tgz", "integrity": "sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0=", - "dev": true, "requires": { "safe-buffer": "^5.0.1" } @@ -10049,8 +9959,7 @@ "tweetnacl": { "version": "0.14.5", "resolved": "http://registry.npm.taobao.org/tweetnacl/download/tweetnacl-0.14.5.tgz", - "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=", - "dev": true + "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=" }, "type-check": { "version": "0.3.2", @@ -10071,7 +9980,6 @@ "version": "1.6.18", "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", - "dev": true, "requires": { "media-typer": "0.3.0", "mime-types": "~2.1.24" @@ -10080,14 +9988,12 @@ "mime-db": { "version": "1.45.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.45.0.tgz", - "integrity": "sha512-CkqLUxUk15hofLoLyljJSrukZi8mAtgd+yE5uO4tqRZsdsAJKv0O+rFMhVDRJgozy+yG6md5KwuXhD4ocIoP+w==", - "dev": true + "integrity": "sha512-CkqLUxUk15hofLoLyljJSrukZi8mAtgd+yE5uO4tqRZsdsAJKv0O+rFMhVDRJgozy+yG6md5KwuXhD4ocIoP+w==" }, "mime-types": { "version": "2.1.28", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.28.tgz", "integrity": "sha512-0TO2yJ5YHYr7M2zzT7gDU1tbwHxEUWBCLt0lscSNpcdAfFyJOVEpRYNS7EXVcTLNj/25QO8gulHC5JtTzSE2UQ==", - "dev": true, "requires": { "mime-db": "1.45.0" } @@ -10252,8 +10158,7 @@ "unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", - "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=", - "dev": true + "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=" }, "unset-value": { "version": "1.0.0", @@ -10306,7 +10211,6 @@ "version": "4.2.2", "resolved": "http://registry.npm.taobao.org/uri-js/download/uri-js-4.2.2.tgz", "integrity": "sha1-lMVA4f93KVbiKZUHwBCupsiDjrA=", - "dev": true, "requires": { "punycode": "^2.1.0" }, @@ -10314,8 +10218,7 @@ "punycode": { "version": "2.1.1", "resolved": "http://registry.npm.taobao.org/punycode/download/punycode-2.1.1.tgz", - "integrity": "sha1-tYsBCsQMIsVldhbI0sLALHv0eew=", - "dev": true + "integrity": "sha1-tYsBCsQMIsVldhbI0sLALHv0eew=" } } }, @@ -10350,8 +10253,7 @@ "url-set-query": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/url-set-query/-/url-set-query-1.0.0.tgz", - "integrity": "sha1-AW6M/Xwg7gXK/neV6JK9BwL6ozk=", - "dev": true + "integrity": "sha1-AW6M/Xwg7gXK/neV6JK9BwL6ozk=" }, "use": { "version": "3.1.1", @@ -10386,8 +10288,7 @@ "utils-merge": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", - "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=", - "dev": true + "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=" }, "uuid": { "version": "3.3.2", @@ -10421,14 +10322,12 @@ "vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", - "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=", - "dev": true + "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" }, "verror": { "version": "1.10.0", "resolved": "http://registry.npm.taobao.org/verror/download/verror-1.10.0.tgz", "integrity": "sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=", - "dev": true, "requires": { "assert-plus": "^1.0.0", "core-util-is": "1.0.2", @@ -10619,7 +10518,6 @@ "version": "2.6.0", "resolved": "https://registry.npmjs.org/xhr/-/xhr-2.6.0.tgz", "integrity": "sha512-/eCGLb5rxjx5e3mF1A7s+pLlR6CGyqWN91fv1JgER5mVWg1MZmlhBvy9kjcsOdRk8RrIujotWyJamfyrp+WIcA==", - "dev": true, "requires": { "global": "~4.4.0", "is-function": "^1.0.1", @@ -10631,7 +10529,6 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/xhr-request/-/xhr-request-1.1.0.tgz", "integrity": "sha512-Y7qzEaR3FDtL3fP30k9wO/e+FBnBByZeybKOhASsGP30NIkRAAkKD/sCnLvgEfAIEC1rcmK7YG8f4oEnIrrWzA==", - "dev": true, "requires": { "buffer-to-arraybuffer": "^0.0.5", "object-assign": "^4.1.1", @@ -10646,7 +10543,6 @@ "version": "0.1.3", "resolved": "https://registry.npmjs.org/xhr-request-promise/-/xhr-request-promise-0.1.3.tgz", "integrity": "sha512-YUBytBsuwgitWtdRzXDDkWAXzhdGB8bYm0sSzMPZT7Z2MBjMSTHFsyCT1yCRATY+XC69DUrQraRAEgcoCRaIPg==", - "dev": true, "requires": { "xhr-request": "^1.1.0" } diff --git a/package.json b/package.json index fba42f6..12f3880 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@okexchain/javascript-sdk", - "version": "0.0.30", + "version": "0.0.31", "license": "Apache-2.0", "main": "lib/index.js", "scripts": { @@ -22,6 +22,7 @@ "camelcase": "^5.3.1", "crypto-browserify": "^3.12.0", "crypto-js": "^3.1.9-1", + "eth-lib": "^0.1.29", "events": "^3.0.0", "is_js": "^0.9.0", "keccak": "^3.0.1", @@ -53,7 +54,6 @@ "buffer": "^5.2.1", "cross-env": "^5.2.0", "eslint": "^5.11.1", - "eth-lib": "^0.1.29", "http-server": "^0.11.1", "husky": "^3.0.0", "jest": "^23.6.0", From 59eee3f2a4a43a950de973bc1f5228f1582cc25b Mon Sep 17 00:00:00 2001 From: zhengchao Date: Thu, 4 Mar 2021 18:14:03 +0800 Subject: [PATCH 4/9] gen docs --- docs/okexchain-jssdk-doc-client.md | 310 +++++++++++++++++ docs/okexchain-jssdk-doc-crypto.md | 310 +++++++++++++++++ docs/okexchain-jssdk-doc.md | 538 ----------------------------- package.json | 6 +- 4 files changed, 624 insertions(+), 540 deletions(-) create mode 100644 docs/okexchain-jssdk-doc-client.md create mode 100644 docs/okexchain-jssdk-doc-crypto.md delete mode 100644 docs/okexchain-jssdk-doc.md diff --git a/docs/okexchain-jssdk-doc-client.md b/docs/okexchain-jssdk-doc-client.md new file mode 100644 index 0000000..c9e0609 --- /dev/null +++ b/docs/okexchain-jssdk-doc-client.md @@ -0,0 +1,310 @@ + + +## crypto + +* [crypto](#module_crypto) + * _static_ + * [.getHDPath](#module_crypto.getHDPath) + * [.decodeAddressToBuffer](#module_crypto.decodeAddressToBuffer) + * [.validateAddress](#module_crypto.validateAddress) ⇒ boolean + * [.encodeAddressToBech32](#module_crypto.encodeAddressToBech32) ⇒ string + * [.generatePrivateKey](#module_crypto.generatePrivateKey) ⇒ string + * [.getPubKeyFromHex](#module_crypto.getPubKeyFromHex) ⇒ Elliptic.PublicKey + * [.encodePubKeyToCompressedBuffer](#module_crypto.encodePubKeyToCompressedBuffer) ⇒ Buffer + * [.getPubKeyHexFromPrivateKey](#module_crypto.getPubKeyHexFromPrivateKey) ⇒ string + * [.getPubKeyFromPrivateKey](#module_crypto.getPubKeyFromPrivateKey) ⇒ Elliptic.PublicKey + * [.getAddressFromPubKey](#module_crypto.getAddressFromPubKey) ⇒ string + * [.getAddressFromPrivateKey](#module_crypto.getAddressFromPrivateKey) ⇒ string + * [.sign](#module_crypto.sign) ⇒ Buffer + * [.validateSig](#module_crypto.validateSig) ⇒ boolean + * [.generateKeyStore](#module_crypto.generateKeyStore) ⇒ object + * [.getPrivateKeyFromKeyStore](#module_crypto.getPrivateKeyFromKeyStore) ⇒ string + * [.generateMnemonic](#module_crypto.generateMnemonic) ⇒ string + * [.validateMnemonic](#module_crypto.validateMnemonic) ⇒ bool + * [.getPrivateKeyFromMnemonic](#module_crypto.getPrivateKeyFromMnemonic) ⇒ string + * [.sha256Ripemd160](#module_crypto.sha256Ripemd160) ⇒ string + * [.sha256](#module_crypto.sha256) ⇒ string + * _inner_ + * [~isBN(object)](#module_crypto..isBN) ⇒ Boolean + * [~isHexStrict(hex)](#module_crypto..isHexStrict) ⇒ Boolean + * [~sha3()](#module_crypto..sha3) ⇒ String + * [~toChecksumAddress(address)](#module_crypto..toChecksumAddress) ⇒ String + + + +### crypto.getHDPath +Get HD path by cointype param . + +**Kind**: static constant of [crypto](#module_crypto) + +| Param | Type | Description | +| --- | --- | --- | +| cointype, | string | default 60 | + + + +### crypto.decodeAddressToBuffer +Decode address from bech32 to buffer. + +**Kind**: static constant of [crypto](#module_crypto) + +| Param | Type | Description | +| --- | --- | --- | +| addr | string | bech32 format | + + + +### crypto.validateAddress ⇒ boolean +Validate address. + +**Kind**: static constant of [crypto](#module_crypto) + +| Param | Type | Description | +| --- | --- | --- | +| addr | string | bech32 format | + + + +### crypto.encodeAddressToBech32 ⇒ string +Encodes address from hex to bech32 format. + +**Kind**: static constant of [crypto](#module_crypto) +**Returns**: string - address with bech32 format + +| Param | Type | Description | +| --- | --- | --- | +| hexAddr | string | address in hex string | +| prefix | string | address prefix | + + + +### crypto.generatePrivateKey ⇒ string +Generates privateKey. + +**Kind**: static constant of [crypto](#module_crypto) +**Returns**: string - privateKey hex string + +| Param | Type | Description | +| --- | --- | --- | +| len | number | privateKey length (default: 32 bytes) | + + + +### crypto.getPubKeyFromHex ⇒ Elliptic.PublicKey +Get publicKey from hex string. + +**Kind**: static constant of [crypto](#module_crypto) +**Returns**: Elliptic.PublicKey - pubKey + +| Param | Type | Description | +| --- | --- | --- | +| publicKey | string | pubKey with hex string format | + + + +### crypto.encodePubKeyToCompressedBuffer ⇒ Buffer +Encode pubKey to compressed pubKey buffer. + +**Kind**: static constant of [crypto](#module_crypto) + +| Param | Type | +| --- | --- | +| pubKey | Elliptic.PublicKey | + + + +### crypto.getPubKeyHexFromPrivateKey ⇒ string +Get public key from private key. + +**Kind**: static constant of [crypto](#module_crypto) +**Returns**: string - public key in hex string + +| Param | Type | Description | +| --- | --- | --- | +| privateKeyHex | string | the private key hex string | + + + +### crypto.getPubKeyFromPrivateKey ⇒ Elliptic.PublicKey +Get public key from private key. + +**Kind**: static constant of [crypto](#module_crypto) +**Returns**: Elliptic.PublicKey - PubKey + +| Param | Type | +| --- | --- | +| privateKey | Buffer | + + + +### crypto.getAddressFromPubKey ⇒ string +Gets address from pubKey with hex format. + +**Kind**: static constant of [crypto](#module_crypto) +**Returns**: string - address + +| Param | Type | Description | +| --- | --- | --- | +| publicKey | string | publicKey hexstring | +| prefix | string | address prefix | + + + +### crypto.getAddressFromPrivateKey ⇒ string +Get address from private key. + +**Kind**: static constant of [crypto](#module_crypto) +**Returns**: string - address + +| Param | Type | Description | +| --- | --- | --- | +| privateKeyHex | string | the private key hexstring | +| prefix | string | address prefix | + + + +### crypto.sign ⇒ Buffer +Sign msg with privateKey and Msg in hex format. + +**Kind**: static constant of [crypto](#module_crypto) +**Returns**: Buffer - Signature. + +| Param | Type | Description | +| --- | --- | --- | +| msgHex | string | msg in hex format. | +| privateKey | string | The private key in hex format. | + + + +### crypto.validateSig ⇒ boolean +Validate signature. + +**Kind**: static constant of [crypto](#module_crypto) + +| Param | Type | Description | +| --- | --- | --- | +| sigHex | string | signature in hex format | +| msgHex | string | msg in hex format. | +| pubKeyHex | string | public key in hex format | + + + +### crypto.generateKeyStore ⇒ object +Generate KeyStore with privateKey and password. + +**Kind**: static constant of [crypto](#module_crypto) + +| Param | Type | +| --- | --- | +| privateKeyHex | string | +| password | string | + + + +### crypto.getPrivateKeyFromKeyStore ⇒ string +Get privateKey from keyStore. + +**Kind**: static constant of [crypto](#module_crypto) +**Returns**: string - privateKey + +| Param | Type | +| --- | --- | +| keystore | string \| object | +| password | string | + + + +### crypto.generateMnemonic ⇒ string +Generate mnemonic. + +**Kind**: static constant of [crypto](#module_crypto) + + +### crypto.validateMnemonic ⇒ bool +Validate mnemonic. + +**Kind**: static constant of [crypto](#module_crypto) + +| Param | Type | +| --- | --- | +| mnemonic. | string | + + + +### crypto.getPrivateKeyFromMnemonic ⇒ string +Get private key from mnemonic. + +**Kind**: static constant of [crypto](#module_crypto) +**Returns**: string - hexstring + +| Param | Type | Description | +| --- | --- | --- | +| mnemonic | string | | +| cointype, | string | default 60 | + + + +### crypto.sha256Ripemd160 ⇒ string +Just like ripemd160(sha256(hex)) + +**Kind**: static constant of [crypto](#module_crypto) +**Returns**: string - hash + +| Param | Type | +| --- | --- | +| hex | string | + + + +### crypto.sha256 ⇒ string +SHA256. + +**Kind**: static constant of [crypto](#module_crypto) +**Returns**: string - hash + +| Param | Type | +| --- | --- | +| hex | string | + + + +### crypto~isBN(object) ⇒ Boolean +Returns true if object is BN, otherwise false + +**Kind**: inner method of [crypto](#module_crypto) + +| Param | Type | +| --- | --- | +| object | Object | + + + +### crypto~isHexStrict(hex) ⇒ Boolean +Check if string is HEX, requires a 0x in front + +**Kind**: inner method of [crypto](#module_crypto) + +| Param | Type | Description | +| --- | --- | --- | +| hex | String | to be checked | + + + +### crypto~sha3() ⇒ String +Hashes values to a sha3 hash using keccak 256 + +To hash a HEX string the hex must have 0x in front. + +**Kind**: inner method of [crypto](#module_crypto) +**Returns**: String - the sha3 string + + +### crypto~toChecksumAddress(address) ⇒ String +Converts to a checksum address + +**Kind**: inner method of [crypto](#module_crypto) + +| Param | Type | Description | +| --- | --- | --- | +| address | String | the given HEX address | + diff --git a/docs/okexchain-jssdk-doc-crypto.md b/docs/okexchain-jssdk-doc-crypto.md new file mode 100644 index 0000000..c9e0609 --- /dev/null +++ b/docs/okexchain-jssdk-doc-crypto.md @@ -0,0 +1,310 @@ + + +## crypto + +* [crypto](#module_crypto) + * _static_ + * [.getHDPath](#module_crypto.getHDPath) + * [.decodeAddressToBuffer](#module_crypto.decodeAddressToBuffer) + * [.validateAddress](#module_crypto.validateAddress) ⇒ boolean + * [.encodeAddressToBech32](#module_crypto.encodeAddressToBech32) ⇒ string + * [.generatePrivateKey](#module_crypto.generatePrivateKey) ⇒ string + * [.getPubKeyFromHex](#module_crypto.getPubKeyFromHex) ⇒ Elliptic.PublicKey + * [.encodePubKeyToCompressedBuffer](#module_crypto.encodePubKeyToCompressedBuffer) ⇒ Buffer + * [.getPubKeyHexFromPrivateKey](#module_crypto.getPubKeyHexFromPrivateKey) ⇒ string + * [.getPubKeyFromPrivateKey](#module_crypto.getPubKeyFromPrivateKey) ⇒ Elliptic.PublicKey + * [.getAddressFromPubKey](#module_crypto.getAddressFromPubKey) ⇒ string + * [.getAddressFromPrivateKey](#module_crypto.getAddressFromPrivateKey) ⇒ string + * [.sign](#module_crypto.sign) ⇒ Buffer + * [.validateSig](#module_crypto.validateSig) ⇒ boolean + * [.generateKeyStore](#module_crypto.generateKeyStore) ⇒ object + * [.getPrivateKeyFromKeyStore](#module_crypto.getPrivateKeyFromKeyStore) ⇒ string + * [.generateMnemonic](#module_crypto.generateMnemonic) ⇒ string + * [.validateMnemonic](#module_crypto.validateMnemonic) ⇒ bool + * [.getPrivateKeyFromMnemonic](#module_crypto.getPrivateKeyFromMnemonic) ⇒ string + * [.sha256Ripemd160](#module_crypto.sha256Ripemd160) ⇒ string + * [.sha256](#module_crypto.sha256) ⇒ string + * _inner_ + * [~isBN(object)](#module_crypto..isBN) ⇒ Boolean + * [~isHexStrict(hex)](#module_crypto..isHexStrict) ⇒ Boolean + * [~sha3()](#module_crypto..sha3) ⇒ String + * [~toChecksumAddress(address)](#module_crypto..toChecksumAddress) ⇒ String + + + +### crypto.getHDPath +Get HD path by cointype param . + +**Kind**: static constant of [crypto](#module_crypto) + +| Param | Type | Description | +| --- | --- | --- | +| cointype, | string | default 60 | + + + +### crypto.decodeAddressToBuffer +Decode address from bech32 to buffer. + +**Kind**: static constant of [crypto](#module_crypto) + +| Param | Type | Description | +| --- | --- | --- | +| addr | string | bech32 format | + + + +### crypto.validateAddress ⇒ boolean +Validate address. + +**Kind**: static constant of [crypto](#module_crypto) + +| Param | Type | Description | +| --- | --- | --- | +| addr | string | bech32 format | + + + +### crypto.encodeAddressToBech32 ⇒ string +Encodes address from hex to bech32 format. + +**Kind**: static constant of [crypto](#module_crypto) +**Returns**: string - address with bech32 format + +| Param | Type | Description | +| --- | --- | --- | +| hexAddr | string | address in hex string | +| prefix | string | address prefix | + + + +### crypto.generatePrivateKey ⇒ string +Generates privateKey. + +**Kind**: static constant of [crypto](#module_crypto) +**Returns**: string - privateKey hex string + +| Param | Type | Description | +| --- | --- | --- | +| len | number | privateKey length (default: 32 bytes) | + + + +### crypto.getPubKeyFromHex ⇒ Elliptic.PublicKey +Get publicKey from hex string. + +**Kind**: static constant of [crypto](#module_crypto) +**Returns**: Elliptic.PublicKey - pubKey + +| Param | Type | Description | +| --- | --- | --- | +| publicKey | string | pubKey with hex string format | + + + +### crypto.encodePubKeyToCompressedBuffer ⇒ Buffer +Encode pubKey to compressed pubKey buffer. + +**Kind**: static constant of [crypto](#module_crypto) + +| Param | Type | +| --- | --- | +| pubKey | Elliptic.PublicKey | + + + +### crypto.getPubKeyHexFromPrivateKey ⇒ string +Get public key from private key. + +**Kind**: static constant of [crypto](#module_crypto) +**Returns**: string - public key in hex string + +| Param | Type | Description | +| --- | --- | --- | +| privateKeyHex | string | the private key hex string | + + + +### crypto.getPubKeyFromPrivateKey ⇒ Elliptic.PublicKey +Get public key from private key. + +**Kind**: static constant of [crypto](#module_crypto) +**Returns**: Elliptic.PublicKey - PubKey + +| Param | Type | +| --- | --- | +| privateKey | Buffer | + + + +### crypto.getAddressFromPubKey ⇒ string +Gets address from pubKey with hex format. + +**Kind**: static constant of [crypto](#module_crypto) +**Returns**: string - address + +| Param | Type | Description | +| --- | --- | --- | +| publicKey | string | publicKey hexstring | +| prefix | string | address prefix | + + + +### crypto.getAddressFromPrivateKey ⇒ string +Get address from private key. + +**Kind**: static constant of [crypto](#module_crypto) +**Returns**: string - address + +| Param | Type | Description | +| --- | --- | --- | +| privateKeyHex | string | the private key hexstring | +| prefix | string | address prefix | + + + +### crypto.sign ⇒ Buffer +Sign msg with privateKey and Msg in hex format. + +**Kind**: static constant of [crypto](#module_crypto) +**Returns**: Buffer - Signature. + +| Param | Type | Description | +| --- | --- | --- | +| msgHex | string | msg in hex format. | +| privateKey | string | The private key in hex format. | + + + +### crypto.validateSig ⇒ boolean +Validate signature. + +**Kind**: static constant of [crypto](#module_crypto) + +| Param | Type | Description | +| --- | --- | --- | +| sigHex | string | signature in hex format | +| msgHex | string | msg in hex format. | +| pubKeyHex | string | public key in hex format | + + + +### crypto.generateKeyStore ⇒ object +Generate KeyStore with privateKey and password. + +**Kind**: static constant of [crypto](#module_crypto) + +| Param | Type | +| --- | --- | +| privateKeyHex | string | +| password | string | + + + +### crypto.getPrivateKeyFromKeyStore ⇒ string +Get privateKey from keyStore. + +**Kind**: static constant of [crypto](#module_crypto) +**Returns**: string - privateKey + +| Param | Type | +| --- | --- | +| keystore | string \| object | +| password | string | + + + +### crypto.generateMnemonic ⇒ string +Generate mnemonic. + +**Kind**: static constant of [crypto](#module_crypto) + + +### crypto.validateMnemonic ⇒ bool +Validate mnemonic. + +**Kind**: static constant of [crypto](#module_crypto) + +| Param | Type | +| --- | --- | +| mnemonic. | string | + + + +### crypto.getPrivateKeyFromMnemonic ⇒ string +Get private key from mnemonic. + +**Kind**: static constant of [crypto](#module_crypto) +**Returns**: string - hexstring + +| Param | Type | Description | +| --- | --- | --- | +| mnemonic | string | | +| cointype, | string | default 60 | + + + +### crypto.sha256Ripemd160 ⇒ string +Just like ripemd160(sha256(hex)) + +**Kind**: static constant of [crypto](#module_crypto) +**Returns**: string - hash + +| Param | Type | +| --- | --- | +| hex | string | + + + +### crypto.sha256 ⇒ string +SHA256. + +**Kind**: static constant of [crypto](#module_crypto) +**Returns**: string - hash + +| Param | Type | +| --- | --- | +| hex | string | + + + +### crypto~isBN(object) ⇒ Boolean +Returns true if object is BN, otherwise false + +**Kind**: inner method of [crypto](#module_crypto) + +| Param | Type | +| --- | --- | +| object | Object | + + + +### crypto~isHexStrict(hex) ⇒ Boolean +Check if string is HEX, requires a 0x in front + +**Kind**: inner method of [crypto](#module_crypto) + +| Param | Type | Description | +| --- | --- | --- | +| hex | String | to be checked | + + + +### crypto~sha3() ⇒ String +Hashes values to a sha3 hash using keccak 256 + +To hash a HEX string the hex must have 0x in front. + +**Kind**: inner method of [crypto](#module_crypto) +**Returns**: String - the sha3 string + + +### crypto~toChecksumAddress(address) ⇒ String +Converts to a checksum address + +**Kind**: inner method of [crypto](#module_crypto) + +| Param | Type | Description | +| --- | --- | --- | +| address | String | the given HEX address | + diff --git a/docs/okexchain-jssdk-doc.md b/docs/okexchain-jssdk-doc.md deleted file mode 100644 index f469605..0000000 --- a/docs/okexchain-jssdk-doc.md +++ /dev/null @@ -1,538 +0,0 @@ -## Modules - -
-
client
-
-
crypto
-
-
- -## Classes - -
-
HttpProxy
-

HttpProxy

-
-
Transaction
-

Transaction

-
-
- - - -## client - -* [client](#module_client) - * [.OKEXChainClient](#module_client.OKEXChainClient) - * [new exports.OKEXChainClient(url)](#new_module_client.OKEXChainClient_new) - * [.setMode(mode)](#module_client.OKEXChainClient+setMode) - * [.setAccountInfo(privateKey)](#module_client.OKEXChainClient+setAccountInfo) ⇒ OKEXChainClient - * [.sendSendTransaction(to, amount, denom, memo, sequenceNumber)](#module_client.OKEXChainClient+sendSendTransaction) ⇒ Object - * [.sendCancelOrderTransaction(orderId, memo, sequenceNumber)](#module_client.OKEXChainClient+sendCancelOrderTransaction) ⇒ Object - * [.sendPlaceOrderTransaction(product, side, price, quantity, memo, sequence)](#module_client.OKEXChainClient+sendPlaceOrderTransaction) ⇒ Object - * [.buildTransaction(msg, signMsg, sequenceNumber, memo)](#module_client.OKEXChainClient+buildTransaction) ⇒ [Transaction](#Transaction) - * [.sendTransaction(tx, mode)](#module_client.OKEXChainClient+sendTransaction) ⇒ Object - * [.getAccount(address)](#module_client.OKEXChainClient+getAccount) ⇒ Object - * [.getBalance(address)](#module_client.OKEXChainClient+getBalance) ⇒ Object - * [.getBalanceFromAccountInfo(accountInfo)](#module_client.OKEXChainClient+getBalanceFromAccountInfo) ⇒ Object - * [.getSequenceNumber(address)](#module_client.OKEXChainClient+getSequenceNumber) ⇒ Number - * [.getSequenceNumberFromAccountInfo(accountInfo)](#module_client.OKEXChainClient+getSequenceNumberFromAccountInfo) ⇒ Number - * [.getAccountNumberFromAccountInfo(accountInfo)](#module_client.OKEXChainClient+getAccountNumberFromAccountInfo) ⇒ Number - - - -### client.OKEXChainClient -The OKEXChain client. - -**Kind**: static class of [client](#module_client) - -* [.OKEXChainClient](#module_client.OKEXChainClient) - * [new exports.OKEXChainClient(url)](#new_module_client.OKEXChainClient_new) - * [.setMode(mode)](#module_client.OKEXChainClient+setMode) - * [.setAccountInfo(privateKey)](#module_client.OKEXChainClient+setAccountInfo) ⇒ OKEXChainClient - * [.sendSendTransaction(to, amount, denom, memo, sequenceNumber)](#module_client.OKEXChainClient+sendSendTransaction) ⇒ Object - * [.sendCancelOrderTransaction(orderId, memo, sequenceNumber)](#module_client.OKEXChainClient+sendCancelOrderTransaction) ⇒ Object - * [.sendPlaceOrderTransaction(product, side, price, quantity, memo, sequence)](#module_client.OKEXChainClient+sendPlaceOrderTransaction) ⇒ Object - * [.buildTransaction(msg, signMsg, sequenceNumber, memo)](#module_client.OKEXChainClient+buildTransaction) ⇒ [Transaction](#Transaction) - * [.sendTransaction(tx, mode)](#module_client.OKEXChainClient+sendTransaction) ⇒ Object - * [.getAccount(address)](#module_client.OKEXChainClient+getAccount) ⇒ Object - * [.getBalance(address)](#module_client.OKEXChainClient+getBalance) ⇒ Object - * [.getBalanceFromAccountInfo(accountInfo)](#module_client.OKEXChainClient+getBalanceFromAccountInfo) ⇒ Object - * [.getSequenceNumber(address)](#module_client.OKEXChainClient+getSequenceNumber) ⇒ Number - * [.getSequenceNumberFromAccountInfo(accountInfo)](#module_client.OKEXChainClient+getSequenceNumberFromAccountInfo) ⇒ Number - * [.getAccountNumberFromAccountInfo(accountInfo)](#module_client.OKEXChainClient+getAccountNumberFromAccountInfo) ⇒ Number - - - -#### new exports.OKEXChainClient(url) - -| Param | Type | -| --- | --- | -| url | string | - - - -#### okexChainClient.setMode(mode) -set the mode when send transaction - -**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) - -| Param | Type | Description | -| --- | --- | --- | -| mode | string | block|sync|async | - - - -#### okexChainClient.setAccountInfo(privateKey) ⇒ OKEXChainClient -**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) - -| Param | Type | -| --- | --- | -| privateKey | string | - - - -#### okexChainClient.sendSendTransaction(to, amount, denom, memo, sequenceNumber) ⇒ Object -Send SendTransaction. - -**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) -**Returns**: Object - response - -| Param | Type | Default | Description | -| --- | --- | --- | --- | -| to | String | | To Address | -| amount | Number | | Coin Quantity | -| denom | String | | Coin Name | -| memo | String | | | -| sequenceNumber | Number | | | - - - -#### okexChainClient.sendCancelOrderTransaction(orderId, memo, sequenceNumber) ⇒ Object -Send CancelOrderTransaction. - -**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) -**Returns**: Object - response - -| Param | Type | Default | -| --- | --- | --- | -| orderId | String | | -| memo | String | | -| sequenceNumber | Number | | - - - -#### okexChainClient.sendPlaceOrderTransaction(product, side, price, quantity, memo, sequence) ⇒ Object -Send PlaceOrderTransaction. - -**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) -**Returns**: Object - response - -| Param | Type | Default | -| --- | --- | --- | -| product | String | | -| side | String | | -| price | Number | | -| quantity | Number | | -| memo | Number | | -| sequence | Number | | - - - -#### okexChainClient.buildTransaction(msg, signMsg, sequenceNumber, memo) ⇒ [Transaction](#Transaction) -Build Transaction for sending to OKEXChain. - -**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) -**Returns**: [Transaction](#Transaction) - Transaction object - -| Param | Type | Default | -| --- | --- | --- | -| msg | Object | | -| signMsg | Object | | -| sequenceNumber | Number | | -| memo | String | | - - - -#### okexChainClient.sendTransaction(tx, mode) ⇒ Object -send transaction to OKEXChain. - -**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) -**Returns**: Object - response (success or fail) - -| Param | Type | Description | -| --- | --- | --- | -| tx | signedTx | signed Transaction object | -| mode | Boolean | use synchronous mode, optional | - - - -#### okexChainClient.getAccount(address) ⇒ Object -get account - -**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) -**Returns**: Object - result - -| Param | Type | -| --- | --- | -| address | String | - - - -#### okexChainClient.getBalance(address) ⇒ Object -get balances from OKEXChain - -**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) -**Returns**: Object - result - -| Param | Type | -| --- | --- | -| address | String | - - - -#### okexChainClient.getBalanceFromAccountInfo(accountInfo) ⇒ Object -get balances from accountInfo Object - -**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) -**Returns**: Object - result - -| Param | Type | Description | -| --- | --- | --- | -| accountInfo | Object | optional address | - - - -#### okexChainClient.getSequenceNumber(address) ⇒ Number -get SequenceNumber from OKEXChain - -**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) -**Returns**: Number - sequenceNumber - -| Param | Type | -| --- | --- | -| address | String | - - - -#### okexChainClient.getSequenceNumberFromAccountInfo(accountInfo) ⇒ Number -get SequenceNumber from accountInfo Object - -**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) -**Returns**: Number - sequenceNumber - -| Param | Type | -| --- | --- | -| accountInfo | String | - - - -#### okexChainClient.getAccountNumberFromAccountInfo(accountInfo) ⇒ Number -get accountNumber from accountInfo Object - -**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) -**Returns**: Number - accountNumber - -| Param | Type | -| --- | --- | -| accountInfo | String | - - - -## crypto - -* [crypto](#module_crypto) - * [.decodeAddressToBuffer](#module_crypto.decodeAddressToBuffer) - * [.validateAddress](#module_crypto.validateAddress) ⇒ boolean - * [.encodeAddressToBech32](#module_crypto.encodeAddressToBech32) ⇒ string - * [.generatePrivateKey](#module_crypto.generatePrivateKey) ⇒ string - * [.getPubKeyFromHex](#module_crypto.getPubKeyFromHex) ⇒ Elliptic.PublicKey - * [.encodePubKeyToCompressedBuffer](#module_crypto.encodePubKeyToCompressedBuffer) ⇒ Buffer - * [.getPubKeyHexFromPrivateKey](#module_crypto.getPubKeyHexFromPrivateKey) ⇒ string - * [.getPubKeyFromPrivateKey](#module_crypto.getPubKeyFromPrivateKey) ⇒ Elliptic.PublicKey - * [.getAddressFromPubKey](#module_crypto.getAddressFromPubKey) ⇒ string - * [.getAddressFromPrivateKey](#module_crypto.getAddressFromPrivateKey) ⇒ string - * [.sign](#module_crypto.sign) ⇒ Buffer - * [.validateSig](#module_crypto.validateSig) ⇒ boolean - * [.generateKeyStore](#module_crypto.generateKeyStore) ⇒ object - * [.getPrivateKeyFromKeyStore](#module_crypto.getPrivateKeyFromKeyStore) ⇒ string - * [.generateMnemonic](#module_crypto.generateMnemonic) ⇒ string - * [.validateMnemonic](#module_crypto.validateMnemonic) ⇒ bool - * [.getPrivateKeyFromMnemonic](#module_crypto.getPrivateKeyFromMnemonic) ⇒ string - * [.sha256Ripemd160](#module_crypto.sha256Ripemd160) ⇒ string - * [.sha256](#module_crypto.sha256) ⇒ string - - - -### crypto.decodeAddressToBuffer -Decode address from bech32 to buffer. - -**Kind**: static constant of [crypto](#module_crypto) - -| Param | Type | Description | -| --- | --- | --- | -| addr | string | bech32 format | - - - -### crypto.validateAddress ⇒ boolean -Validate address. - -**Kind**: static constant of [crypto](#module_crypto) - -| Param | Type | Description | -| --- | --- | --- | -| addr | string | bech32 format | - - - -### crypto.encodeAddressToBech32 ⇒ string -Encodes address from hex to bech32 format. - -**Kind**: static constant of [crypto](#module_crypto) -**Returns**: string - address with bech32 format - -| Param | Type | Description | -| --- | --- | --- | -| hexAddr | string | address in hex string | -| prefix | string | address prefix | - - - -### crypto.generatePrivateKey ⇒ string -Generates privateKey. - -**Kind**: static constant of [crypto](#module_crypto) -**Returns**: string - privateKey hex string - -| Param | Type | Description | -| --- | --- | --- | -| len | number | privateKey length (default: 32 bytes) | - - - -### crypto.getPubKeyFromHex ⇒ Elliptic.PublicKey -Get publicKey from hex string. - -**Kind**: static constant of [crypto](#module_crypto) -**Returns**: Elliptic.PublicKey - pubKey - -| Param | Type | Description | -| --- | --- | --- | -| publicKey | string | pubKey with hex string format | - - - -### crypto.encodePubKeyToCompressedBuffer ⇒ Buffer -Encode pubKey to compressed pubKey buffer. - -**Kind**: static constant of [crypto](#module_crypto) - -| Param | Type | -| --- | --- | -| pubKey | Elliptic.PublicKey | - - - -### crypto.getPubKeyHexFromPrivateKey ⇒ string -Get public key from private key. - -**Kind**: static constant of [crypto](#module_crypto) -**Returns**: string - public key in hex string - -| Param | Type | Description | -| --- | --- | --- | -| privateKeyHex | string | the private key hex string | - - - -### crypto.getPubKeyFromPrivateKey ⇒ Elliptic.PublicKey -Get public key from private key. - -**Kind**: static constant of [crypto](#module_crypto) -**Returns**: Elliptic.PublicKey - PubKey - -| Param | Type | -| --- | --- | -| privateKey | Buffer | - - - -### crypto.getAddressFromPubKey ⇒ string -Gets address from pubKey with hex format. - -**Kind**: static constant of [crypto](#module_crypto) -**Returns**: string - address - -| Param | Type | Description | -| --- | --- | --- | -| publicKeyHex | string | publicKey hexstring | -| prefix | string | address prefix | - - - -### crypto.getAddressFromPrivateKey ⇒ string -Get address from private key. - -**Kind**: static constant of [crypto](#module_crypto) -**Returns**: string - address - -| Param | Type | Description | -| --- | --- | --- | -| privateKeyHex | string | the private key hexstring | -| prefix | string | address prefix | - - - -### crypto.sign ⇒ Buffer -Sign msg with privateKey and Msg in hex format. - -**Kind**: static constant of [crypto](#module_crypto) -**Returns**: Buffer - Signature. - -| Param | Type | Description | -| --- | --- | --- | -| msgHex | string | msg in hex format. | -| privateKey | string | The private key in hex format. | - - - -### crypto.validateSig ⇒ boolean -Validate signature. - -**Kind**: static constant of [crypto](#module_crypto) - -| Param | Type | Description | -| --- | --- | --- | -| sigHex | string | signature in hex format | -| msgHex | string | msg in hex format. | -| pubKeyHex | string | public key in hex format | - - - -### crypto.generateKeyStore ⇒ object -Generate KeyStore with privateKey and password. - -**Kind**: static constant of [crypto](#module_crypto) - -| Param | Type | -| --- | --- | -| privateKeyHex | string | -| password | string | - - - -### crypto.getPrivateKeyFromKeyStore ⇒ string -Get privateKey from keyStore. - -**Kind**: static constant of [crypto](#module_crypto) -**Returns**: string - privateKey - -| Param | Type | -| --- | --- | -| keystore | string \| object | -| password | string | - - - -### crypto.generateMnemonic ⇒ string -Generate mnemonic. - -**Kind**: static constant of [crypto](#module_crypto) - - -### crypto.validateMnemonic ⇒ bool -Validate mnemonic. - -**Kind**: static constant of [crypto](#module_crypto) - -| Param | Type | -| --- | --- | -| mnemonic. | string | - - - -### crypto.getPrivateKeyFromMnemonic ⇒ string -Get private key from mnemonic. - -**Kind**: static constant of [crypto](#module_crypto) -**Returns**: string - hexstring - -| Param | Type | -| --- | --- | -| mnemonic | string | - - - -### crypto.sha256Ripemd160 ⇒ string -Just like ripemd160(sha256(hex)) - -**Kind**: static constant of [crypto](#module_crypto) -**Returns**: string - hash - -| Param | Type | -| --- | --- | -| hex | string | - - - -### crypto.sha256 ⇒ string -SHA256. - -**Kind**: static constant of [crypto](#module_crypto) -**Returns**: string - hash - -| Param | Type | -| --- | --- | -| hex | string | - - - -## HttpProxy -HttpProxy - -**Kind**: global class - - -## Transaction -Transaction - -**Kind**: global class - -* [Transaction](#Transaction) - * [new Transaction()](#new_Transaction_new) - * [.sign(privateKeyHex, msg)](#Transaction+sign) ⇒ [Transaction](#Transaction) - * [.serializeTransactionWithJson(mode)](#Transaction+serializeTransactionWithJson) ⇒ Object - - - -### new Transaction() - -| Param | Type | -| --- | --- | -| param.account_number | String | -| param.chain_id | String | -| param.fee | Object | -| param.memo | String | -| param.msg | Object | -| param.sequence | String | - - - -### transaction.sign(privateKeyHex, msg) ⇒ [Transaction](#Transaction) -**Kind**: instance method of [Transaction](#Transaction) - -| Param | Type | -| --- | --- | -| privateKeyHex | string | -| msg | Object | - - - -### transaction.serializeTransactionWithJson(mode) ⇒ Object -**Kind**: instance method of [Transaction](#Transaction) - -| Param | Type | -| --- | --- | -| mode | string | - diff --git a/package.json b/package.json index 12f3880..eeedda5 100644 --- a/package.json +++ b/package.json @@ -6,9 +6,11 @@ "scripts": { "test": "cross-env NODE_ENV=test jest", "build": "rm -rf lib && npx babel src -d lib", - "build:docs": "npx jsdoc-to-markdown -f src/**/*.js > docs/okexchain-jssdk-doc.md", + "build:docsclient": "npx jsdoc-to-markdown -f src/*.js > docs/okexchain-jssdk-doc-client.md", + "build:docscrypto": "npx jsdoc-to-markdown -f src/crypto/*.js > docs/okexchain-jssdk-doc-crypto.md", "prepublishOnly": "npm run build", - "lint": "eslint --fix src __tests__" + "lint": "eslint --fix src __tests__", + "sdk": "webpack-dev-server --config build/webpack.config.sdk.js" }, "dependencies": { "axios": "^0.18.0", From a453e4b0d997a79b83c2c78a84050f6192f4a61b Mon Sep 17 00:00:00 2001 From: zhengchao Date: Thu, 4 Mar 2021 19:32:14 +0800 Subject: [PATCH 5/9] gen client docs --- docs/okexchain-jssdk-doc-client.md | 641 ++++++++++++++++++++--------- package.json | 2 +- 2 files changed, 445 insertions(+), 198 deletions(-) diff --git a/docs/okexchain-jssdk-doc-client.md b/docs/okexchain-jssdk-doc-client.md index c9e0609..d610613 100644 --- a/docs/okexchain-jssdk-doc-client.md +++ b/docs/okexchain-jssdk-doc-client.md @@ -1,310 +1,557 @@ - - -## crypto - -* [crypto](#module_crypto) - * _static_ - * [.getHDPath](#module_crypto.getHDPath) - * [.decodeAddressToBuffer](#module_crypto.decodeAddressToBuffer) - * [.validateAddress](#module_crypto.validateAddress) ⇒ boolean - * [.encodeAddressToBech32](#module_crypto.encodeAddressToBech32) ⇒ string - * [.generatePrivateKey](#module_crypto.generatePrivateKey) ⇒ string - * [.getPubKeyFromHex](#module_crypto.getPubKeyFromHex) ⇒ Elliptic.PublicKey - * [.encodePubKeyToCompressedBuffer](#module_crypto.encodePubKeyToCompressedBuffer) ⇒ Buffer - * [.getPubKeyHexFromPrivateKey](#module_crypto.getPubKeyHexFromPrivateKey) ⇒ string - * [.getPubKeyFromPrivateKey](#module_crypto.getPubKeyFromPrivateKey) ⇒ Elliptic.PublicKey - * [.getAddressFromPubKey](#module_crypto.getAddressFromPubKey) ⇒ string - * [.getAddressFromPrivateKey](#module_crypto.getAddressFromPrivateKey) ⇒ string - * [.sign](#module_crypto.sign) ⇒ Buffer - * [.validateSig](#module_crypto.validateSig) ⇒ boolean - * [.generateKeyStore](#module_crypto.generateKeyStore) ⇒ object - * [.getPrivateKeyFromKeyStore](#module_crypto.getPrivateKeyFromKeyStore) ⇒ string - * [.generateMnemonic](#module_crypto.generateMnemonic) ⇒ string - * [.validateMnemonic](#module_crypto.validateMnemonic) ⇒ bool - * [.getPrivateKeyFromMnemonic](#module_crypto.getPrivateKeyFromMnemonic) ⇒ string - * [.sha256Ripemd160](#module_crypto.sha256Ripemd160) ⇒ string - * [.sha256](#module_crypto.sha256) ⇒ string - * _inner_ - * [~isBN(object)](#module_crypto..isBN) ⇒ Boolean - * [~isHexStrict(hex)](#module_crypto..isHexStrict) ⇒ Boolean - * [~sha3()](#module_crypto..sha3) ⇒ String - * [~toChecksumAddress(address)](#module_crypto..toChecksumAddress) ⇒ String - - - -### crypto.getHDPath -Get HD path by cointype param . - -**Kind**: static constant of [crypto](#module_crypto) + + +## client + +* [client](#module_client) + * [.OKEXChainClient](#module_client.OKEXChainClient) + * [new exports.OKEXChainClient(url, config)](#new_module_client.OKEXChainClient_new) + * [.setMode(mode)](#module_client.OKEXChainClient+setMode) + * [.setChainId(id)](#module_client.OKEXChainClient+setChainId) + * [.setAddress(address)](#module_client.OKEXChainClient+setAddress) + * [.setAccountInfo(privateKey)](#module_client.OKEXChainClient+setAccountInfo) ⇒ OKEXChainClient + * [.sendSendTransaction(to, amount, denom, memo, sequenceNumber)](#module_client.OKEXChainClient+sendSendTransaction) ⇒ Object + * [.sendCancelOrderTransaction(orderId, memo, sequenceNumber)](#module_client.OKEXChainClient+sendCancelOrderTransaction) ⇒ Object + * [.sendPlaceOrderTransaction(product, side, price, quantity, memo, sequence)](#module_client.OKEXChainClient+sendPlaceOrderTransaction) ⇒ Object + * [.buildTransaction(msg, signMsg, memo, fee, sequenceNumber)](#module_client.OKEXChainClient+buildTransaction) ⇒ Transaction + * [.sendTransaction(tx, mode)](#module_client.OKEXChainClient+sendTransaction) ⇒ Object + * [.getAccount(address)](#module_client.OKEXChainClient+getAccount) ⇒ Object + * [.getBalance(address)](#module_client.OKEXChainClient+getBalance) ⇒ Object + * [.getBalanceFromAccountInfo(accountInfo)](#module_client.OKEXChainClient+getBalanceFromAccountInfo) ⇒ Object + * [.getSequenceNumber(address)](#module_client.OKEXChainClient+getSequenceNumber) ⇒ Number + * [.getSequenceNumberFromAccountInfo(accountInfo)](#module_client.OKEXChainClient+getSequenceNumberFromAccountInfo) ⇒ Number + * [.getAccountNumberFromAccountInfo(accountInfo)](#module_client.OKEXChainClient+getAccountNumberFromAccountInfo) ⇒ Number + * [.sendTokenIssueTransaction(symbol, whole_name, total_supply, mintable, description, memo, sequenceNumber)](#module_client.OKEXChainClient+sendTokenIssueTransaction) ⇒ Object + * [.sendTokenBurnTransaction(token, amount, memo, sequenceNumber)](#module_client.OKEXChainClient+sendTokenBurnTransaction) ⇒ Object + * [.sendTokenMintTransaction(token, amount, memo, sequenceNumber)](#module_client.OKEXChainClient+sendTokenMintTransaction) ⇒ Object + * [.sendRegisterDexOperatorTransaction(website, handling_fee_address, memo, sequenceNumber)](#module_client.OKEXChainClient+sendRegisterDexOperatorTransaction) ⇒ Object + * [.sendListTokenPairTransaction(base_asset, quote_asset, init_price, memo, sequenceNumber)](#module_client.OKEXChainClient+sendListTokenPairTransaction) ⇒ Object + * [.sendAddProductDepositTransaction(amount, product, memo, sequenceNumber)](#module_client.OKEXChainClient+sendAddProductDepositTransaction) ⇒ Object + * [.sendWithdrawProductDepositTransaction(amount, product, memo, sequenceNumber)](#module_client.OKEXChainClient+sendWithdrawProductDepositTransaction) ⇒ Object + * [.sendAddLiquidityTransaction(min_liquidity, max_base_amount, base_token, quote_amount, quote_token, deadline, memo, sequenceNumber)](#module_client.OKEXChainClient+sendAddLiquidityTransaction) ⇒ Object + * [.sendRemoveLiquidityTransaction(liquidity, min_base_amount, base_token, min_quote_amount, quote_token, deadline, memo, sequenceNumber)](#module_client.OKEXChainClient+sendRemoveLiquidityTransaction) ⇒ Object + * [.sendCreateExchangeTransaction(Token0Name, Token1Name, memo, sequenceNumber)](#module_client.OKEXChainClient+sendCreateExchangeTransaction) ⇒ Object + * [.sendSwapTokenTransaction(sold_token_amount, sold_token, min_bought_token_amount, bought_token, deadline, recipient, memo, sequenceNumber)](#module_client.OKEXChainClient+sendSwapTokenTransaction) ⇒ Object + * [.sendFarmCreatePoolTransaction(pool_name, min_lock_denom, min_lock_amount, yield_symbol, memo, sequenceNumber)](#module_client.OKEXChainClient+sendFarmCreatePoolTransaction) ⇒ Object + * [.sendFarmDestroyPoolTransaction(pool_name, memo, sequenceNumber)](#module_client.OKEXChainClient+sendFarmDestroyPoolTransaction) ⇒ Object + * [.sendFarmProvideTransaction(pool_name, provide_denom, provide_amount, yielded_per_block, start_height, memo, sequenceNumber)](#module_client.OKEXChainClient+sendFarmProvideTransaction) ⇒ Object + * [.sendFarmLockTransaction(pool_name, lock_denom, lock_amount, memo, sequenceNumber)](#module_client.OKEXChainClient+sendFarmLockTransaction) ⇒ Object + * [.sendFarmUnLockTransaction(pool_name, unlock_denom, unlock_amount, memo, sequenceNumber)](#module_client.OKEXChainClient+sendFarmUnLockTransaction) ⇒ Object + * [.sendFarmClaimTransaction(pool_name, memo, sequenceNumber)](#module_client.OKEXChainClient+sendFarmClaimTransaction) ⇒ Object + + + +### client.OKEXChainClient +The OKEXChain client. + +**Kind**: static class of [client](#module_client) + +* [.OKEXChainClient](#module_client.OKEXChainClient) + * [new exports.OKEXChainClient(url, config)](#new_module_client.OKEXChainClient_new) + * [.setMode(mode)](#module_client.OKEXChainClient+setMode) + * [.setChainId(id)](#module_client.OKEXChainClient+setChainId) + * [.setAddress(address)](#module_client.OKEXChainClient+setAddress) + * [.setAccountInfo(privateKey)](#module_client.OKEXChainClient+setAccountInfo) ⇒ OKEXChainClient + * [.sendSendTransaction(to, amount, denom, memo, sequenceNumber)](#module_client.OKEXChainClient+sendSendTransaction) ⇒ Object + * [.sendCancelOrderTransaction(orderId, memo, sequenceNumber)](#module_client.OKEXChainClient+sendCancelOrderTransaction) ⇒ Object + * [.sendPlaceOrderTransaction(product, side, price, quantity, memo, sequence)](#module_client.OKEXChainClient+sendPlaceOrderTransaction) ⇒ Object + * [.buildTransaction(msg, signMsg, memo, fee, sequenceNumber)](#module_client.OKEXChainClient+buildTransaction) ⇒ Transaction + * [.sendTransaction(tx, mode)](#module_client.OKEXChainClient+sendTransaction) ⇒ Object + * [.getAccount(address)](#module_client.OKEXChainClient+getAccount) ⇒ Object + * [.getBalance(address)](#module_client.OKEXChainClient+getBalance) ⇒ Object + * [.getBalanceFromAccountInfo(accountInfo)](#module_client.OKEXChainClient+getBalanceFromAccountInfo) ⇒ Object + * [.getSequenceNumber(address)](#module_client.OKEXChainClient+getSequenceNumber) ⇒ Number + * [.getSequenceNumberFromAccountInfo(accountInfo)](#module_client.OKEXChainClient+getSequenceNumberFromAccountInfo) ⇒ Number + * [.getAccountNumberFromAccountInfo(accountInfo)](#module_client.OKEXChainClient+getAccountNumberFromAccountInfo) ⇒ Number + * [.sendTokenIssueTransaction(symbol, whole_name, total_supply, mintable, description, memo, sequenceNumber)](#module_client.OKEXChainClient+sendTokenIssueTransaction) ⇒ Object + * [.sendTokenBurnTransaction(token, amount, memo, sequenceNumber)](#module_client.OKEXChainClient+sendTokenBurnTransaction) ⇒ Object + * [.sendTokenMintTransaction(token, amount, memo, sequenceNumber)](#module_client.OKEXChainClient+sendTokenMintTransaction) ⇒ Object + * [.sendRegisterDexOperatorTransaction(website, handling_fee_address, memo, sequenceNumber)](#module_client.OKEXChainClient+sendRegisterDexOperatorTransaction) ⇒ Object + * [.sendListTokenPairTransaction(base_asset, quote_asset, init_price, memo, sequenceNumber)](#module_client.OKEXChainClient+sendListTokenPairTransaction) ⇒ Object + * [.sendAddProductDepositTransaction(amount, product, memo, sequenceNumber)](#module_client.OKEXChainClient+sendAddProductDepositTransaction) ⇒ Object + * [.sendWithdrawProductDepositTransaction(amount, product, memo, sequenceNumber)](#module_client.OKEXChainClient+sendWithdrawProductDepositTransaction) ⇒ Object + * [.sendAddLiquidityTransaction(min_liquidity, max_base_amount, base_token, quote_amount, quote_token, deadline, memo, sequenceNumber)](#module_client.OKEXChainClient+sendAddLiquidityTransaction) ⇒ Object + * [.sendRemoveLiquidityTransaction(liquidity, min_base_amount, base_token, min_quote_amount, quote_token, deadline, memo, sequenceNumber)](#module_client.OKEXChainClient+sendRemoveLiquidityTransaction) ⇒ Object + * [.sendCreateExchangeTransaction(Token0Name, Token1Name, memo, sequenceNumber)](#module_client.OKEXChainClient+sendCreateExchangeTransaction) ⇒ Object + * [.sendSwapTokenTransaction(sold_token_amount, sold_token, min_bought_token_amount, bought_token, deadline, recipient, memo, sequenceNumber)](#module_client.OKEXChainClient+sendSwapTokenTransaction) ⇒ Object + * [.sendFarmCreatePoolTransaction(pool_name, min_lock_denom, min_lock_amount, yield_symbol, memo, sequenceNumber)](#module_client.OKEXChainClient+sendFarmCreatePoolTransaction) ⇒ Object + * [.sendFarmDestroyPoolTransaction(pool_name, memo, sequenceNumber)](#module_client.OKEXChainClient+sendFarmDestroyPoolTransaction) ⇒ Object + * [.sendFarmProvideTransaction(pool_name, provide_denom, provide_amount, yielded_per_block, start_height, memo, sequenceNumber)](#module_client.OKEXChainClient+sendFarmProvideTransaction) ⇒ Object + * [.sendFarmLockTransaction(pool_name, lock_denom, lock_amount, memo, sequenceNumber)](#module_client.OKEXChainClient+sendFarmLockTransaction) ⇒ Object + * [.sendFarmUnLockTransaction(pool_name, unlock_denom, unlock_amount, memo, sequenceNumber)](#module_client.OKEXChainClient+sendFarmUnLockTransaction) ⇒ Object + * [.sendFarmClaimTransaction(pool_name, memo, sequenceNumber)](#module_client.OKEXChainClient+sendFarmClaimTransaction) ⇒ Object + + + +#### new exports.OKEXChainClient(url, config) | Param | Type | Description | | --- | --- | --- | -| cointype, | string | default 60 | +| url | string | | +| config | Object | { chainId: "okexchain-66" (mainnet, default) / "okexchain-65" (testnet) relativePath: "/okexchain/v1" (mainnet, default) / "/okexchain-test/v1" (testnet) isMainnet: true (mainnet) / false (other, default) signer: external signer object, Object / null (default) } | - + -### crypto.decodeAddressToBuffer -Decode address from bech32 to buffer. +#### okexChainClient.setMode(mode) +set the mode when send transaction -**Kind**: static constant of [crypto](#module_crypto) +**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) | Param | Type | Description | | --- | --- | --- | -| addr | string | bech32 format | +| mode | string | block|sync|async | - + -### crypto.validateAddress ⇒ boolean -Validate address. +#### okexChainClient.setChainId(id) +set the chainId when send transaction -**Kind**: static constant of [crypto](#module_crypto) +**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) -| Param | Type | Description | +| Param | Type | +| --- | --- | +| id | string | + + + +#### okexChainClient.setAddress(address) +set the address + +**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) + +| Param | Type | +| --- | --- | +| address | string | + + + +#### okexChainClient.setAccountInfo(privateKey) ⇒ OKEXChainClient +**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) + +| Param | Type | +| --- | --- | +| privateKey | string | + + + +#### okexChainClient.sendSendTransaction(to, amount, denom, memo, sequenceNumber) ⇒ Object +Send SendTransaction. + +**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) +**Returns**: Object - response + +| Param | Type | Default | Description | +| --- | --- | --- | --- | +| to | String | | To Address | +| amount | Number | | Coin Quantity | +| denom | String | | Coin Name | +| memo | String | | | +| sequenceNumber | Number | | | + + + +#### okexChainClient.sendCancelOrderTransaction(orderId, memo, sequenceNumber) ⇒ Object +Send CancelOrderTransaction. + +**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) +**Returns**: Object - response + +| Param | Type | Default | | --- | --- | --- | -| addr | string | bech32 format | +| orderId | String | | +| memo | String | | +| sequenceNumber | Number | | - + -### crypto.encodeAddressToBech32 ⇒ string -Encodes address from hex to bech32 format. +#### okexChainClient.sendPlaceOrderTransaction(product, side, price, quantity, memo, sequence) ⇒ Object +Send PlaceOrderTransaction. -**Kind**: static constant of [crypto](#module_crypto) -**Returns**: string - address with bech32 format +**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) +**Returns**: Object - response -| Param | Type | Description | +| Param | Type | Default | | --- | --- | --- | -| hexAddr | string | address in hex string | -| prefix | string | address prefix | +| product | String | | +| side | String | | +| price | Number | | +| quantity | Number | | +| memo | Number | | +| sequence | Number | | - + -### crypto.generatePrivateKey ⇒ string -Generates privateKey. +#### okexChainClient.buildTransaction(msg, signMsg, memo, fee, sequenceNumber) ⇒ Transaction +Build Transaction for sending to okexchain. -**Kind**: static constant of [crypto](#module_crypto) -**Returns**: string - privateKey hex string +**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) +**Returns**: Transaction - Transaction object -| Param | Type | Description | +| Param | Type | Default | | --- | --- | --- | -| len | number | privateKey length (default: 32 bytes) | +| msg | Object | | +| signMsg | Object | | +| memo | String | | +| fee | String | | +| sequenceNumber | Number | | - + -### crypto.getPubKeyFromHex ⇒ Elliptic.PublicKey -Get publicKey from hex string. +#### okexChainClient.sendTransaction(tx, mode) ⇒ Object +send transaction to OKEXChain. -**Kind**: static constant of [crypto](#module_crypto) -**Returns**: Elliptic.PublicKey - pubKey +**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) +**Returns**: Object - response (success or fail) | Param | Type | Description | | --- | --- | --- | -| publicKey | string | pubKey with hex string format | +| tx | signedTx | signed Transaction object | +| mode | Boolean | use synchronous mode, optional | + + + +#### okexChainClient.getAccount(address) ⇒ Object +get account - +**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) +**Returns**: Object - result -### crypto.encodePubKeyToCompressedBuffer ⇒ Buffer -Encode pubKey to compressed pubKey buffer. +| Param | Type | +| --- | --- | +| address | String | + + -**Kind**: static constant of [crypto](#module_crypto) +#### okexChainClient.getBalance(address) ⇒ Object +get balances from OKEXChain + +**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) +**Returns**: Object - result | Param | Type | | --- | --- | -| pubKey | Elliptic.PublicKey | +| address | String | - + -### crypto.getPubKeyHexFromPrivateKey ⇒ string -Get public key from private key. +#### okexChainClient.getBalanceFromAccountInfo(accountInfo) ⇒ Object +get balances from accountInfo Object -**Kind**: static constant of [crypto](#module_crypto) -**Returns**: string - public key in hex string +**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) +**Returns**: Object - result | Param | Type | Description | | --- | --- | --- | -| privateKeyHex | string | the private key hex string | +| accountInfo | Object | optional address | - + -### crypto.getPubKeyFromPrivateKey ⇒ Elliptic.PublicKey -Get public key from private key. +#### okexChainClient.getSequenceNumber(address) ⇒ Number +get SequenceNumber from OKEXChain -**Kind**: static constant of [crypto](#module_crypto) -**Returns**: Elliptic.PublicKey - PubKey +**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) +**Returns**: Number - sequenceNumber | Param | Type | | --- | --- | -| privateKey | Buffer | +| address | String | - + -### crypto.getAddressFromPubKey ⇒ string -Gets address from pubKey with hex format. +#### okexChainClient.getSequenceNumberFromAccountInfo(accountInfo) ⇒ Number +get SequenceNumber from accountInfo Object -**Kind**: static constant of [crypto](#module_crypto) -**Returns**: string - address +**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) +**Returns**: Number - sequenceNumber -| Param | Type | Description | +| Param | Type | +| --- | --- | +| accountInfo | String | + + + +#### okexChainClient.getAccountNumberFromAccountInfo(accountInfo) ⇒ Number +get accountNumber from accountInfo Object + +**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) +**Returns**: Number - accountNumber + +| Param | Type | +| --- | --- | +| accountInfo | String | + + + +#### okexChainClient.sendTokenIssueTransaction(symbol, whole_name, total_supply, mintable, description, memo, sequenceNumber) ⇒ Object +Send TokenIssueTransaction. + +**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) +**Returns**: Object - response + +| Param | Type | Default | | --- | --- | --- | -| publicKey | string | publicKey hexstring | -| prefix | string | address prefix | +| symbol | String | | +| whole_name | String | | +| total_supply | String | | +| mintable | Boolean | false | +| description | String | | +| memo | String | | +| sequenceNumber | Number | | - + -### crypto.getAddressFromPrivateKey ⇒ string -Get address from private key. +#### okexChainClient.sendTokenBurnTransaction(token, amount, memo, sequenceNumber) ⇒ Object +Send TokenBurnTransaction. -**Kind**: static constant of [crypto](#module_crypto) -**Returns**: string - address +**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) +**Returns**: Object - response -| Param | Type | Description | +| Param | Type | Default | | --- | --- | --- | -| privateKeyHex | string | the private key hexstring | -| prefix | string | address prefix | +| token | String | | +| amount | String | | +| memo | String | | +| sequenceNumber | Number | | - + -### crypto.sign ⇒ Buffer -Sign msg with privateKey and Msg in hex format. +#### okexChainClient.sendTokenMintTransaction(token, amount, memo, sequenceNumber) ⇒ Object +Send TokenMintTransaction. -**Kind**: static constant of [crypto](#module_crypto) -**Returns**: Buffer - Signature. +**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) +**Returns**: Object - response -| Param | Type | Description | +| Param | Type | Default | | --- | --- | --- | -| msgHex | string | msg in hex format. | -| privateKey | string | The private key in hex format. | +| token | String | | +| amount | String | | +| memo | String | | +| sequenceNumber | Number | | - + -### crypto.validateSig ⇒ boolean -Validate signature. +#### okexChainClient.sendRegisterDexOperatorTransaction(website, handling_fee_address, memo, sequenceNumber) ⇒ Object +Send RegisterDexOperatorTransaction. -**Kind**: static constant of [crypto](#module_crypto) +**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) +**Returns**: Object - response -| Param | Type | Description | +| Param | Type | Default | | --- | --- | --- | -| sigHex | string | signature in hex format | -| msgHex | string | msg in hex format. | -| pubKeyHex | string | public key in hex format | +| website | String | | +| handling_fee_address | String | | +| memo | String | | +| sequenceNumber | Number | | - + -### crypto.generateKeyStore ⇒ object -Generate KeyStore with privateKey and password. +#### okexChainClient.sendListTokenPairTransaction(base_asset, quote_asset, init_price, memo, sequenceNumber) ⇒ Object +Send ListTokenPairTransaction. -**Kind**: static constant of [crypto](#module_crypto) +**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) +**Returns**: Object - response -| Param | Type | -| --- | --- | -| privateKeyHex | string | -| password | string | +| Param | Type | Default | +| --- | --- | --- | +| base_asset | String | | +| quote_asset | String | | +| init_price | String | | +| memo | String | | +| sequenceNumber | Number | | - + -### crypto.getPrivateKeyFromKeyStore ⇒ string -Get privateKey from keyStore. +#### okexChainClient.sendAddProductDepositTransaction(amount, product, memo, sequenceNumber) ⇒ Object +Send AddProductDepositTransaction. -**Kind**: static constant of [crypto](#module_crypto) -**Returns**: string - privateKey +**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) +**Returns**: Object - response -| Param | Type | -| --- | --- | -| keystore | string \| object | -| password | string | +| Param | Type | Default | +| --- | --- | --- | +| amount | String | | +| product | String | | +| memo | String | | +| sequenceNumber | Number | | - + -### crypto.generateMnemonic ⇒ string -Generate mnemonic. +#### okexChainClient.sendWithdrawProductDepositTransaction(amount, product, memo, sequenceNumber) ⇒ Object +Send WithdrawProductDepositTransaction. -**Kind**: static constant of [crypto](#module_crypto) - +**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) +**Returns**: Object - response -### crypto.validateMnemonic ⇒ bool -Validate mnemonic. +| Param | Type | Default | +| --- | --- | --- | +| amount | String | | +| product | String | | +| memo | String | | +| sequenceNumber | Number | | -**Kind**: static constant of [crypto](#module_crypto) + -| Param | Type | -| --- | --- | -| mnemonic. | string | +#### okexChainClient.sendAddLiquidityTransaction(min_liquidity, max_base_amount, base_token, quote_amount, quote_token, deadline, memo, sequenceNumber) ⇒ Object +Send AddLiquidityTransaction. - +**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) +**Returns**: Object - response -### crypto.getPrivateKeyFromMnemonic ⇒ string -Get private key from mnemonic. +| Param | Type | Default | +| --- | --- | --- | +| min_liquidity | Number | | +| max_base_amount | Number | | +| base_token | String | | +| quote_amount | Number | | +| quote_token | String | | +| deadline | String | | +| memo | String | | +| sequenceNumber | Number | | -**Kind**: static constant of [crypto](#module_crypto) -**Returns**: string - hexstring + -| Param | Type | Description | +#### okexChainClient.sendRemoveLiquidityTransaction(liquidity, min_base_amount, base_token, min_quote_amount, quote_token, deadline, memo, sequenceNumber) ⇒ Object +Send RemoveLiquidityTransaction. + +**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) +**Returns**: Object - response + +| Param | Type | Default | | --- | --- | --- | -| mnemonic | string | | -| cointype, | string | default 60 | +| liquidity | Number | | +| min_base_amount | Number | | +| base_token | String | | +| min_quote_amount | Number | | +| quote_token | String | | +| deadline | String | | +| memo | String | | +| sequenceNumber | Number | | - + -### crypto.sha256Ripemd160 ⇒ string -Just like ripemd160(sha256(hex)) +#### okexChainClient.sendCreateExchangeTransaction(Token0Name, Token1Name, memo, sequenceNumber) ⇒ Object +Send CreateExchangeTransaction. -**Kind**: static constant of [crypto](#module_crypto) -**Returns**: string - hash +**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) +**Returns**: Object - response -| Param | Type | -| --- | --- | -| hex | string | +| Param | Type | Default | +| --- | --- | --- | +| Token0Name | String | | +| Token1Name | String | | +| memo | String | | +| sequenceNumber | Number | | - + -### crypto.sha256 ⇒ string -SHA256. +#### okexChainClient.sendSwapTokenTransaction(sold_token_amount, sold_token, min_bought_token_amount, bought_token, deadline, recipient, memo, sequenceNumber) ⇒ Object +Send SwapTokenTransaction. -**Kind**: static constant of [crypto](#module_crypto) -**Returns**: string - hash +**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) +**Returns**: Object - response -| Param | Type | -| --- | --- | -| hex | string | +| Param | Type | Default | +| --- | --- | --- | +| sold_token_amount | Number | | +| sold_token | String | | +| min_bought_token_amount | Number | | +| bought_token | String | | +| deadline | String | | +| recipient | String | | +| memo | String | | +| sequenceNumber | Number | | - + -### crypto~isBN(object) ⇒ Boolean -Returns true if object is BN, otherwise false +#### okexChainClient.sendFarmCreatePoolTransaction(pool_name, min_lock_denom, min_lock_amount, yield_symbol, memo, sequenceNumber) ⇒ Object +Send FarmCreatePoolTransaction. -**Kind**: inner method of [crypto](#module_crypto) +**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) +**Returns**: Object - response -| Param | Type | -| --- | --- | -| object | Object | +| Param | Type | Default | +| --- | --- | --- | +| pool_name | String | | +| min_lock_denom | String | | +| min_lock_amount | Number | | +| yield_symbol | String | | +| memo | String | | +| sequenceNumber | Number | | - + -### crypto~isHexStrict(hex) ⇒ Boolean -Check if string is HEX, requires a 0x in front +#### okexChainClient.sendFarmDestroyPoolTransaction(pool_name, memo, sequenceNumber) ⇒ Object +Send FarmDestroyPoolTransaction. -**Kind**: inner method of [crypto](#module_crypto) +**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) +**Returns**: Object - response -| Param | Type | Description | +| Param | Type | Default | | --- | --- | --- | -| hex | String | to be checked | +| pool_name | String | | +| memo | String | | +| sequenceNumber | Number | | - + -### crypto~sha3() ⇒ String -Hashes values to a sha3 hash using keccak 256 +#### okexChainClient.sendFarmProvideTransaction(pool_name, provide_denom, provide_amount, yielded_per_block, start_height, memo, sequenceNumber) ⇒ Object +Send FarmProvideTransaction. -To hash a HEX string the hex must have 0x in front. +**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) +**Returns**: Object - response -**Kind**: inner method of [crypto](#module_crypto) -**Returns**: String - the sha3 string - +| Param | Type | Default | +| --- | --- | --- | +| pool_name | String | | +| provide_denom | String | | +| provide_amount | Number | | +| yielded_per_block | Number | | +| start_height | String | | +| memo | String | | +| sequenceNumber | Number | | -### crypto~toChecksumAddress(address) ⇒ String -Converts to a checksum address + -**Kind**: inner method of [crypto](#module_crypto) +#### okexChainClient.sendFarmLockTransaction(pool_name, lock_denom, lock_amount, memo, sequenceNumber) ⇒ Object +Send FarmLockTransaction. -| Param | Type | Description | +**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) +**Returns**: Object - response + +| Param | Type | Default | +| --- | --- | --- | +| pool_name | String | | +| lock_denom | String | | +| lock_amount | Number | | +| memo | String | | +| sequenceNumber | Number | | + + + +#### okexChainClient.sendFarmUnLockTransaction(pool_name, unlock_denom, unlock_amount, memo, sequenceNumber) ⇒ Object +Send FarmUnLockTransaction. + +**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) +**Returns**: Object - response + +| Param | Type | Default | +| --- | --- | --- | +| pool_name | String | | +| unlock_denom | String | | +| unlock_amount | Number | | +| memo | String | | +| sequenceNumber | Number | | + + + +#### okexChainClient.sendFarmClaimTransaction(pool_name, memo, sequenceNumber) ⇒ Object +Send FarmClaimTransaction. + +**Kind**: instance method of [OKEXChainClient](#module_client.OKEXChainClient) +**Returns**: Object - response + +| Param | Type | Default | | --- | --- | --- | -| address | String | the given HEX address | +| pool_name | String | | +| memo | String | | +| sequenceNumber | Number | | diff --git a/package.json b/package.json index eeedda5..0ab3e25 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "test": "cross-env NODE_ENV=test jest", "build": "rm -rf lib && npx babel src -d lib", - "build:docsclient": "npx jsdoc-to-markdown -f src/*.js > docs/okexchain-jssdk-doc-client.md", + "build:docsclient": "npx jsdoc-to-markdown -f src/client.js > docs/okexchain-jssdk-doc-client.md", "build:docscrypto": "npx jsdoc-to-markdown -f src/crypto/*.js > docs/okexchain-jssdk-doc-crypto.md", "prepublishOnly": "npm run build", "lint": "eslint --fix src __tests__", From bdc92900f47520b414bda99128b2ecba4461cb60 Mon Sep 17 00:00:00 2001 From: zhengchao Date: Mon, 8 Mar 2021 19:28:02 +0800 Subject: [PATCH 6/9] test cross domain --- __tests__/client.test.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/__tests__/client.test.js b/__tests__/client.test.js index 805232a..3ce5796 100644 --- a/__tests__/client.test.js +++ b/__tests__/client.test.js @@ -4,11 +4,14 @@ import * as crypto from "../src/crypto" const mnemonic = "total lottery arena when pudding best candy until army spoil drill pool" -const privateKey = "29892b64003fc5c8c89dc795a2ae82aa84353bb4352f28707c2ed32aa1011884" -const fromAddress = "okexchain1pt7xrmxul7sx54ml44lvv403r06clrdkgmvr9g" -const serverUrl = "http://localhost:8545" +const privateKey_996 = "29892b64003fc5c8c89dc795a2ae82aa84353bb4352f28707c2ed32aa1011884" +const privateKey = "828e61f969a7369f3340b07dd2080740d8445d7f802899ddacf9bc4db8608997" +const from_996 = "okexchain1pt7xrmxul7sx54ml44lvv403r06clrdkgmvr9g" +const from = "okexchain1ya7dn2rr8nx07tx9ksq8gvz5utvarrh03cen3l" +const serverUrl = "https://exchaintest.okexcn.com" +// const serverUrl = "https://exchaintest.okexcn.com" const userAddress = "okexchain1jjvpmgwwgs99nhlje3aag0lackunqgj7xnrnwe" -const chainId = "okexchain-1" // -testnet1 +const chainId = "okexchain-65" // -testnet1 const baseCoin = "okt" const testCoin = "xxb-781" const testProduct = testCoin + "_" + baseCoin @@ -21,11 +24,14 @@ describe("OKEXChainClient test", async () => { it("get balance", async () => { const client = new OKEXChainClient(serverUrl, { - chainId: chainId + chainId: chainId, + relativePath: "/okexchain-test/v1", + isMainnet: false }) - const privateKey = crypto.getPrivateKeyFromMnemonic(mnemonic) + const privateKey = crypto.getPrivateKeyFromMnemonic(mnemonic, '60') await client.setAccountInfo(privateKey) - const res = await client.getBalance(fromAddress) + const res = await client.getBalance(from) + console.log(res) expect(res.length).toBeGreaterThanOrEqual(0) }) From 9f3ea5bb0ad3974f6c4f12da46263483288e926d Mon Sep 17 00:00:00 2001 From: zhengchao Date: Tue, 9 Mar 2021 16:28:52 +0800 Subject: [PATCH 7/9] add qrcode module --- package.json | 1 + src/client.js | 20 +++++++++++++++++++- src/index.js | 5 ++++- src/transaction.js | 29 ++++++++++++++++++++++++++++- 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 0ab3e25..bf4b81a 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "sdk": "webpack-dev-server --config build/webpack.config.sdk.js" }, "dependencies": { + "@walletconnect/client": "1.3.3", "axios": "^0.18.0", "babel-polyfill": "^6.26.0", "base32-encode": "^1.1.0", diff --git a/src/client.js b/src/client.js index 92d8a97..3dbd421 100644 --- a/src/client.js +++ b/src/client.js @@ -7,6 +7,7 @@ import * as crypto from "./crypto" import Transaction from "./transaction" import HttpProxy from "./httpProxy" +import * as wallet from './wallet' const defaultChainId = "okexchain-66" const defaultRelativePath = "/okexchain/v1" @@ -107,6 +108,12 @@ export class OKEXChainClient { * @return {OKEXChainClient} */ async setAccountInfo(privateKey) { + if(!privateKey) { + const address = await wallet.getAddress(); + if (!address) throw new Error("invalid privateKey: " + privateKey) + await this.setAccountInfoByWallet(address); + return this; + } if (privateKey !== this.privateKey) { const address = crypto.getAddressFromPrivateKey(privateKey, bech32Head) if (!address) throw new Error("invalid privateKey: " + privateKey) @@ -119,6 +126,17 @@ export class OKEXChainClient { return this } + /** + * @return {OKEXChainClient} + */ + async setAccountInfoByWallet(address) { + if (!address) throw new Error("invalid wallet connect address: " + address); + if (address === this.address) return this + this.address = address + const data = await this.getAccount(address) + this.account_number = this.getAccountNumberFromAccountInfo(data) + return this + } /** * Send SendTransaction. @@ -283,7 +301,7 @@ export class OKEXChainClient { return await tx.sign(this.signer, signMsg, this.address); } else { - return tx.sign(this.privateKey, signMsg) + return this.privateKey ? tx.sign(this.privateKey, signMsg) : tx.signByWallet(signMsg) } } diff --git a/src/index.js b/src/index.js index 583b1ab..fa7c6df 100644 --- a/src/index.js +++ b/src/index.js @@ -1,8 +1,11 @@ import "babel-polyfill" import * as client from "./client" import * as crypto from "./crypto" +import * as wallet from "./wallet" const { OKEXChainClient } = client module.exports = OKEXChainClient -module.exports.crypto = crypto +module.exports.crypto = crypto; +module.exports.wallet = wallet; + diff --git a/src/transaction.js b/src/transaction.js index 3081ed2..799acf1 100644 --- a/src/transaction.js +++ b/src/transaction.js @@ -1,5 +1,5 @@ import * as crypto from "./crypto/" - +import * as wallet from "./wallet" /** * Transaction @@ -67,6 +67,33 @@ class Transaction { return this } + /** + * @param {Object} msg + * @return {Transaction} + **/ + async signByWallet(msg) { + + const signMsg = { + to: '', + symbol: 'OKT', + memo: this.memo, + // contractAddress:'', + decimalNum: '0', + accountNumber:this.account_number.toString(), + sequenceNumber:this.sequence.toString(), + value: '0', + gasLimit: this.fee.gas, + gasPrice: this.fee.amount[0].amount, + data: JSON.stringify(msg) + } + + console.log("signmsg: ",JSON.stringify(signMsg)) + + this.signatures = await wallet.sign(signMsg); + + return this + } + /** * @param {string} mode * @return {Object} From 7e99d1e6c50798fa542e1d72ef096417aca87008 Mon Sep 17 00:00:00 2001 From: zhengchao Date: Tue, 9 Mar 2021 16:32:52 +0800 Subject: [PATCH 8/9] add qrcode module --- package-lock.json | 183 ++++++++++++++++++++++++++++++++++ package.json | 2 +- src/wallet/connector.js | 210 ++++++++++++++++++++++++++++++++++++++++ src/wallet/index.js | 29 ++++++ 4 files changed, 423 insertions(+), 1 deletion(-) create mode 100644 src/wallet/connector.js create mode 100644 src/wallet/index.js diff --git a/package-lock.json b/package-lock.json index 3ff539a..a765b9a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -774,6 +774,22 @@ "to-fast-properties": "^2.0.0" } }, + "@json-rpc-tools/types": { + "version": "1.6.4", + "resolved": "https://registry.npmjs.org/@json-rpc-tools/types/-/types-1.6.4.tgz", + "integrity": "sha512-DHtnvlIFN8YUun38Sy9SaRdV/BsUMFM5bAABDsb/iPGLfPHOMKoAyuPOwEqQ2vgtc9ayTcQ2546OPTQ92IzJ/g==", + "requires": { + "keyvaluestorage-interface": "^1.0.0" + } + }, + "@json-rpc-tools/utils": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/@json-rpc-tools/utils/-/utils-1.6.1.tgz", + "integrity": "sha512-cNwP4QapAls+xATU8zLLqPYa9qCbgwEyWEK7vE1oH91b3LfbUYwHtiWZ1+rv0X/mh/9cWNTo2Oi2Sah/QX0WwA==", + "requires": { + "@json-rpc-tools/types": "^1.6.1" + } + }, "@json-schema-spec/json-pointer": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/@json-schema-spec/json-pointer/-/json-pointer-0.1.2.tgz", @@ -792,6 +808,26 @@ "uri-js": "^4.2.2" } }, + "@pedrouid/iso-crypto": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@pedrouid/iso-crypto/-/iso-crypto-1.1.0.tgz", + "integrity": "sha512-twi+tW67XT0BSOv4rsegnGo4TQMhfFswS/GY3KhrjFiNw3z9x+cMkfO+itNe1JZghQxsxHuhifvfsnG814g1hQ==", + "requires": { + "@pedrouid/iso-random": "^1.1.0", + "aes-js": "^3.1.2", + "enc-utils": "^3.0.0", + "hash.js": "^1.1.7" + } + }, + "@pedrouid/iso-random": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@pedrouid/iso-random/-/iso-random-1.1.0.tgz", + "integrity": "sha512-U8P2qdbvyU5aom0036dkpp0C9c8pgW1SNhAo8+zPDzgmKA58Hl6dc+ZkQXkE9aHrzN6v/0w+409JMjSYwx5tVw==", + "requires": { + "enc-utils": "^3.0.0", + "randombytes": "^2.1.0" + } + }, "@types/deep-equal": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@types/deep-equal/-/deep-equal-1.0.1.tgz", @@ -804,6 +840,93 @@ "integrity": "sha512-f5j5b/Gf71L+dbqxIpQ4Z2WlmI/mPJ0fOkGGmFgtb6sAu97EPczzbS3/tJKxmcYDj55OX6ssqwDAWOHIYDRDGA==", "dev": true }, + "@walletconnect/client": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/@walletconnect/client/-/client-1.3.3.tgz", + "integrity": "sha512-aHwsX2lvdEhb2OutHr0cKKRNMOAhaE/Xejbk6stbUozeh0MKAWwhVW5g16xd+wX07Mictq4JFQrg3dSsabRJlg==", + "requires": { + "@walletconnect/core": "^1.3.3", + "@walletconnect/iso-crypto": "^1.3.3", + "@walletconnect/types": "^1.3.3", + "@walletconnect/utils": "^1.3.3" + } + }, + "@walletconnect/core": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/@walletconnect/core/-/core-1.3.6.tgz", + "integrity": "sha512-1HHP2xZI6b88WQgszs3gP5xkkCwwlWgDJz+J6ADGzVXhQP21p1mZhKezUtx27rOtQimMIrPDfgPyAHwQBZkkSw==", + "requires": { + "@walletconnect/socket-transport": "^1.3.6", + "@walletconnect/types": "^1.3.6", + "@walletconnect/utils": "^1.3.6" + } + }, + "@walletconnect/iso-crypto": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/@walletconnect/iso-crypto/-/iso-crypto-1.3.6.tgz", + "integrity": "sha512-HypXNSmMAuEvNhllXWsCHtCVK4JfFFcZqPijurcXmOtWanjZV+8NuiYnKG11qAllSbYRwqKchb7GTDp33n0g0Q==", + "requires": { + "@pedrouid/iso-crypto": "^1.0.0", + "@walletconnect/types": "^1.3.6", + "@walletconnect/utils": "^1.3.6" + } + }, + "@walletconnect/socket-transport": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/@walletconnect/socket-transport/-/socket-transport-1.3.6.tgz", + "integrity": "sha512-dvO8mRECU4I6FpoQX9GMh9BNzR2/g6vcj9LEIjgApW6Rfx0mCKUgoVBSi2W7NHC94zfdYiJdaH950oismj5gNw==", + "requires": { + "@walletconnect/types": "^1.3.6", + "@walletconnect/utils": "^1.3.6", + "ws": "7.3.0" + }, + "dependencies": { + "ws": { + "version": "7.3.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.3.0.tgz", + "integrity": "sha512-iFtXzngZVXPGgpTlP1rBqsUK82p9tKqsWRPg5L56egiljujJT3vGAYnHANvFxBieXrTFavhzhxW52jnaWV+w2w==" + } + } + }, + "@walletconnect/types": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/@walletconnect/types/-/types-1.3.6.tgz", + "integrity": "sha512-fNir3Pi1ZpuVlgNr8qtP2LOSsV9rNgJGHmBnHHqKNmpuRpPxG1mhmKFdDHNGyVIP5bM5CWIXmlULDTax63UJbg==" + }, + "@walletconnect/utils": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/@walletconnect/utils/-/utils-1.3.6.tgz", + "integrity": "sha512-nzTO5A3Ltjrsu6u8SR/KqdHTH03848KIj5MQlOCUjwxW1fXOvuri8+kwFKqlMn0bk1Qvlt6rrOptbt14PW8kSA==", + "requires": { + "@json-rpc-tools/utils": "1.6.1", + "@walletconnect/types": "^1.3.6", + "bn.js": "4.11.8", + "detect-browser": "5.1.0", + "enc-utils": "3.0.0", + "js-sha3": "0.8.0", + "query-string": "6.13.5", + "safe-json-utils": "1.0.0", + "window-getters": "1.0.0", + "window-metadata": "1.0.0" + }, + "dependencies": { + "query-string": { + "version": "6.13.5", + "resolved": "https://registry.npmjs.org/query-string/-/query-string-6.13.5.tgz", + "integrity": "sha512-svk3xg9qHR39P3JlHuD7g3nRnyay5mHbrPctEBDUxUkHRifPHXJDhBUycdCC0NBjXoDf44Gb+IsOZL1Uwn8M/Q==", + "requires": { + "decode-uri-component": "^0.2.0", + "split-on-first": "^1.0.0", + "strict-uri-encode": "^2.0.0" + } + }, + "strict-uri-encode": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz", + "integrity": "sha1-ucczDHBChi9rFC3CdLvMWGbONUY=" + } + } + }, "JSONStream": { "version": "1.3.5", "resolved": "http://registry.npm.taobao.org/JSONStream/download/JSONStream-1.3.5.tgz", @@ -890,6 +1013,11 @@ "integrity": "sha1-02O2b1+sXwGP+cOh57b44xDMORM=", "dev": true }, + "aes-js": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/aes-js/-/aes-js-3.1.2.tgz", + "integrity": "sha512-e5pEa2kBnBOgR4Y/p20pskXI74UEz7de8ZGVo58asOtvSVG5YAbJeELPZxOmt+Bnz3rX753YKhfIn4X4l1PPRQ==" + }, "ajv": { "version": "6.10.0", "resolved": "http://registry.npm.taobao.org/ajv/download/ajv-6.10.0.tgz", @@ -3026,6 +3154,11 @@ "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" }, + "detect-browser": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/detect-browser/-/detect-browser-5.1.0.tgz", + "integrity": "sha512-WKa9p+/MNwmTiS+V2AS6eGxic+807qvnV3hC+4z2GTY+F42h1n8AynVTMMc4EJBC32qMs6yjOTpeDEQQt/AVqQ==" + }, "detect-indent": { "version": "4.0.0", "resolved": "http://registry.npm.taobao.org/detect-indent/download/detect-indent-4.0.0.tgz", @@ -3189,6 +3322,15 @@ "integrity": "sha1-kzoEBShgyF6DwSJHnEdIqOTHIVY=", "dev": true }, + "enc-utils": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/enc-utils/-/enc-utils-3.0.0.tgz", + "integrity": "sha512-e57t/Z2HzWOLwOp7DZcV0VMEY8t7ptWwsxyp6kM2b2zrk6JqIpXxzkruHAMiBsy5wg9jp/183GdiRXCvBtzsYg==", + "requires": { + "is-typedarray": "1.0.0", + "typedarray-to-buffer": "3.1.5" + } + }, "encodeurl": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", @@ -6780,6 +6922,11 @@ "integrity": "sha1-+IxgjjJKM3OpW8xFrTBeXJecRZs=", "dev": true }, + "js-sha3": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.8.0.tgz", + "integrity": "sha512-gF1cRrHhIzNfToc802P800N8PpXS+evLLXfsVpowqmAFR9uwbi89WvXg2QspOmXL8QL86J4T1EpFu+yUkwJY3Q==" + }, "js-tokens": { "version": "4.0.0", "resolved": "http://registry.npm.taobao.org/js-tokens/download/js-tokens-4.0.0.tgz", @@ -7015,6 +7162,11 @@ "node-gyp-build": "^4.2.0" } }, + "keyvaluestorage-interface": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/keyvaluestorage-interface/-/keyvaluestorage-interface-1.0.0.tgz", + "integrity": "sha512-8t6Q3TclQ4uZynJY9IGr2+SsIGwK9JHcO6ootkHCGA0CrQCRy+VkouYNO2xicET6b9al7QKzpebNow+gkpCL8g==" + }, "kind-of": { "version": "6.0.2", "resolved": "http://registry.npm.taobao.org/kind-of/download/kind-of-6.0.2.tgz", @@ -8808,6 +8960,11 @@ "resolved": "http://registry.npm.taobao.org/safe-buffer/download/safe-buffer-5.1.2.tgz", "integrity": "sha1-mR7GnSluAxN0fVm9/St0XDX4go0=" }, + "safe-json-utils": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/safe-json-utils/-/safe-json-utils-1.0.0.tgz", + "integrity": "sha512-n0hJm6BgX8wk3G+AS8MOQnfcA8dfE6ZMUfwkHUNx69YxPlU3HDaZTHXWto35Z+C4mOjK1odlT95WutkGC+0Idw==" + }, "safe-regex": { "version": "1.1.0", "resolved": "http://registry.npm.taobao.org/safe-regex/download/safe-regex-1.1.0.tgz", @@ -9309,6 +9466,11 @@ "integrity": "sha1-dezRqI3owYTvAV6vtRtbSL/RG7E=", "dev": true }, + "split-on-first": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/split-on-first/-/split-on-first-1.1.0.tgz", + "integrity": "sha512-43ZssAJaMusuKWL8sKUBQXHWOpq8d6CfN/u1p4gUzfJkM05C8rxTmYrkIPTXapZpORA6LkkzcUulJ8FqA7Uudw==" + }, "split-string": { "version": "3.1.0", "resolved": "http://registry.npm.taobao.org/split-string/download/split-string-3.1.0.tgz", @@ -10006,6 +10168,14 @@ "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", "dev": true }, + "typedarray-to-buffer": { + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz", + "integrity": "sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==", + "requires": { + "is-typedarray": "^1.0.0" + } + }, "typeforce": { "version": "1.18.0", "resolved": "http://registry.npm.taobao.org/typeforce/download/typeforce-1.18.0.tgz", @@ -10454,6 +10624,19 @@ "bs58check": "<3.0.0" } }, + "window-getters": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/window-getters/-/window-getters-1.0.0.tgz", + "integrity": "sha512-xyvEFq3x+7dCA7NFhqOmTMk0fPmmAzCUYL2svkw2LGBaXXQLRP0lFnfXHzysri9WZNMkzp/FD1u0w2Qc7Co+JA==" + }, + "window-metadata": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/window-metadata/-/window-metadata-1.0.0.tgz", + "integrity": "sha512-eYoXsZ9X4J+6xZgbHhNAatSR5bCtT409q8B+2Ol9ySx7qsdtgVZcNfox4qszFmKlGsFtT2b1Tcmcy69bRMObcg==", + "requires": { + "window-getters": "^1.0.0" + } + }, "wordwrap": { "version": "1.0.0", "resolved": "http://registry.npm.taobao.org/wordwrap/download/wordwrap-1.0.0.tgz", diff --git a/package.json b/package.json index bf4b81a..fc2627f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@okexchain/javascript-sdk", - "version": "0.0.31", + "version": "0.0.32", "license": "Apache-2.0", "main": "lib/index.js", "scripts": { diff --git a/src/wallet/connector.js b/src/wallet/connector.js new file mode 100644 index 0000000..04acc20 --- /dev/null +++ b/src/wallet/connector.js @@ -0,0 +1,210 @@ +import WalletConnect from '@walletconnect/client'; + +const GET_ACCOUNTS = { + jsonrpc: '2.0', + method: 'get_accounts' +}; + +const GET_SIGN = { + jsonrpc: '2.0', + method: 'okt_signTransaction' +}; + +const OKEXCHAIN = 'okexchain'; + +// const DURING = 5000; + +class Connector { + + constructor() { + this.resetConnector(); + } + + resetConnector() { + if(this.interval) clearInterval(this.interval); + this.walletConnector = null; + this.account = null; + this.address = ''; + this.interval = null; + this.callback = {}; + } + + handleConnect(accounts) { + this.account = accounts[0]; + } + + async onConnect(payload) { + try { + await this.getAccounts(); + const { accounts } = payload.params[0]; + this.handleConnect(accounts); + if(!this.address) throw new Error; + this.doCallback('success',{address: this.address}); + } catch { + this.doCallback('error'); + } + } + + onDisconnect() { + this.killSession(); + } + + async getAccounts() { + const walletConnector = this.walletConnector; + if(!walletConnector) return ''; + // this.startTimer(); + return new Promise((resolve,reject) => { + let address = ''; + // let timer = setTimeout(() => { + // if(!address) { + // console.log('获取address超时,将断开链接'); + // this.killSession(); + // } + // }, DURING); + const params = {...GET_ACCOUNTS, id: Date.now()}; + console.log('get address params: ' + JSON.stringify(params)); + walletConnector.sendCustomRequest(params).then((res) => { + const okexchainAccount = res.find((account) => { + return account.address.startsWith(OKEXCHAIN); + }); + if (okexchainAccount) { + address = okexchainAccount.address; + this.address = address; + } + if(!address) throw new Error('get address failed'); + resolve(this.address); + }).catch(err => { + // console.log('获取address失败,将断开链接'); + // this.killSession(); + reject(err); + }).finally(() => { + // clearTimeout(timer); + }); + }); + } + + async startTimer() { + if(this.startTimer.interval) return; + this.startTimer.interval = setInterval(() => { + console.log('get address'); + this.getAccounts(); + }, DURING); + } + + async subscribeToEvents() { + const walletConnector = this.walletConnector; + if (!walletConnector) { + return; + } + walletConnector.on('call_request', (error, payload) => { + console.log('call_request', payload, error); + if (error) { + throw error; + } + }); + + walletConnector.on('connect', (error, payload) => { + console.log('connect', payload); + if (error) { + throw error; + } + this.onConnect(payload); + }); + + walletConnector.on('disconnect', (error, payload) => { + console.log('disconnect', payload); + this.onDisconnect(); + if (error) { + throw error; + } + }); + + walletConnector.on('session_request',(error, payload) => { + console.log('session_request', payload); + if (error) { + throw error; + } + }); + + if (walletConnector.connected) { + const { accounts } = walletConnector; + this.handleConnect(accounts); + } + } + + async createSession() { + const walletConnector = this.walletConnector; + if(!walletConnector) return; + await walletConnector.createSession(); + } + + async walletConnectInit() { + const bridge = 'wss://bridge.walletconnect.org'; + const walletConnector = new WalletConnect({ bridge }); + walletConnector._clientMeta.name = 'ΟKEx DEX'; + walletConnector._clientMeta.url = walletConnector._clientMeta.url.replace(/okex/i,'οkex'); + this.walletConnector = walletConnector; + + this.subscribeToEvents(); + + if (!walletConnector.connected || !walletConnector.uri) { + console.log('create session'); + await this.createSession(); + } else { + await this.getAccounts(); + } + } + + killSession(callback) { + const walletConnector = this.walletConnector; + if (walletConnector && walletConnector.connected) { + walletConnector.killSession(); + } + if(callback) callback(); + else this.doCallback('sessionCancel'); + this.resetConnector(); + } + + setCallback(callback={}) { + this.callback = callback; + } + + doCallback(type,params) { + if(typeof this.callback[type] === 'function' )this.callback[type](params); + } + + async getSession(callback) { + this.setCallback(callback); + let session = ''; + try { + if(!this.walletConnector || !this.walletConnector.uri) { + await this.walletConnectInit(); + } + session = this.walletConnector.uri; + } finally { + if(!session) { + console.log('初始链接失败') + this.killSession(); + } + else this.doCallback('sessionSuccess'); + } + return session; + } + + async sign(signMsg) { + return new Promise((resolve,reject) => { + const params = {...GET_SIGN,params:[signMsg],id:Date.now()}; + console.log('发送签名数据',JSON.stringify(params)); + this.walletConnector.sendCustomRequest(params).then((res) => { + res = JSON.parse(res); + console.log(res); + resolve(res.tx.signatures); + }).catch(err => { + console.log('签名失败') + reject(err); + }); + }); + } +} + +export default new Connector(); diff --git a/src/wallet/index.js b/src/wallet/index.js new file mode 100644 index 0000000..22390f4 --- /dev/null +++ b/src/wallet/index.js @@ -0,0 +1,29 @@ +import connector from './connector'; + +/** + * {sessionSuccess,sessionFail,sessionCancel,success,error} + * @param {*} callbacks + */ +export function getSession(callback={}) { + return connector.getSession(callback); +} + +export function killSession() { + return connector.killSession(); +} + +export async function getAddress() { + let address = connector.address; + try { + if(!address) address = await connector.getAccounts(); + } catch { + console.log('get address fail'); + } + return address; +} + +export function sign(signMsg) { + return connector.sign(signMsg); +} + + From 9a303cf8adb6edf0f16fa25e3971cbacc4b8a69b Mon Sep 17 00:00:00 2001 From: zhengchao Date: Wed, 10 Mar 2021 15:45:25 +0800 Subject: [PATCH 9/9] add okexchain 0x address convert --- docs/okexchain-jssdk-doc-crypto.md | 24 ++++++++++++++++++++++++ src/crypto/index.js | 12 +++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/docs/okexchain-jssdk-doc-crypto.md b/docs/okexchain-jssdk-doc-crypto.md index c9e0609..6c73db4 100644 --- a/docs/okexchain-jssdk-doc-crypto.md +++ b/docs/okexchain-jssdk-doc-crypto.md @@ -8,6 +8,8 @@ * [.decodeAddressToBuffer](#module_crypto.decodeAddressToBuffer) * [.validateAddress](#module_crypto.validateAddress) ⇒ boolean * [.encodeAddressToBech32](#module_crypto.encodeAddressToBech32) ⇒ string + * [.convertBech32ToHex](#module_crypto.convertBech32ToHex) ⇒ String + * [.convertHexToBech32](#module_crypto.convertHexToBech32) ⇒ string * [.generatePrivateKey](#module_crypto.generatePrivateKey) ⇒ string * [.getPubKeyFromHex](#module_crypto.getPubKeyFromHex) ⇒ Elliptic.PublicKey * [.encodePubKeyToCompressedBuffer](#module_crypto.encodePubKeyToCompressedBuffer) ⇒ Buffer @@ -76,6 +78,28 @@ Encodes address from hex to bech32 format. | hexAddr | string | address in hex string | | prefix | string | address prefix | + + +### crypto.convertBech32ToHex ⇒ String +covert okexchain address to 0x address + +**Kind**: static constant of [crypto](#module_crypto) + +| Param | +| --- | +| bech32Address | + + + +### crypto.convertHexToBech32 ⇒ string +covert 0x address to okexchain address + +**Kind**: static constant of [crypto](#module_crypto) + +| Param | +| --- | +| hexAddress | + ### crypto.generatePrivateKey ⇒ string diff --git a/src/crypto/index.js b/src/crypto/index.js index b758fdb..4d0337f 100644 --- a/src/crypto/index.js +++ b/src/crypto/index.js @@ -77,11 +77,21 @@ export const encodeAddressToBech32 = (hexAddr, prefix = "okexchain") => { function buf2hex(buffer) { // buffer is an ArrayBuffer return Array.prototype.map.call(new Uint8Array(buffer), x => ('00' + x.toString(16)).slice(-2)).join(''); } + +/** + * covert okexchain address to 0x address + * @param bech32Address + * @returns {String} + */ export const convertBech32ToHex = (bech32Address) => { const address = decodeAddressToBuffer(bech32Address) return toChecksumAddress("0x"+buf2hex(address)) } - +/** + * covert 0x address to okexchain address + * @param hexAddress + * @returns {string} + */ export const convertHexToBech32 = (hexAddress) => { return encodeAddressToBech32(hexAddress.toLowerCase()) }