-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
48 changed files
with
1,212 additions
and
430 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,4 +40,4 @@ jobs: | |
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
verbose: true | ||
slug: bcnmy/sdk | ||
slug: bcnmy/sdk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# @biconomy/sdk | ||
|
||
## 0.0.0 | ||
## 0.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { | ||
type Account, | ||
type Address, | ||
type Chain, | ||
type EIP1193Provider, | ||
type EIP1193RequestFn, | ||
type EIP1474Methods, | ||
type LocalAccount, | ||
type OneOf, | ||
type Transport, | ||
type WalletClient, | ||
createWalletClient, | ||
custom | ||
} from "viem" | ||
import { toAccount } from "viem/accounts" | ||
|
||
import { signTypedData } from "viem/actions" | ||
import { getAction } from "viem/utils" | ||
|
||
export type Signer = LocalAccount | ||
export type UnknownSigner = OneOf< | ||
| EIP1193Provider | ||
| WalletClient<Transport, Chain | undefined, Account> | ||
| LocalAccount | ||
| Account | ||
> | ||
export async function toSigner({ | ||
signer, | ||
address | ||
}: { | ||
signer: UnknownSigner | ||
address?: Address | ||
}): Promise<LocalAccount> { | ||
if ("type" in signer && signer.type === "local") { | ||
return signer as LocalAccount | ||
} | ||
|
||
let walletClient: | ||
| WalletClient<Transport, Chain | undefined, Account> | ||
| undefined = undefined | ||
|
||
if ("request" in signer) { | ||
if (!address) { | ||
try { | ||
;[address] = await (signer.request as EIP1193RequestFn<EIP1474Methods>)( | ||
{ | ||
method: "eth_requestAccounts" | ||
} | ||
) | ||
} catch { | ||
;[address] = await (signer.request as EIP1193RequestFn<EIP1474Methods>)( | ||
{ | ||
method: "eth_accounts" | ||
} | ||
) | ||
} | ||
} | ||
if (!address) throw new Error("address required") | ||
|
||
walletClient = createWalletClient({ | ||
account: address, | ||
transport: custom(signer as EIP1193Provider) | ||
}) | ||
} | ||
|
||
if (!walletClient) { | ||
walletClient = signer as WalletClient<Transport, Chain | undefined, Account> | ||
} | ||
|
||
return toAccount({ | ||
address: walletClient.account.address, | ||
async signMessage({ message }) { | ||
return walletClient.signMessage({ message }) | ||
}, | ||
async signTypedData(typedData) { | ||
return getAction( | ||
walletClient, | ||
signTypedData, | ||
"signTypedData" | ||
)(typedData as any) | ||
}, | ||
async signTransaction(_) { | ||
throw new Error("Not supported") | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.