diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts index 716c1ef..6429337 100644 --- a/docs/.vitepress/config.mts +++ b/docs/.vitepress/config.mts @@ -9,8 +9,8 @@ export default defineConfig({ // https://vitepress.dev/reference/default-theme-config nav: [ { text: 'Home', link: '/' }, - { text: 'API', link: '/api' }, - { text: 'Examples', link: '/examples' } + { text: 'API', link: 'https://jsr.io/@planetarium/chrono-sdk/doc' }, + { text: 'Examples', link: '/developer/examples' } ], sidebar: [ @@ -40,7 +40,7 @@ export default defineConfig({ items: [ { text: 'API', - link: '/developer/api', + link: 'https://jsr.io/@planetarium/chrono-sdk/doc', }, { text: 'Examples', diff --git a/docs/developer/api.md b/docs/developer/api.md deleted file mode 100644 index 1e50393..0000000 --- a/docs/developer/api.md +++ /dev/null @@ -1,200 +0,0 @@ ---- -outline: deep ---- - -# Wallet API (i.e., `window.chronoWallet`) - -This page describes the specifications and issues of the Chrono Wallet API. - -Chrono Wallet communicates with browser extensions through a global variable called `window.chronoWallet` to provide an interface to do things like signing. This is similar to how MetaMask provides a JSON-RPC API through `window.ethereum`. - -## `connect` - -### Signature - -```typescript -function connect(): Promise; -``` - -### Parameters - -There is no parameter. - -### Returns - -It doesn't return. - -### Examples - -```typescript -await window.chronoWallet.connect(); -``` - -## `isConnected` - -### Signature - -```typescript -function isConnected(): Promise; -``` - -### Parameters - -There is no parameter. - -### Returns - -It returns whether it is connected or not. - -### Examples - -```typescript -const isConnected = await window.chronoWallet.isConnected(); -``` - -## `listAccounts` - -### Signature - -```typescript -function listAccounts(): Promise<{ - address: Address; -}[]>; -``` - -### Parameters - -There is no parameter. - -### Returns - -It returns an array of objects. Each object has `activated` and `address` properties. - -### Examples - -```typescript -import { Address } from "@planetarium/account"; - -const accounts = await window.chronoWallet.listAccounts(); -const addresses: Address[] = accounts.map(x => x.address); -``` - -## `getPublicKey` - -### Signature - -```typescript -function getPublicKey(address: string): Promise; -``` - -### Parameters - -- `address`: A hexadecimal string. The content must be an address of a public key to get, compatible for [ERC-55](https://eips.ethereum.org/EIPS/eip-55). - -### Returns - -It returns a hexadecimal string, public key. - -### Examples - -```typescript -import { PublicKey } from "@planetarium/account"; - -const publicKey: PublicKey = await window.chronoWallet.getPublicKey("0x2cBaDf26574756119cF705289C33710F27443767"); -``` - -## `sign` - -Sign a new transaction with an action. If you want to configure properties like `nonce`, `timestamp`, you should use [`window.chronoWallet.signTx`](#window-chronowallet-signtx) - -### Signature - -```typescript -function sign(signer: Address, action: Value): Promise; -``` - -### Parameters - -- `signer`: A hexadecimal string. The content must be the signer's address compatible for [ERC-55](https://eips.ethereum.org/EIPS/eip-55). -- `action`: A hexadecimal string. The content should be encoded action. - -### Returns - -It returns a hexadecimal string, encoded signed transaction. - -### Examples - -```typescript -import { Address } from "@planetarium/account"; -import { encode, BencodexDictionary } from "@planetarium/bencodex"; -import { Buffer } from "buffer"; - -const signer = Address.fromHex("0x2cBaDf26574756119cF705289C33710F27443767"); -const action = new BencodexDictionary([ - ["type_id", "daily_reward7"], - ["values", new BencodexDictionary([ - ["a", Buffer.from("DE3873DB166647Cc3538ef64EAA8A0cCFD51B9fE", "hex")] - ])] -]); - -const signedTxBytes = await window.chronoWallet.sign(signer, action); -``` - -## `signTx` - -### Signature - -```typescript -function signTx(signer: Address, unsignedTx: UnsignedTx): Promise; -``` - -### Parameters - -- `signer`: A hexadecimal string. The content must be the signer's address compatible for [ERC-55](https://eips.ethereum.org/EIPS/eip-55). -- `unsignedTx`: A hexadecimal string. The content should be encoded unsigned transaction. - -### Returns - -It returns a hexadecimal string, encoded signed transaction. - -### Examples - -```typescript -import { type UnsignedTx, encodeUnsignedTx } from "@planetarium/tx"; -import { Address } from "@planetarium/account"; -import { encode, BencodexDictionary } from "@planetarium/bencodex"; -import { Buffer } from "buffer"; -import { Decimal } from "decimal.js"; - -const signer = Address.fromHex("0x2cBaDf26574756119cF705289C33710F27443767"); -const publicKey = await window.chronoWallet.getPublicKey(signer); -const action = new BencodexDictionary([ - ["type_id", "daily_reward7"], - ["values", new BencodexDictionary([ - ["a", Buffer.from("DE3873DB166647Cc3538ef64EAA8A0cCFD51B9fE", "hex")] - ])] -]); - -const unsignedTx = { - signer: signer.toBytes(), - actions: [action], - updatedAddresses: new Set([]), - nonce: 1n, - genesisHash, - publicKey: publicKey.toBytes("uncompressed"), - timestamp: new Date(), - maxGasPrice: { - currency: { - ticker: "Mead", - decimalPlaces: 18, - minters: null, - totalSupplyTrackable: false, - maximumSupply: null, - }, - rawValue: BigInt(Decimal.pow(10, 18).toString()) - }, - gasLimit, -}; - -const signedTxBytes = await window.chronoWallet.sign(signer, unsignedTx); -``` diff --git a/packages/chrono-sdk/jsr.json b/packages/chrono-sdk/jsr.json index e6e047e..182cb21 100644 --- a/packages/chrono-sdk/jsr.json +++ b/packages/chrono-sdk/jsr.json @@ -1,7 +1,7 @@ { "$schema": "https://jsr.io/schema/config-file.v1.json", "name": "@planetarium/chrono-sdk", - "version": "0.2.0", + "version": "0.3.0", "exports": { ".": "./src/index.ts", "./hooks": "./src/hooks/index.ts"