Skip to content

Commit

Permalink
Release 0.13.3.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Jan 19, 2025
1 parent bcb2407 commit e03df52
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ _Check out all web3 utility libraries:_ [ETH](https://github.com/paulmillr/micro

## Usage

> npm install micro-eth-signer
> `npm install micro-eth-signer`
> `jsr add jsr:@paulmillr/micro-eth-signer`
We support all major platforms and runtimes.
For [Deno](https://deno.land), ensure to use [npm specifier](https://deno.land/[email protected]/node/npm_specifiers).
For React Native, you may need a [polyfill for getRandomValues](https://github.com/LinusU/react-native-get-random-values).
If you don't like NPM, a standalone [eth-signer.js](https://github.com/paulmillr/micro-eth-signer/releases) is also available.

Expand Down Expand Up @@ -103,17 +104,17 @@ There are two messaging standards: [EIP-191](https://eips.ethereum.org/EIPS/eip-
import * as typed from 'micro-eth-signer/typed-data';

// Example message
const message = "Hello, Ethereum!";
const privateKey = "0x4c0883a69102937d6231471b5dbb6204fe512961708279f1d7b1b8e7e8b1b1e1";
const message = 'Hello, Ethereum!';
const privateKey = '0x4c0883a69102937d6231471b5dbb6204fe512961708279f1d7b1b8e7e8b1b1e1';

// Sign the message
const signature = typed.personal.sign(message, privateKey);
console.log("Signature:", signature);
console.log('Signature:', signature);

// Verify the signature
const address = "0xYourEthereumAddress";
const address = '0xYourEthereumAddress';
const isValid = typed.personal.verify(signature, message, address);
console.log("Is valid:", isValid);
console.log('Is valid:', isValid);
```

#### EIP-712
Expand All @@ -124,13 +125,13 @@ import * as typed from 'micro-eth-signer/typed-data';
const types = {
Person: [
{ name: 'name', type: 'string' },
{ name: 'wallet', type: 'address' }
{ name: 'wallet', type: 'address' },
],
Mail: [
{ name: 'from', type: 'Person' },
{ name: 'to', type: 'Person' },
{ name: 'contents', type: 'string' }
]
{ name: 'contents', type: 'string' },
],
};

// Define the domain
Expand All @@ -139,37 +140,37 @@ const domain: typed.EIP712Domain = {
version: '1',
chainId: 1,
verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
salt: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef'
salt: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef',
};

// Define the message
const message = {
from: {
name: 'Alice',
wallet: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC'
wallet: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
},
to: {
name: 'Bob',
wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB'
wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
},
contents: 'Hello, Bob!'
contents: 'Hello, Bob!',
};

// Create the typed data
const typedData: typed.TypedData<typeof types, 'Mail'> = {
types,
primaryType: 'Mail',
domain,
message
message,
};

// Sign the typed data
const privateKey = "0x4c0883a69102937d6231471b5dbb6204fe512961708279f1d7b1b8e7e8b1b1e1";
const privateKey = '0x4c0883a69102937d6231471b5dbb6204fe512961708279f1d7b1b8e7e8b1b1e1';
const signature = typed.signTyped(typedData, privateKey);
console.log("Signature:", signature);
console.log('Signature:', signature);

// Verify the signature
const address = "0xYourEthereumAddress";
const address = '0xYourEthereumAddress';
const isValid = typed.verifyTyped(signature, typedData, address);

// Recover the public key
Expand Down Expand Up @@ -338,7 +339,6 @@ There are following limitations:

Check out [`src/net/ens.ts`](./src/net/ens.ts) for type-safe contract execution example.


### Human-readable transaction hints

The transaction sent ERC-20 USDT token between addresses. The library produces a following hint:
Expand Down

0 comments on commit e03df52

Please sign in to comment.