Skip to content

Commit

Permalink
πŸ’πŸ½β€β™‚οΈ Ethereum provider.js ekle
Browse files Browse the repository at this point in the history
  • Loading branch information
KimlikDAO-bot committed Jan 8, 2024
1 parent 0b070b8 commit 151f224
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 24 deletions.
1 change: 1 addition & 0 deletions api/oauth2.d.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ oauth2.AccessToken;
* code: string,
* client_id: string,
* client_secret: string,
* redirect_uri: (string | undefined)
* }}
*/
oauth2.AccessTokenRequest;
4 changes: 2 additions & 2 deletions cloudflare/test/pageWorker.compiled-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion crypto/secp256k1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 7 additions & 21 deletions ethereum/TCKTLite.js
Original file line number Diff line number Diff line change
@@ -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<string>}
*/
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<string>}
*/
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<boolean>}
*/
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 };

Expand Down
32 changes: 32 additions & 0 deletions ethereum/provider.js
Original file line number Diff line number Diff line change
@@ -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<string>}
*/
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,
};

0 comments on commit 151f224

Please sign in to comment.