From 151f2241ca15e95b5a7b3ab0a72f4ba04512cadc Mon Sep 17 00:00:00 2001 From: KimlikDAO-bot Date: Mon, 8 Jan 2024 17:19:32 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=81=F0=9F=8F=BD=E2=80=8D=E2=99=82?= =?UTF-8?q?=EF=B8=8F=20Ethereum=20provider.js=20ekle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/oauth2.d.js | 1 + cloudflare/test/pageWorker.compiled-test.js | 4 +-- crypto/secp256k1.js | 2 +- ethereum/TCKTLite.js | 28 +++++------------- ethereum/provider.js | 32 +++++++++++++++++++++ 5 files changed, 43 insertions(+), 24 deletions(-) create mode 100644 ethereum/provider.js diff --git a/api/oauth2.d.js b/api/oauth2.d.js index 996cc9a..6bb7a3a 100644 --- a/api/oauth2.d.js +++ b/api/oauth2.d.js @@ -24,6 +24,7 @@ oauth2.AccessToken; * code: string, * client_id: string, * client_secret: string, + * redirect_uri: (string | undefined) * }} */ oauth2.AccessTokenRequest; diff --git a/cloudflare/test/pageWorker.compiled-test.js b/cloudflare/test/pageWorker.compiled-test.js index 179c777..7fc38ad 100644 --- a/cloudflare/test/pageWorker.compiled-test.js +++ b/cloudflare/test/pageWorker.compiled-test.js @@ -99,8 +99,8 @@ const PageWorker = create("https://kimlikdao.org/", { "?en": "ana-en.html", "al": "al-tr.html", "mint": "al-en.html", - "incele": "incele-tr.html", - "view": "incele-en.html", + "tcktm": "tcktm-tr.html", + "my-tckt": "tcktm-en.html", "oyla": "oyla-tr.html", "vote": "oyla-en.html", "iptal": "iptal-tr.html", diff --git a/crypto/secp256k1.js b/crypto/secp256k1.js index 4dc0943..b8d002d 100644 --- a/crypto/secp256k1.js +++ b/crypto/secp256k1.js @@ -23,7 +23,7 @@ const P = (1n << 256n) - (1n << 32n) - 977n; * @const {!bigint} * @noinline */ -const N = (1n << 256n) - BigInt("0x14551231950b75fc4402da1732fc9bebf"); +const N = P - BigInt("0x14551231950b75fc4402da1722fc9baee"); /** * Unlike the % operation, modP always returns a positive number y such that diff --git a/ethereum/TCKTLite.js b/ethereum/TCKTLite.js index 395ec04..1f56c4c 100644 --- a/ethereum/TCKTLite.js +++ b/ethereum/TCKTLite.js @@ -1,36 +1,22 @@ +import { address, callMethod, isNonzero } from "/lib/ethereum/provider"; + /** @const {string} */ const TCKT_ADDR = "0xcCc0a9b023177549fcf26c947edb5bfD9B230cCc"; /** * @param {!eth.Provider} provider - * @param {string} contract Contract adddress given with the 0x prefix - * @param {string} calldata Calldata transmitted to the contract verbatim. - * @return {!Promise} - */ -const callMethod = (provider, contract, calldata) => - provider.request(/** @type {!eth.Request} */({ - method: "eth_call", - params: [/** @type {!eth.Transaction} */({ - to: contract, - data: calldata - }), "latest"] - })) - -/** - * @param {!eth.Provider} provider - * @param {string} address + * @param {string} addr * @return {!Promise} */ -const handleOf = (provider, address) => - callMethod(provider, TCKT_ADDR, "0xc50a1514" + "0".repeat(24) + address.slice(2).toLowerCase()); +const handleOf = (provider, addr) => + callMethod(provider, TCKT_ADDR, "0xc50a1514" + address(addr)); /** * @param {!eth.Provider} provider - * @param {string} address + * @param {string} addr * @return {!Promise} */ -const hasDID = (provider, address) => - handleOf(provider, address).then((hexCid) => hexCid.replaceAll("0", "") != "x"); +const hasDID = (provider, addr) => handleOf(provider, addr).then(isNonzero); export { TCKT_ADDR }; diff --git a/ethereum/provider.js b/ethereum/provider.js new file mode 100644 index 0000000..1384d37 --- /dev/null +++ b/ethereum/provider.js @@ -0,0 +1,32 @@ +/** + * @param {!eth.Provider} provider + * @param {string} contract Contract adddress given with the 0x prefix + * @param {string} calldata Calldata transmitted to the contract verbatim. + * @return {!Promise} + */ +const callMethod = (provider, contract, calldata) => + provider.request(/** @type {!eth.Request} */({ + method: "eth_call", + params: [/** @type {!eth.Transaction} */({ + to: contract, + data: calldata + }), "latest"] + })); + +/** + * @param {string} address starting with 0x + * @return {string} length 64 string, padded for calldata + */ +const address = (address) => "0".repeat(24) + address.slice(2); + +/** + * @param {string} value + * @return {boolean} + */ +const isNonzero = (value) => value.replaceAll("0", "") != 'x'; + +export { + address, + callMethod, + isNonzero, +};