Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc generation for viem to account ledger #390

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,8 @@ jobs:
needs: [install-dependencies]
if: |
github.base_ref == 'master' || contains(github.base_ref, 'staging') || contains(github.base_ref, 'production') ||
contains(needs.install-dependencies.outputs.all_modified_files, 'packages/cli') ||
contains(needs.install-dependencies.outputs.all_modified_files, 'packages/**') ||
contains(needs.install-dependencies.outputs.all_modified_files, 'packages/sdk') ||
contains(needs.install-dependencies.outputs.all_modified_files, 'packages/typescript') ||
contains(needs.install-dependencies.outputs.all_modified_files, ',package.json') ||
contains(needs.install-dependencies.outputs.all_modified_files, ',yarn.lock') ||
false
Expand Down
57 changes: 57 additions & 0 deletions packages/docs/viem-account-ledger/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
@celo/viem-account-ledger / [Modules](modules.md)

# @celo/viem-account-ledger

This library aims to ease the usage of a ledger device with (viem)[https://viem.sh/].

## Installation

```bash
npm install @celo/viem-account-ledger viem@2 @ledgerhq/[email protected]
# or yarn or bun or ...
```

> [!IMPORTANT] > `viem` is a peer dependency and MUST be installed alongside this library.
> `@ledgerhq/transport-node-hid` is a peer dependency and MUST be installed alongside this library.

## Usage

```ts
import TransportNodeHid from '@ledgerhq/hw-transport-node-hid'
import { createWalletClient } from 'viem'
import { celo, celoAlfajores } from 'viem/chains'
import { ledgerToAccount } from '@celo/viem-account-ledger'

async function main() => {
const account = await ledgerToAccount({
transport: await TransportNodeHid.open(''),
})
const client = createWalletClient({
account,
chain: celo,
transport: http()
});
await client.sendTransaction({
to: '0x123...',
value: 10n,
feeCurrency: '0x123...'
});
}
```

You can also use the `account` directly eg:

```ts
const account = await ledgerToAccount({
transport: await TransportNodeHid.open(''),
})
account.signTransaction({
to: '0x123...',
value: 123n,
chainId: celoAlfajores.id,
nonce: 42,
maxFeePerGas: 100n,
maxPriorityFeePerGas: 100n,
feeCurrency: '0x123...',
})
```
10 changes: 10 additions & 0 deletions packages/docs/viem-account-ledger/modules.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[@celo/viem-account-ledger](README.md) / Modules

# @celo/viem-account-ledger

## Table of contents

### Modules

- [index](modules/index.md)
- [ledger-to-account](modules/ledger_to_account.md)
29 changes: 29 additions & 0 deletions packages/docs/viem-account-ledger/modules/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[@celo/viem-account-ledger](../README.md) / [Modules](../modules.md) / index

# Module: index

## Table of contents

### References

- [CELO\_BASE\_DERIVATION\_PATH](index.md#celo_base_derivation_path)
- [DEFAULT\_DERIVATION\_PATH](index.md#default_derivation_path)
- [ledgerToAccount](index.md#ledgertoaccount)

## References

### CELO\_BASE\_DERIVATION\_PATH

Re-exports [CELO_BASE_DERIVATION_PATH](ledger_to_account.md#celo_base_derivation_path)

___

### DEFAULT\_DERIVATION\_PATH

Re-exports [DEFAULT_DERIVATION_PATH](ledger_to_account.md#default_derivation_path)

___

### ledgerToAccount

Re-exports [ledgerToAccount](ledger_to_account.md#ledgertoaccount)
86 changes: 86 additions & 0 deletions packages/docs/viem-account-ledger/modules/ledger_to_account.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
[@celo/viem-account-ledger](../README.md) / [Modules](../modules.md) / ledger-to-account

# Module: ledger-to-account

## Table of contents

### Type Aliases

- [LedgerAccount](ledger_to_account.md#ledgeraccount)

### Variables

- [CELO\_BASE\_DERIVATION\_PATH](ledger_to_account.md#celo_base_derivation_path)
- [DEFAULT\_DERIVATION\_PATH](ledger_to_account.md#default_derivation_path)
- [ETH\_DERIVATION\_PATH\_BASE](ledger_to_account.md#eth_derivation_path_base)

### Functions

- [ledgerToAccount](ledger_to_account.md#ledgertoaccount)

## Type Aliases

### LedgerAccount

Ƭ **LedgerAccount**: `LocalAccount`\<``"ledger"``\>

#### Defined in

[ledger-to-account.ts:10](https://github.com/celo-org/developer-tooling/blob/master/packages/viem-account-ledger/src/ledger-to-account.ts#L10)

## Variables

### CELO\_BASE\_DERIVATION\_PATH

• `Const` **CELO\_BASE\_DERIVATION\_PATH**: `string`

#### Defined in

[ledger-to-account.ts:13](https://github.com/celo-org/developer-tooling/blob/master/packages/viem-account-ledger/src/ledger-to-account.ts#L13)

___

### DEFAULT\_DERIVATION\_PATH

• `Const` **DEFAULT\_DERIVATION\_PATH**: `string`

#### Defined in

[ledger-to-account.ts:14](https://github.com/celo-org/developer-tooling/blob/master/packages/viem-account-ledger/src/ledger-to-account.ts#L14)

___

### ETH\_DERIVATION\_PATH\_BASE

• `Const` **ETH\_DERIVATION\_PATH\_BASE**: ``"m/44'/60'/0'"``

#### Defined in

[ledger-to-account.ts:12](https://github.com/celo-org/developer-tooling/blob/master/packages/viem-account-ledger/src/ledger-to-account.ts#L12)

## Functions

### ledgerToAccount

▸ **ledgerToAccount**(`options`): `Promise`\<[`LedgerAccount`](ledger_to_account.md#ledgeraccount)\>

A function to create a ledger account for viem

#### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `options` | `Object` | `undefined` | |
| `options.baseDerivationPath?` | `string` | `DEFAULT_DERIVATION_PATH` | defaults to "m/44'/60'/0" |
| `options.derivationPathIndex?` | `string` \| `number` | `0` | aka addressIndex |
| `options.transport` | `default` | `undefined` | a Ledger Transport |

#### Returns

`Promise`\<[`LedgerAccount`](ledger_to_account.md#ledgeraccount)\>

a viem LocalAccount<"ledger">

#### Defined in

[ledger-to-account.ts:25](https://github.com/celo-org/developer-tooling/blob/master/packages/viem-account-ledger/src/ledger-to-account.ts#L25)
2 changes: 2 additions & 0 deletions packages/viem-account-ledger/src/data.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// export default 'AAAAaARDRUxPRx7ON1DaI3+TuOM5xTaYm4l4pDgAAAASAACk7DBFAiEA5rECRg94+fCoIvoG9/5qWh62zl2C6Y+aFuuZrFe4CtcCIEJbRrkL3gqwT/Jj+7L3neazgpVCCTZZ3HX9JXXg5vleAAAAaARjVVNEdl3oFoRYYedaJfyhIrtomLixKCoAAAASAACk7DBFAiEApwQFHNBKXp+V2jq8BMD2y/5AwC9bhPQ2H4hT/vMl/B4CIFalOVtBFGREUKMU/F5vDlJLeQrTn6GQeDertpB2FpMvAAAAaARjRVVS2HY8uidqNzjm3oW0s79f3tbWynMAAAASAACk7DBFAiEAh2UeP1+SI2Ed5SiAjpJF6MkMrVa94gUwjJztyBlzhWMCIHfaOrEsxdxAGx+P+hxuSNO4zcw6KRLfJkkuic1V/CrHAAAAagZiIENFTE/dyb5X9VP+dXUtYWBrlMvX4CZO+AAAABIAAPNwMEUCIQCi62KsBfuNcfX0MriiRZ7a5DKERhtIz7sZ1SqBT7ruhgIgVrfmavyWzxzDW4AQeHn++A4qPjB1pQKoHvNXo8Hf1SMAAABpBmIgY1VTRGJJKmRKWI/ZBCcL7QatUrmr/qGuAAAAEgAA83AwRAIgGDYx4oB/gkYUqLeXqvEZXx9nOxVHzTe2ajyd2wnehxgCICQBe/rBPcXiaQJj3pdoXxroct/hV6r3G2G7y79EOEAPAAAAaQZiIGNFVVL57OMBJHrSziGJSUGDCiRw9Od0ygAAABIAAPNwMEQCIEdcFWP+HxEUoF1sCGVd34QGS0hL5cVUdrWdqVm3bYTgAiBCMA+Rg3Ubc3xla/35wzZesPlbeSMEPcr4uqL+8PeydwAAAGoGYSBDRUxP8ZSv31CwPmm9fQV8GqnhDJlU5MkAAAASAACu8zBFAiEAk/o0FBus2/QCrunFGEyoneQIRaMRC+y5L6Dvar8MU/kCIByJt2ziRhDG3AAbyXBIuJfZQujSHFcSJL3xF0xIlcPdAAAAaQZhIGNVU0SHQGn6HrFtRNYi8uDKJe6hcjabwQAAABIAAK7zMEQCIClrH2xgE3WMbD+hgQ7t5SiAcVG5WiUZ655voqCszKEoAiA/cO8UVgNY891MNJ5yeDk8w47WO0E1DQecrK71LR8g8gAAAGoGYSBjRVVSEMiSpuxDpT5F0LkWtLfTg7G3jA8AAAASAACu8zBFAiEAgpktbB1ZxyAwMJwKTSbZ30n8zgRuW0twbXoZxlsUAswCIHek4l4CIbjVMG2HVr0Ml9/8kA4F9dr69JBMaoSUkdKl'

// This was signed by Marek Olszewski on Wed 18 June 2024
/** @internal */
export default 'AAAAZwRVU0RUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGAACk7DBEAiA45AhZco0/POPgpuUPBqRnGG1SfGPpXE8+Hckw0dZLCQIgWteUoWhghs0KwxfgX2P0jJ2gYQEAbq6J+mWfSs9yWzcAAABnBFVTRFQOKj4FvJoW9SkqYXBFanEMuJxvcgAAABIAAKTsMEQCIAl/QSQA3JAF4c+otYCNG+JghDIV17habVFg/kLOLG9UAiAY+PSK6WBYObKt8OObZHKiAVWHOaI0E26OC61ytGCN4wAAAGgEVVNEQwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABgAApOwwRQIhAJAwutARDDU/EgrpV1SYRuLsKR/JjkYP4rRT6InIlo8GAiAgyuHrUNUuEdfijlmY8UWzR/jzLzycmkjEjL8qV06GvwAAAGcEVVNEQy8l3rOEjCB/yODDQDWzun/BV2ArAAAAEgAApOwwRAIgVYSG4e4JD7mbHMdOd29i5c4872THYeVWqDsb6ZE0JA4CIGVsHMurIGTBw1WUJqmOsBXUBlP5bhljUufw9jgQKq7JAAAAaARlWE9Gc/k9zEnLiiOeIDJmPpR13V7ymggAAAASAACk7DBFAiEA31wGJ9NfYN5Ujs3qkNxXowT73iNAxrBw7SdHTfLn47UCIH0fhGCTysFEdN31WIVCvkgo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F386QYNiGqThC4a5OsgII7Kfz/qW6EYq1+VQAAABrB2EgY1JFQUzk1Rd4XQkdPFSBiDLbYJS8wnRFRQAAABIAAK7zMEUCIQDVjhKnLdzKU84vV/13nvvshLsaCC4IfzLFmieUNniSMAIgMCRja6R+GcT2OFVF8ClIx/7ZBlIHEIqooo/8Bnpy1sc='

// How did we get this? By following these steps:
Expand All @@ -11,6 +12,7 @@ export default 'AAAAZwRVU0RUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGAACk7DBEAiA45AhZco0/
// 5 - and store it in key `KEY=04b06cf5d8f7ed71d8bd9b9dc37944a1c6d240f69bb0be3621dddbb6ac0eccd1508bcc2ea46227e43b941e2c6f1b1cd0ae68e54b185e2cabef3455580604bd45b8`
// 5 - finally run `echo $ASN1_PREFIX$KEY | xxd -r -p - | openssl ec -inform der -pubin -pubout`
// 6 - enjoy
/** @internal */
export const legacyLedgerPublicKeyHex = [
`-----BEGIN PUBLIC KEY-----`,
`MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAEsGz12Pftcdi9m53DeUShxtJA9puwvjYh`,
Expand Down
11 changes: 10 additions & 1 deletion packages/viem-account-ledger/src/ledger-to-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,21 @@ import { CeloTransactionSerializable, serializeTransaction } from 'viem/celo'

import { checkForKnownToken, generateLedger } from './utils.js'

type LedgerAccount = LocalAccount<'ledger'>
export type LedgerAccount = LocalAccount<'ledger'>

export const ETH_DERIVATION_PATH_BASE = "m/44'/60'/0'" as const
export const CELO_BASE_DERIVATION_PATH = `${CELO_DERIVATION_PATH_BASE.slice(2)}/0`
export const DEFAULT_DERIVATION_PATH = `${ETH_DERIVATION_PATH_BASE.slice(2)}/0`

/**
* A function to create a ledger account for viem
* @param options
* @param options.transport a Ledger Transport
* @param options.derivationPathIndex aka addressIndex
* @param options.baseDerivationPath defaults to "m/44'/60'/0"
*
* @returns a viem LocalAccount<"ledger">
*/
export async function ledgerToAccount({
transport,
derivationPathIndex = 0,
Expand Down
1 change: 1 addition & 0 deletions packages/viem-account-ledger/src/types.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/** @internal */
export type Hex = `0x${string}`
5 changes: 3 additions & 2 deletions packages/viem-account-ledger/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
"hideGenerator": true,
"out": "../docs/viem-account-ledger",
"gitRevision": "master",
"readme": "none",
"entryPoints": ["./src"],
"readme": "./README.md",
"entryPoints": ["./src/index.ts", "./src/ledger-to-account.ts"],
"excludeInternal": true,
"githubPages": false,
"plugin": ["typedoc-plugin-markdown"],
"entryPointStrategy": "expand"
Expand Down
Loading