Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #554 from klaytn/dev
Browse files Browse the repository at this point in the history
version up to 0.9.8-beta
  • Loading branch information
jack authored Dec 5, 2023
2 parents 008517e + 39776c6 commit 4e36d0b
Show file tree
Hide file tree
Showing 146 changed files with 4,335 additions and 5,963 deletions.
4 changes: 4 additions & 0 deletions ethers-ext/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ module.exports = {
],
"newlines-between": "always",
}],
"import/no-unresolved": [
"error", // eslint-plugin-import cannot resolve subpaths https://github.com/firebase/firebase-admin-node/discussions/1359
{ ignore: ["^@klaytn/js-ext-core/util$"] }
],

// formatting
"curly": ["warn", "all"],
Expand Down
10 changes: 2 additions & 8 deletions ethers-ext/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ npm install --save @klaytn/ethers-ext

## Usage

See examples.
See [example](./example) and [test](./test).


## Build

Expand All @@ -26,13 +27,6 @@ See examples.
npm install
```
- (optional) Import @klaytn/web3rpc from local file.
Use this method to use the latest version of the web3rpc.
```
npm link ../web3rpc/sdk/client/javascript/openapi
```
- Build the library
```
Expand Down
9 changes: 9 additions & 0 deletions ethers-ext/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# ethers-ext examples

- [accountKey](./accountKey) Klaytn AccountKey types
- [accountStore](./accountStore) AccountStore usage
- [rpc](./rpc) Klaytn node RPC wrappers
- [smartContract](./smartContract) Smart contract usage
- [transactions](./transactions) Klaytn transaction types
- [util](./util) Utility functions

47 changes: 47 additions & 0 deletions ethers-ext/example/accountKey/AccountKeyLegacy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// AccountKeyLegacy
// https://docs.klaytn.foundation/content/klaytn/design/accounts#accountkeylegacy

const { sign } = require("crypto");

const { Wallet } = require("@klaytn/ethers-ext");
const { ethers } = require("ethers");

const senderAddr = "0xa2a8854b1802d8cd5de631e690817c253d6a9153";
const senderPriv = "0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8";
const recieverAddr = "0xc40b6909eb7085590e1c26cb3becc25368e249e9";

const provider = new ethers.providers.JsonRpcProvider("https://public-en-baobab.klaytn.net");
const wallet = new Wallet(senderPriv, provider);

async function sendTx() {
let tx = {
from: senderAddr,
to: recieverAddr,
value: 0,
};

let sentTx = await wallet.sendTransaction(tx);
console.log("sentTx", sentTx);

let rc = await sentTx.wait();
console.log("receipt", rc);
}

async function verifyMsg() {
const msg = "hello";
const msghex = ethers.utils.hexlify(ethers.utils.toUtf8Bytes(msg));
const sig = await wallet.signMessage(msg);
console.log({ senderAddr, msg, msghex, sig });

const addr1 = ethers.utils.verifyMessage(msg, sig);
console.log("recoveredAddr lib", addr1, addr1.toLowerCase() === senderAddr);

const addr2 = await provider.send("klay_recoverFromMessage", [senderAddr, msghex, sig, "latest"]);
console.log("recoveredAddr rpc", addr2, addr2.toLowerCase() === senderAddr);
}

async function main() {
await sendTx();
await verifyMsg();
}
main().catch(console.error);
30 changes: 0 additions & 30 deletions ethers-ext/example/accountKey/AccountKeyLegacy_01_ValueTransfer.js

This file was deleted.

38 changes: 0 additions & 38 deletions ethers-ext/example/accountKey/AccountKeyLegacy_02_ValueTransfer.js

This file was deleted.

33 changes: 0 additions & 33 deletions ethers-ext/example/accountKey/AccountKeyLegacy_03_signVerify.js

This file was deleted.

68 changes: 68 additions & 0 deletions ethers-ext/example/accountKey/AccountKeyPublic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// AccountKeyPublic
// https://docs.klaytn.foundation/content/klaytn/design/accounts#accountkeypublic

const { Wallet, TxType, AccountKeyType, parseKlay } = require("@klaytn/ethers-ext");
const { ethers } = require("ethers");

const senderAddr = "0xe15cd70a41dfb05e7214004d7d054801b2a2f06b";
const senderPriv = "0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8";
const senderNewPriv = "0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8";
const recieverAddr = "0xc40b6909eb7085590e1c26cb3becc25368e249e9";

const provider = new ethers.providers.JsonRpcProvider("https://public-en-baobab.klaytn.net");
const wallet = new Wallet(senderAddr, senderPriv, provider);
const wallet2 = new Wallet(senderAddr, senderNewPriv, provider);

async function updateAccount() {
let senderNewPub = new ethers.utils.SigningKey(senderNewPriv).compressedPublicKey;

let tx = {
type: TxType.AccountUpdate,
from: senderAddr,
key: {
type: AccountKeyType.Public,
key: senderNewPub,
}
};

let sentTx = await wallet.sendTransaction(tx);
console.log("updateAccount", sentTx);

let rc = await sentTx.wait();
console.log("receipt", rc);
}

async function sendTx() {
let tx = {
type: TxType.ValueTransfer,
from: senderAddr,
to: recieverAddr,
value: parseKlay("0.01"),
};

let sentTx = await wallet2.sendTransaction(tx);
console.log("sentTx", sentTx);

let rc = await sentTx.wait();
console.log("receipt", rc);
}

async function recoverMsg() {
const msg = "hello";
const msghex = ethers.utils.hexlify(ethers.utils.toUtf8Bytes(msg));
const sig = await wallet2.signMessage(msg);
console.log({ senderAddr, msg, msghex, sig });

const addr1 = ethers.utils.verifyMessage(msg, sig);
console.log("recoveredAddr lib", addr1, addr1.toLowerCase() === wallet2.address.toLowerCase());

const addr2 = await provider.send("klay_recoverFromMessage", [senderAddr, msghex, sig, "latest"]);
console.log("recoveredAddr rpc", addr2, addr2.toLowerCase() === wallet2.address.toLowerCase());
}

async function main() {
await updateAccount();
await sendTx();
await recoverMsg();
}
main().catch(console.error);
37 changes: 0 additions & 37 deletions ethers-ext/example/accountKey/AccountKeyPublic_01_accountUpdate.js

This file was deleted.

32 changes: 0 additions & 32 deletions ethers-ext/example/accountKey/AccountKeyPublic_02_valueTransfer.js

This file was deleted.

39 changes: 0 additions & 39 deletions ethers-ext/example/accountKey/AccountKeyPublic_03_valueTransfer.js

This file was deleted.

Loading

0 comments on commit 4e36d0b

Please sign in to comment.