-
Notifications
You must be signed in to change notification settings - Fork 18
Signers: Address post-merge review of #40 — bare compat for /signers, VoidSigner tx population, interface cleanup #95
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // Copyright 2024 Tether Operations Limited | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| 'use strict' | ||
|
|
||
| import 'bare-node-runtime/global' | ||
|
|
||
| export * from './index.js' with { imports: 'bare-node-runtime/imports' } | ||
|
|
||
| export { default } from './index.js' with { imports: 'bare-node-runtime/imports' } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -18,29 +18,28 @@ import { BaseWallet } from 'ethers' | |||||||||||||||||||||||||||||||||||||||
| import { SignerError } from '@tetherto/wdk-wallet' | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| import MemorySafeSigningKey from '../memory-safe/signing-key.js' | ||||||||||||||||||||||||||||||||||||||||
| import { ISignerEvm } from './seed-signer-evm.js' | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| /** @typedef {import('../utils/tx-populator-evm.js').UnsignedEvmTransaction} UnsignedEvmTransaction */ | ||||||||||||||||||||||||||||||||||||||||
| /** @typedef {import('./signer-evm.js').ISignerEvm} ISignerEvm */ | ||||||||||||||||||||||||||||||||||||||||
| /** @typedef {import('@tetherto/wdk-wallet').KeyPair} KeyPair */ | ||||||||||||||||||||||||||||||||||||||||
| /** @typedef {import('ethers').TransactionLike} TransactionLike */ | ||||||||||||||||||||||||||||||||||||||||
| /** @typedef {import('ethers').AuthorizationRequest} AuthorizationRequest */ | ||||||||||||||||||||||||||||||||||||||||
| /** @typedef {import('ethers').Authorization} Authorization */ | ||||||||||||||||||||||||||||||||||||||||
| /** @typedef {import('../wallet-account-read-only-evm.js').TypedData} TypedData */ | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||
| * @extends {ISignerEvm} | ||||||||||||||||||||||||||||||||||||||||
| * Signer that wraps a raw private key in a memory-safe buffer, exposing a minimal | ||||||||||||||||||||||||||||||||||||||||
| * interface for signing messages, transactions and typed data. This signer does | ||||||||||||||||||||||||||||||||||||||||
| * not support derivation and always represents a single account. | ||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||
| * @implements {ISignerEvm} | ||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||
| export default class PrivateKeySignerEvm extends ISignerEvm { | ||||||||||||||||||||||||||||||||||||||||
| export default class PrivateKeySignerEvm { | ||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||
| * Create a signer from a raw private key. | ||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||
| * @param {string|Uint8Array} privateKey - Hex string (with/without 0x) or raw key bytes. | ||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||
| constructor (privateKey) { | ||||||||||||||||||||||||||||||||||||||||
| super() | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| // Expect a Uint8Array buffer; accept hex string as convenience | ||||||||||||||||||||||||||||||||||||||||
| let privateKeyBuffer = privateKey | ||||||||||||||||||||||||||||||||||||||||
| if (typeof privateKey === 'string') { | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -61,30 +60,36 @@ export default class PrivateKeySignerEvm extends ISignerEvm { | |||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||
| * Whether this signer can derive child signers. Always false: a private-key signer is a | ||||||||||||||||||||||||||||||||||||||||
| * single standalone account and is bound directly to a wallet account. | ||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||
| * @type {boolean} | ||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||
| get isDerivable () { return false } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||
| * The account index. Always undefined for private key signers: a raw key has no | ||||||||||||||||||||||||||||||||||||||||
| * BIP-44 position, so reporting an index would be misleading. | ||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||
| * @type {number|undefined} | ||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||
| get index () { return undefined } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||
| * The derivation path. Always undefined for private key signers. | ||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||
| * @type {string|undefined} | ||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||
| get path () { return this._path } | ||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The path and index will always be null for a private key signer.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Private key signers don't need a path property so you can get rid of it:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||
| * The account's address. | ||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||
| * @type {string} | ||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||
| get address () { return this._address } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||
| * The account's key pair (private and public key buffers). | ||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||
| * @type {KeyPair} | ||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||
| get keyPair () { | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -95,15 +100,21 @@ export default class PrivateKeySignerEvm extends ISignerEvm { | |||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||
| * PrivateKeySignerEvm is not a hierarchical signer and cannot derive. | ||||||||||||||||||||||||||||||||||||||||
| * @returns {Promise<never>} | ||||||||||||||||||||||||||||||||||||||||
| * Derive a child signer using a relative path (e.g., "0'/0/0"). | ||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||
| * @param {string} relPath - The relative derivation path. | ||||||||||||||||||||||||||||||||||||||||
| * @returns {Promise<never>} Never resolves; private-key signers cannot derive. | ||||||||||||||||||||||||||||||||||||||||
| * @throws {SignerError} Always — private-key signers do not support derivation. | ||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||
| async derive () { | ||||||||||||||||||||||||||||||||||||||||
| async derive (relPath) { | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
97
to
+99
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This should be:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
| throw new SignerError('PrivateKeySignerEvm does not support derivation.') | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| /** @returns {Promise<string>} */ | ||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||
| * Returns the account's address. | ||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||
| * @returns {Promise<string>} The account's address. | ||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||
| async getAddress () { | ||||||||||||||||||||||||||||||||||||||||
| return this._address | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -119,13 +130,13 @@ export default class PrivateKeySignerEvm extends ISignerEvm { | |||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||
| * Signs a transaction and returns the serialized signed transaction hex. | ||||||||||||||||||||||||||||||||||||||||
| * Signs a transaction. | ||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||
| * @param {UnsignedEvmTransaction} unsignedTx - The unsigned transaction object. | ||||||||||||||||||||||||||||||||||||||||
| * @returns {Promise<string>} | ||||||||||||||||||||||||||||||||||||||||
| * @param {TransactionLike} tx - The transaction to sign. | ||||||||||||||||||||||||||||||||||||||||
| * @returns {Promise<string>} The signed transaction as a hex string. | ||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||
| async signTransaction (unsignedTx) { | ||||||||||||||||||||||||||||||||||||||||
| return this._wallet.signTransaction(unsignedTx) | ||||||||||||||||||||||||||||||||||||||||
| async signTransaction (tx) { | ||||||||||||||||||||||||||||||||||||||||
| return this._wallet.signTransaction(tx) | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -139,15 +150,18 @@ export default class PrivateKeySignerEvm extends ISignerEvm { | |||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||
| * Sign an ERC-7702 authorization tuple. | ||||||||||||||||||||||||||||||||||||||||
| * @param {AuthorizationRequest} auth | ||||||||||||||||||||||||||||||||||||||||
| * @returns {Promise<Authorization>} | ||||||||||||||||||||||||||||||||||||||||
| * Signs an ERC-7702 authorization tuple. | ||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||
| * @param {AuthorizationRequest} auth - The authorization request. | ||||||||||||||||||||||||||||||||||||||||
| * @returns {Promise<Authorization>} The signed authorization. | ||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||
| async signAuthorization (auth) { | ||||||||||||||||||||||||||||||||||||||||
| return this._wallet.authorizeSync(auth) | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| /** Dispose secrets from memory. */ | ||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||
| * Disposes the signer, erasing its secrets from memory. | ||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||
| dispose () { | ||||||||||||||||||||||||||||||||||||||||
| if (this._signingKey) this._signingKey.dispose() | ||||||||||||||||||||||||||||||||||||||||
| this._signingKey = undefined | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should export the 'ISignerEvm' interface only out of /src/signers/index.js.