@0xkey-io/viem 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/LICENSE +201 -0
- package/README.md +113 -0
- package/dist/index.d.ts +89 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +369 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +356 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +76 -0
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 0xkey
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# @0xkey-io/viem
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@0xkey-io/viem)
|
|
4
|
+
|
|
5
|
+
This package contains helpers to use [Viem](https://viem.sh/) with [ZeroXKey](https://0xkey.com).
|
|
6
|
+
|
|
7
|
+
We provide a ZeroXKey [Custom Account](https://viem.sh/docs/accounts/custom.html#custom-account) (signer) which implements the signing APIs expected by Viem clients.
|
|
8
|
+
|
|
9
|
+
If you need a lower-level, fully typed HTTP client for interacting with ZeroXKey API, check out [`@0xkey-io/http`](https://www.npmjs.com/package/@0xkey-io/http).
|
|
10
|
+
|
|
11
|
+
## Getting started
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
$ npm install viem @0xkey-io/viem
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { createAccount } from "@0xkey-io/viem";
|
|
19
|
+
import { ZeroXKeyClient } from "@0xkey-io/http";
|
|
20
|
+
import { ApiKeyStamper } from "@0xkey-io/api-key-stamper";
|
|
21
|
+
import { createWalletClient, http } from "viem";
|
|
22
|
+
import { sepolia } from "viem/chains";
|
|
23
|
+
|
|
24
|
+
async function main() {
|
|
25
|
+
// Create a ZeroXKey HTTP client with API key credentials
|
|
26
|
+
const httpClient = new ZeroXKeyClient(
|
|
27
|
+
{
|
|
28
|
+
baseUrl: "https://api.0xkey.com",
|
|
29
|
+
},
|
|
30
|
+
// This uses API key credentials.
|
|
31
|
+
// If you're using passkeys, use `@0xkey-io/webauthn-stamper` to collect webauthn signatures:
|
|
32
|
+
// new WebauthnStamper({...options...})
|
|
33
|
+
new ApiKeyStamper({
|
|
34
|
+
apiPublicKey: "...",
|
|
35
|
+
apiPrivateKey: "...",
|
|
36
|
+
}),
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
// Create the Viem custom account
|
|
40
|
+
const zeroXKeyAccount = await createAccount({
|
|
41
|
+
client: httpClient,
|
|
42
|
+
organizationId: "...",
|
|
43
|
+
signWith: "...",
|
|
44
|
+
// optional; will be fetched from ZeroXKey if not provided
|
|
45
|
+
ethereumAddress: "...",
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Below: standard Viem APIs are used, nothing special!
|
|
49
|
+
|
|
50
|
+
const client = createWalletClient({
|
|
51
|
+
account: zeroXKeyAccount,
|
|
52
|
+
chain: sepolia,
|
|
53
|
+
transport: http(`https://sepolia.infura.io/v3/$(YOUR_INFURA_API_KEY)`),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const transactionRequest = {
|
|
57
|
+
to: "0x08d2b0a37F869FF76BACB5Bab3278E26ab7067B7" as `0x${string}`,
|
|
58
|
+
value: 1000000000000000n, // 0.001 ETH
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const txHash = await client.sendTransaction(transactionRequest);
|
|
62
|
+
console.log(`Success! Transaction broadcast with hash ${txHash}`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
main().catch((error) => {
|
|
66
|
+
console.error(error);
|
|
67
|
+
process.exit(1);
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Testing (Local)
|
|
72
|
+
|
|
73
|
+
1. Copy `.env.example` to `.env`
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
$ cp .env.example .env
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
2. Start the Anvil node in one shell:
|
|
80
|
+
- Install [Foundry](https://book.getfoundry.sh/getting-started/installation) & Anvil if you haven't done so already
|
|
81
|
+
- Add Foundry to your `$PATH`
|
|
82
|
+
```bash
|
|
83
|
+
$ export PATH="$PATH:$HOME/.foundry/bin"
|
|
84
|
+
```
|
|
85
|
+
- Source your env e.g.
|
|
86
|
+
```bash
|
|
87
|
+
$ source ~/.zshrc
|
|
88
|
+
```
|
|
89
|
+
- Run `foundryup` to install `Anvil`
|
|
90
|
+
```bash
|
|
91
|
+
$ foundryup
|
|
92
|
+
```
|
|
93
|
+
- Start Anvil
|
|
94
|
+
```
|
|
95
|
+
$ pnpm anvil
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
3. Run the tests in a new shell:
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
$ pnpm test
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## See also
|
|
105
|
+
|
|
106
|
+
- [`@0xkey-io/example-with-viem`](https://github.com/0xkey-io/sdk-js/tree/main/examples/with-viem): example using this package to create, sign, and broadcast a transaction on Sepolia (Ethereum testnet)
|
|
107
|
+
- [`@0xkey-io/http`](https://www.npmjs.com/package/@0xkey-io/http): lower-level fully typed HTTP client for interacting with ZeroXKey API
|
|
108
|
+
- [`@0xkey-io/api-key-stamper`](https://www.npmjs.com/package/@0xkey-io/api-key-stamper): package to authenticate to ZeroXKey using API key credentials
|
|
109
|
+
- [`@0xkey-io/webauthn-stamper`](https://www.npmjs.com/package/@0xkey-io/webauthn-stamper): package to authenticate to ZeroXKey using Webauthn/passkeys.
|
|
110
|
+
|
|
111
|
+
## Transaction types supported
|
|
112
|
+
|
|
113
|
+
- ZeroXKey's Viem implementation now supports all transaction types: legacy, EIP-2930 (Type 1), EIP-1559 (Type 2), EIP-4844 (Type 3), and EIP-7702 (Type 4). See [with-viem](https://github.com/0xkey-io/sdk-js/tree/main/examples/with-viem/) for examples of scripts that sign using those various types.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { BaseError } from "viem";
|
|
2
|
+
import { SignAuthorizationReturnType, SignAuthorizationParameters } from "viem/accounts";
|
|
3
|
+
import type { Hex, LocalAccount, SerializeTransactionFn, SignableMessage, TransactionSerializable, TypedData } from "viem";
|
|
4
|
+
import { TActivityStatus, TActivityId, TSignature, ZeroXKeyClient } from "@0xkey-io/http";
|
|
5
|
+
import type { ZeroXKeyBrowserClient } from "@0xkey-io/sdk-browser";
|
|
6
|
+
import type { ZeroXKeySDKClientBase } from "@0xkey-io/core";
|
|
7
|
+
import type { ZeroXKeyServerClient } from "@0xkey-io/sdk-server";
|
|
8
|
+
export type TZeroXKeyConsensusNeededErrorType = ZeroXKeyConsensusNeededError & {
|
|
9
|
+
name: "ZeroXKeyConsensusNeededError";
|
|
10
|
+
};
|
|
11
|
+
export type TZeroXKeyActivityErrorType = ZeroXKeyActivityError & {
|
|
12
|
+
name: "ZeroXKeyActivityError";
|
|
13
|
+
};
|
|
14
|
+
type TSignAuthorizationParameters = Omit<SignAuthorizationParameters, "privateKey">;
|
|
15
|
+
type TSignatureFormat = "object" | "bytes" | "hex";
|
|
16
|
+
export declare class ZeroXKeyConsensusNeededError extends BaseError {
|
|
17
|
+
name: string;
|
|
18
|
+
activityId: TActivityId | undefined;
|
|
19
|
+
activityStatus: TActivityStatus | undefined;
|
|
20
|
+
constructor({ message, activityId, activityStatus, }: {
|
|
21
|
+
message?: string | undefined;
|
|
22
|
+
activityId: TActivityId | undefined;
|
|
23
|
+
activityStatus: TActivityStatus | undefined;
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export declare class ZeroXKeyActivityError extends BaseError {
|
|
27
|
+
name: string;
|
|
28
|
+
activityId: TActivityId | undefined;
|
|
29
|
+
activityStatus: TActivityStatus | undefined;
|
|
30
|
+
constructor({ message, activityId, activityStatus, }: {
|
|
31
|
+
message?: string | undefined;
|
|
32
|
+
activityId?: TActivityId | undefined;
|
|
33
|
+
activityStatus?: TActivityStatus | undefined;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
export declare function createAccountWithAddress(input: {
|
|
37
|
+
client: ZeroXKeyClient | ZeroXKeyBrowserClient | ZeroXKeyServerClient | ZeroXKeySDKClientBase;
|
|
38
|
+
organizationId: string;
|
|
39
|
+
signWith: string;
|
|
40
|
+
ethereumAddress?: string;
|
|
41
|
+
}): LocalAccount;
|
|
42
|
+
export declare function createAccount(input: {
|
|
43
|
+
client: ZeroXKeyClient | ZeroXKeyBrowserClient | ZeroXKeyServerClient | ZeroXKeySDKClientBase;
|
|
44
|
+
organizationId: string;
|
|
45
|
+
signWith: string;
|
|
46
|
+
ethereumAddress?: string;
|
|
47
|
+
}): Promise<LocalAccount>;
|
|
48
|
+
/**
|
|
49
|
+
* Type bundling configuration for an API Key Viem account creation
|
|
50
|
+
* @deprecated this is used only with {@link createApiKeyAccount}, a deprecated API. See {@link createAccount}.
|
|
51
|
+
*/
|
|
52
|
+
type TApiKeyAccountConfig = {
|
|
53
|
+
/**
|
|
54
|
+
* ZeroXKey API public key
|
|
55
|
+
*/
|
|
56
|
+
apiPublicKey: string;
|
|
57
|
+
/**
|
|
58
|
+
* ZeroXKey API private key
|
|
59
|
+
*/
|
|
60
|
+
apiPrivateKey: string;
|
|
61
|
+
/**
|
|
62
|
+
* ZeroXKey API base URL
|
|
63
|
+
*/
|
|
64
|
+
baseUrl: string;
|
|
65
|
+
/**
|
|
66
|
+
* ZeroXKey organization ID
|
|
67
|
+
*/
|
|
68
|
+
organizationId: string;
|
|
69
|
+
/**
|
|
70
|
+
* ZeroXKey private key ID
|
|
71
|
+
*/
|
|
72
|
+
privateKeyId: string;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Creates a new Custom Account backed by a ZeroXKey API key.
|
|
76
|
+
* @deprecated use {@link createAccount} instead.
|
|
77
|
+
*/
|
|
78
|
+
export declare function createApiKeyAccount(config: TApiKeyAccountConfig): Promise<LocalAccount>;
|
|
79
|
+
export declare function signAuthorization(client: ZeroXKeyClient | ZeroXKeyBrowserClient | ZeroXKeyServerClient | ZeroXKeySDKClientBase, parameters: TSignAuthorizationParameters, organizationId: string, signWith: string): Promise<SignAuthorizationReturnType>;
|
|
80
|
+
export declare function signMessage(client: ZeroXKeyClient | ZeroXKeyBrowserClient | ZeroXKeyServerClient | ZeroXKeySDKClientBase, message: SignableMessage, organizationId: string, signWith: string): Promise<Hex>;
|
|
81
|
+
export declare function signTransaction<TTransactionSerializable extends TransactionSerializable>(client: ZeroXKeyClient | ZeroXKeyBrowserClient | ZeroXKeyServerClient | ZeroXKeySDKClientBase, transaction: TTransactionSerializable, serializer: SerializeTransactionFn<TTransactionSerializable>, organizationId: string, signWith: string): Promise<Hex>;
|
|
82
|
+
export declare function signTypedData(client: ZeroXKeyClient | ZeroXKeyBrowserClient | ZeroXKeyServerClient | ZeroXKeySDKClientBase, data: TypedData | {
|
|
83
|
+
[key: string]: unknown;
|
|
84
|
+
}, organizationId: string, signWith: string): Promise<Hex>;
|
|
85
|
+
export declare function serializeSignature(sig: TSignature, to?: TSignatureFormat): Uint8Array | `0x${string}1b` | `0x${string}1c`;
|
|
86
|
+
export declare function isZeroXKeyActivityConsensusNeededError(error: any): any;
|
|
87
|
+
export declare function isZeroXKeyActivityError(error: any): any;
|
|
88
|
+
export {};
|
|
89
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings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AAE,4BAA4B,EACxC,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,2BAA2B,CAAC,CAmCtC;AAED,wBAAsB,WAAW,CAC/B,MAAM,EACF,cAAc,GACd,qBAAqB,GACrB,oBAAoB,GACpB,qBAAqB,EACzB,OAAO,EAAE,eAAe,EACxB,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,GAAG,CAAC,CAQd;AAED,wBAAsB,eAAe,CACnC,wBAAwB,SAAS,uBAAuB,EAExD,MAAM,EACF,cAAc,GACd,qBAAqB,GACrB,oBAAoB,GACpB,qBAAqB,EACzB,WAAW,EAAE,wBAAwB,EACrC,UAAU,EAAE,sBAAsB,CAAC,wBAAwB,CAAC,EAC5D,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,GAAG,CAAC,CAmCd;AAED,wBAAsB,aAAa,CACjC,MAAM,EACF,cAAc,GACd,qBAAqB,GACrB,oBAAoB,GACpB,qBAAqB,EACzB,IAAI,EAAE,SAAS,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,EAC5C,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,GAAG,CAAC,CASd;AA4MD,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,UAAU,EACf,EAAE,GAAE,gBAAwB,kDAkB7B;AAED,wBAAgB,sCAAsC,CAAC,KAAK,EAAE,GAAG,OAOhE;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,GAAG,OAOjD"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var viem = require('viem');
|
|
4
|
+
var accounts = require('viem/accounts');
|
|
5
|
+
var secp256k1 = require('@noble/curves/secp256k1');
|
|
6
|
+
var http = require('@0xkey-io/http');
|
|
7
|
+
var apiKeyStamper = require('@0xkey-io/api-key-stamper');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Detects the transaction type from a serialized transaction payload.
|
|
11
|
+
* @param serializedTx - The hex-encoded transaction (without 0x prefix)
|
|
12
|
+
* @returns The transaction type to use with ZeroXKey API
|
|
13
|
+
*/
|
|
14
|
+
function detectTransactionType(serializedTx) {
|
|
15
|
+
// Check if the transaction starts with 0x76 (Tempo transaction)
|
|
16
|
+
if (serializedTx.startsWith("76")) {
|
|
17
|
+
return "TRANSACTION_TYPE_TEMPO";
|
|
18
|
+
}
|
|
19
|
+
// Default to Ethereum for all other transactions
|
|
20
|
+
return "TRANSACTION_TYPE_ETHEREUM";
|
|
21
|
+
}
|
|
22
|
+
class ZeroXKeyConsensusNeededError extends viem.BaseError {
|
|
23
|
+
constructor({ message = "ZeroXKey activity requires consensus.", activityId, activityStatus, }) {
|
|
24
|
+
super(message);
|
|
25
|
+
this.name = "ZeroXKeyConsensusNeededError";
|
|
26
|
+
this.activityId = activityId;
|
|
27
|
+
this.activityStatus = activityStatus;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
class ZeroXKeyActivityError extends viem.BaseError {
|
|
31
|
+
constructor({ message = "Received unexpected ZeroXKey activity status.", activityId, activityStatus, }) {
|
|
32
|
+
super(message);
|
|
33
|
+
this.name = "ZeroXKeyActivityError";
|
|
34
|
+
this.activityId = activityId;
|
|
35
|
+
this.activityStatus = activityStatus;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function createAccountWithAddress(input) {
|
|
39
|
+
const { client, organizationId, signWith } = input;
|
|
40
|
+
let { ethereumAddress } = input;
|
|
41
|
+
if (!signWith) {
|
|
42
|
+
throw new http.ZeroXKeyActivityError({
|
|
43
|
+
message: `Missing signWith parameter`,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
if (viem.isAddress(signWith)) {
|
|
47
|
+
// override provided `ethereumAddress`
|
|
48
|
+
ethereumAddress = signWith;
|
|
49
|
+
}
|
|
50
|
+
else if (!ethereumAddress) {
|
|
51
|
+
throw new ZeroXKeyActivityError({
|
|
52
|
+
message: `Missing ethereumAddress parameter`,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return accounts.toAccount({
|
|
56
|
+
address: ethereumAddress,
|
|
57
|
+
sign: function ({ hash }) {
|
|
58
|
+
return signMessage(client, hash, organizationId, signWith);
|
|
59
|
+
},
|
|
60
|
+
signMessage: function ({ message, }) {
|
|
61
|
+
const hashedMessage = viem.hashMessage(message);
|
|
62
|
+
return signMessage(client, hashedMessage, organizationId, signWith);
|
|
63
|
+
},
|
|
64
|
+
signTransaction: function (transaction, options) {
|
|
65
|
+
const serializer = options?.serializer ??
|
|
66
|
+
viem.serializeTransaction;
|
|
67
|
+
return signTransaction(client, transaction, serializer, organizationId, signWith);
|
|
68
|
+
},
|
|
69
|
+
signTypedData: function (typedData) {
|
|
70
|
+
return signTypedData(client, typedData, organizationId, signWith);
|
|
71
|
+
},
|
|
72
|
+
signAuthorization: function (parameters) {
|
|
73
|
+
return signAuthorization(client, parameters, organizationId, signWith);
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
async function createAccount(input) {
|
|
78
|
+
const { client, organizationId, signWith } = input;
|
|
79
|
+
let { ethereumAddress } = input;
|
|
80
|
+
if (!signWith) {
|
|
81
|
+
throw new ZeroXKeyActivityError({
|
|
82
|
+
message: `Missing signWith parameter`,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
if (viem.isAddress(signWith)) {
|
|
86
|
+
// override provided `ethereumAddress`
|
|
87
|
+
ethereumAddress = signWith;
|
|
88
|
+
}
|
|
89
|
+
else if (!ethereumAddress) {
|
|
90
|
+
// we have a private key ID, but not an ethereumAddress
|
|
91
|
+
const data = await client.getPrivateKey({
|
|
92
|
+
privateKeyId: signWith,
|
|
93
|
+
organizationId: organizationId,
|
|
94
|
+
});
|
|
95
|
+
ethereumAddress = data.privateKey.addresses.find((item) => item.format === "ADDRESS_FORMAT_ETHEREUM")?.address;
|
|
96
|
+
if (typeof ethereumAddress !== "string" || !ethereumAddress) {
|
|
97
|
+
throw new ZeroXKeyActivityError({
|
|
98
|
+
message: `Unable to find Ethereum address for key ${signWith} under organization ${organizationId}`,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return createAccountWithAddress({
|
|
103
|
+
client,
|
|
104
|
+
organizationId,
|
|
105
|
+
signWith,
|
|
106
|
+
ethereumAddress,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Creates a new Custom Account backed by a ZeroXKey API key.
|
|
111
|
+
* @deprecated use {@link createAccount} instead.
|
|
112
|
+
*/
|
|
113
|
+
async function createApiKeyAccount(config) {
|
|
114
|
+
const { apiPublicKey, apiPrivateKey, baseUrl, organizationId, privateKeyId } = config;
|
|
115
|
+
const stamper = new apiKeyStamper.ApiKeyStamper({
|
|
116
|
+
apiPublicKey: apiPublicKey,
|
|
117
|
+
apiPrivateKey: apiPrivateKey,
|
|
118
|
+
});
|
|
119
|
+
const client = new http.ZeroXKeyClient({
|
|
120
|
+
baseUrl: baseUrl,
|
|
121
|
+
}, stamper);
|
|
122
|
+
const data = await client.getPrivateKey({
|
|
123
|
+
privateKeyId: privateKeyId,
|
|
124
|
+
organizationId: organizationId,
|
|
125
|
+
});
|
|
126
|
+
const ethereumAddress = data.privateKey.addresses.find((item) => item.format === "ADDRESS_FORMAT_ETHEREUM")?.address;
|
|
127
|
+
if (typeof ethereumAddress !== "string" || !ethereumAddress) {
|
|
128
|
+
throw new http.ZeroXKeyActivityError({
|
|
129
|
+
message: `Unable to find Ethereum address for key ${privateKeyId} under organization ${organizationId}`,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
return accounts.toAccount({
|
|
133
|
+
address: ethereumAddress,
|
|
134
|
+
sign: function ({ hash }) {
|
|
135
|
+
return signMessage(client, hash, organizationId, privateKeyId);
|
|
136
|
+
},
|
|
137
|
+
signMessage: function ({ message, }) {
|
|
138
|
+
const hashedMessage = viem.hashMessage(message);
|
|
139
|
+
return signMessage(client, hashedMessage, organizationId, privateKeyId);
|
|
140
|
+
},
|
|
141
|
+
signTransaction: function (transaction, options) {
|
|
142
|
+
const serializer = options?.serializer ??
|
|
143
|
+
viem.serializeTransaction;
|
|
144
|
+
return signTransaction(client, transaction, serializer, organizationId, privateKeyId);
|
|
145
|
+
},
|
|
146
|
+
signTypedData: function (typedData) {
|
|
147
|
+
return signTypedData(client, typedData, organizationId, privateKeyId);
|
|
148
|
+
},
|
|
149
|
+
signAuthorization: function (parameters) {
|
|
150
|
+
return signAuthorization(client, parameters, organizationId, privateKeyId);
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
async function signAuthorization(client, parameters, organizationId, signWith) {
|
|
155
|
+
const { chainId, nonce, to = "object" } = parameters;
|
|
156
|
+
const address = parameters.contractAddress ?? parameters.address;
|
|
157
|
+
if (!address) {
|
|
158
|
+
throw new ZeroXKeyActivityError({
|
|
159
|
+
message: "Unable to sign authorization: address is undefined.",
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
const signature = await signMessageWithErrorWrapping(client, JSON.stringify({
|
|
163
|
+
address,
|
|
164
|
+
chainId,
|
|
165
|
+
nonce,
|
|
166
|
+
}), organizationId, signWith, "PAYLOAD_ENCODING_EIP7702_AUTHORIZATION", to);
|
|
167
|
+
if (to === "object")
|
|
168
|
+
return {
|
|
169
|
+
address,
|
|
170
|
+
chainId,
|
|
171
|
+
nonce,
|
|
172
|
+
r: `${signature.r}`,
|
|
173
|
+
s: `${signature.s}`,
|
|
174
|
+
v: BigInt(signature.v),
|
|
175
|
+
yParity: Number(signature.v),
|
|
176
|
+
};
|
|
177
|
+
return signature;
|
|
178
|
+
}
|
|
179
|
+
async function signMessage(client, message, organizationId, signWith) {
|
|
180
|
+
const signedMessage = await signMessageWithErrorWrapping(client, message, organizationId, signWith);
|
|
181
|
+
return `${signedMessage}`;
|
|
182
|
+
}
|
|
183
|
+
async function signTransaction(client, transaction, serializer, organizationId, signWith) {
|
|
184
|
+
// Note: for Type 3 transactions, we are specifically handling parsing for payloads containing only the transaction payload body, without any wrappers around blobs, commitments, or proofs.
|
|
185
|
+
// See more: https://github.com/wevm/viem/blob/3ef19eac4963014fb20124d1e46d1715bed5509f/src/accounts/utils/signTransaction.ts#L54-L55
|
|
186
|
+
const signableTransaction = transaction.type === "eip4844"
|
|
187
|
+
? { ...transaction, sidecars: false }
|
|
188
|
+
: transaction;
|
|
189
|
+
const serializedTx = await serializer(signableTransaction);
|
|
190
|
+
const nonHexPrefixedSerializedTx = serializedTx.replace(/^0x/, "");
|
|
191
|
+
// Automatically detect transaction type from the serialized payload
|
|
192
|
+
const transactionType = detectTransactionType(nonHexPrefixedSerializedTx);
|
|
193
|
+
const signedTx = await signTransactionWithErrorWrapping(client, nonHexPrefixedSerializedTx, organizationId, signWith, transactionType);
|
|
194
|
+
if (transaction.type === "eip4844") {
|
|
195
|
+
// Grab components of the signature
|
|
196
|
+
const { r, s, v } = viem.parseTransaction(signedTx);
|
|
197
|
+
// Recombine with the original transaction
|
|
198
|
+
return viem.serializeTransaction(transaction, {
|
|
199
|
+
r: r,
|
|
200
|
+
s: s,
|
|
201
|
+
v: v,
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
return signedTx;
|
|
205
|
+
}
|
|
206
|
+
async function signTypedData(client, data, organizationId, signWith) {
|
|
207
|
+
return (await signMessageWithErrorWrapping(client, viem.serializeTypedData(data), organizationId, signWith, "PAYLOAD_ENCODING_EIP712", "hex"));
|
|
208
|
+
}
|
|
209
|
+
async function signTransactionWithErrorWrapping(client, unsignedTransaction, organizationId, signWith, transactionType) {
|
|
210
|
+
let signedTx;
|
|
211
|
+
try {
|
|
212
|
+
signedTx = await signTransactionImpl(client, unsignedTransaction, organizationId, signWith, transactionType);
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
// Wrap ZeroXKey error in Viem-specific error
|
|
216
|
+
if (error instanceof http.ZeroXKeyActivityError) {
|
|
217
|
+
throw new ZeroXKeyActivityError({
|
|
218
|
+
message: error.message,
|
|
219
|
+
activityId: error.activityId,
|
|
220
|
+
activityStatus: error.activityStatus,
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
if (error instanceof http.ZeroXKeyActivityConsensusNeededError) {
|
|
224
|
+
throw new ZeroXKeyConsensusNeededError({
|
|
225
|
+
message: error.message,
|
|
226
|
+
activityId: error.activityId,
|
|
227
|
+
activityStatus: error.activityStatus,
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
throw new ZeroXKeyActivityError({
|
|
231
|
+
message: `Failed to sign: ${error.message}`,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
return `0x${signedTx}`;
|
|
235
|
+
}
|
|
236
|
+
async function signTransactionImpl(client, unsignedTransaction, organizationId, signWith, transactionType) {
|
|
237
|
+
if (http.isHttpClient(client)) {
|
|
238
|
+
const { activity } = await client.signTransaction({
|
|
239
|
+
type: "ACTIVITY_TYPE_SIGN_TRANSACTION_V2",
|
|
240
|
+
organizationId: organizationId,
|
|
241
|
+
parameters: {
|
|
242
|
+
signWith,
|
|
243
|
+
type: transactionType ?? "TRANSACTION_TYPE_ETHEREUM",
|
|
244
|
+
unsignedTransaction: unsignedTransaction,
|
|
245
|
+
},
|
|
246
|
+
timestampMs: String(Date.now()), // millisecond timestamp
|
|
247
|
+
});
|
|
248
|
+
http.assertActivityCompleted(activity);
|
|
249
|
+
return http.assertNonNull(activity?.result?.signTransactionResult?.signedTransaction);
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
const { activity, signedTransaction } = await client.signTransaction({
|
|
253
|
+
organizationId,
|
|
254
|
+
signWith,
|
|
255
|
+
type: transactionType ?? "TRANSACTION_TYPE_ETHEREUM",
|
|
256
|
+
unsignedTransaction: unsignedTransaction,
|
|
257
|
+
});
|
|
258
|
+
http.assertActivityCompleted(activity /* Type casting is ok here. The invalid types are both actually strings. TS is too strict here! */);
|
|
259
|
+
return http.assertNonNull(signedTransaction);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
async function signMessageWithErrorWrapping(client, message, organizationId, signWith, payloadEncoding = "PAYLOAD_ENCODING_HEXADECIMAL", to = "hex") {
|
|
263
|
+
let signedMessage;
|
|
264
|
+
try {
|
|
265
|
+
signedMessage = await signMessageImpl(client, message, organizationId, signWith, payloadEncoding, to);
|
|
266
|
+
}
|
|
267
|
+
catch (error) {
|
|
268
|
+
// Wrap ZeroXKey error in Viem-specific error
|
|
269
|
+
if (error instanceof http.ZeroXKeyActivityError) {
|
|
270
|
+
throw new ZeroXKeyActivityError({
|
|
271
|
+
message: error.message,
|
|
272
|
+
activityId: error.activityId,
|
|
273
|
+
activityStatus: error.activityStatus,
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
if (error instanceof http.ZeroXKeyActivityConsensusNeededError) {
|
|
277
|
+
throw new ZeroXKeyConsensusNeededError({
|
|
278
|
+
message: error.message,
|
|
279
|
+
activityId: error.activityId,
|
|
280
|
+
activityStatus: error.activityStatus,
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
throw new ZeroXKeyActivityError({
|
|
284
|
+
message: `Failed to sign: ${error.message}`,
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
return signedMessage;
|
|
288
|
+
}
|
|
289
|
+
async function signMessageImpl(client, message, organizationId, signWith, payloadEncoding, to) {
|
|
290
|
+
let result;
|
|
291
|
+
if (http.isHttpClient(client)) {
|
|
292
|
+
const { activity } = await client.signRawPayload({
|
|
293
|
+
type: "ACTIVITY_TYPE_SIGN_RAW_PAYLOAD_V2",
|
|
294
|
+
organizationId: organizationId,
|
|
295
|
+
parameters: {
|
|
296
|
+
signWith,
|
|
297
|
+
payload: message,
|
|
298
|
+
encoding: payloadEncoding,
|
|
299
|
+
hashFunction: "HASH_FUNCTION_NO_OP",
|
|
300
|
+
},
|
|
301
|
+
timestampMs: String(Date.now()), // millisecond timestamp
|
|
302
|
+
});
|
|
303
|
+
http.assertActivityCompleted(activity);
|
|
304
|
+
result = http.assertNonNull(activity?.result?.signRawPayloadResult);
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
const { activity, r, s, v } = await client.signRawPayload({
|
|
308
|
+
organizationId,
|
|
309
|
+
signWith,
|
|
310
|
+
payload: message,
|
|
311
|
+
encoding: payloadEncoding,
|
|
312
|
+
hashFunction: "HASH_FUNCTION_NO_OP",
|
|
313
|
+
});
|
|
314
|
+
http.assertActivityCompleted(activity /* Type casting is ok here. The invalid types are both actually strings. TS is too strict here! */);
|
|
315
|
+
result = {
|
|
316
|
+
r,
|
|
317
|
+
s,
|
|
318
|
+
v,
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
if (to === "object") {
|
|
322
|
+
return {
|
|
323
|
+
r: `0x${result.r}`,
|
|
324
|
+
s: `0x${result.s}`,
|
|
325
|
+
v: BigInt(result.v),
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
return http.assertNonNull(serializeSignature(result, to));
|
|
329
|
+
}
|
|
330
|
+
// Modified from Viem implementation:
|
|
331
|
+
// https://github.com/wevm/viem/blob/c8378d22f692f48edde100693159874702f36330/src/utils/signature/serializeSignature.ts#L38-L39
|
|
332
|
+
function serializeSignature(sig, to = "hex") {
|
|
333
|
+
const { r: rString, s: sString, v: vString } = sig;
|
|
334
|
+
const r = `0x${rString}`;
|
|
335
|
+
const s = `0x${sString}`;
|
|
336
|
+
const v = BigInt(vString);
|
|
337
|
+
// ZeroXKey's `v` returned can be used as a proxy for yParity
|
|
338
|
+
const yParity_ = v;
|
|
339
|
+
const signature = `0x${new secp256k1.secp256k1.Signature(viem.hexToBigInt(r), viem.hexToBigInt(s)).toCompactHex()}${yParity_ === 0n ? "1b" : "1c"}`;
|
|
340
|
+
if (to === "hex")
|
|
341
|
+
return signature;
|
|
342
|
+
return viem.hexToBytes(signature);
|
|
343
|
+
}
|
|
344
|
+
function isZeroXKeyActivityConsensusNeededError(error) {
|
|
345
|
+
return (typeof error.walk === "function" &&
|
|
346
|
+
error.walk((e) => {
|
|
347
|
+
return e instanceof ZeroXKeyConsensusNeededError;
|
|
348
|
+
}));
|
|
349
|
+
}
|
|
350
|
+
function isZeroXKeyActivityError(error) {
|
|
351
|
+
return (typeof error.walk === "function" &&
|
|
352
|
+
error.walk((e) => {
|
|
353
|
+
return e instanceof ZeroXKeyActivityError;
|
|
354
|
+
}));
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
exports.ZeroXKeyActivityError = ZeroXKeyActivityError;
|
|
358
|
+
exports.ZeroXKeyConsensusNeededError = ZeroXKeyConsensusNeededError;
|
|
359
|
+
exports.createAccount = createAccount;
|
|
360
|
+
exports.createAccountWithAddress = createAccountWithAddress;
|
|
361
|
+
exports.createApiKeyAccount = createApiKeyAccount;
|
|
362
|
+
exports.isZeroXKeyActivityConsensusNeededError = isZeroXKeyActivityConsensusNeededError;
|
|
363
|
+
exports.isZeroXKeyActivityError = isZeroXKeyActivityError;
|
|
364
|
+
exports.serializeSignature = serializeSignature;
|
|
365
|
+
exports.signAuthorization = signAuthorization;
|
|
366
|
+
exports.signMessage = signMessage;
|
|
367
|
+
exports.signTransaction = signTransaction;
|
|
368
|
+
exports.signTypedData = signTypedData;
|
|
369
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":[null],"names":["BaseError","ZeroXKeyHttpActivityError","isAddress","toAccount","hashMessage","serializeTransaction","ApiKeyStamper","ZeroXKeyClient","parseTransaction","serializeTypedData","ZeroXKeyHttpActivityConsensusNeededError","isHttpClient","assertActivityCompleted","assertNonNull","secp256k1","hexToBigInt","hexToBytes"],"mappings":";;;;;;;;AAoEA;;;;AAIG;AACH,SAAS,qBAAqB,CAAC,YAAoB,EAAA;;AAEjD,IA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hexToBigInt, hexToBytes } from 'viem';
|
|
2
|
+
import { toAccount } from 'viem/accounts';
|
|
3
|
+
import { secp256k1 } from '@noble/curves/secp256k1';
|
|
4
|
+
import { ZeroXKeyActivityError as ZeroXKeyActivityError$1, ZeroXKeyClient, ZeroXKeyActivityConsensusNeededError, isHttpClient, assertActivityCompleted, assertNonNull } from '@0xkey-io/http';
|
|
5
|
+
import { ApiKeyStamper } from '@0xkey-io/api-key-stamper';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Detects the transaction type from a serialized transaction payload.
|
|
9
|
+
* @param serializedTx - The hex-encoded transaction (without 0x prefix)
|
|
10
|
+
* @returns The transaction type to use with ZeroXKey API
|
|
11
|
+
*/
|
|
12
|
+
function detectTransactionType(serializedTx) {
|
|
13
|
+
// Check if the transaction starts with 0x76 (Tempo transaction)
|
|
14
|
+
if (serializedTx.startsWith("76")) {
|
|
15
|
+
return "TRANSACTION_TYPE_TEMPO";
|
|
16
|
+
}
|
|
17
|
+
// Default to Ethereum for all other transactions
|
|
18
|
+
return "TRANSACTION_TYPE_ETHEREUM";
|
|
19
|
+
}
|
|
20
|
+
class ZeroXKeyConsensusNeededError extends BaseError {
|
|
21
|
+
constructor({ message = "ZeroXKey activity requires consensus.", activityId, activityStatus, }) {
|
|
22
|
+
super(message);
|
|
23
|
+
this.name = "ZeroXKeyConsensusNeededError";
|
|
24
|
+
this.activityId = activityId;
|
|
25
|
+
this.activityStatus = activityStatus;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
class ZeroXKeyActivityError extends BaseError {
|
|
29
|
+
constructor({ message = "Received unexpected ZeroXKey activity status.", activityId, activityStatus, }) {
|
|
30
|
+
super(message);
|
|
31
|
+
this.name = "ZeroXKeyActivityError";
|
|
32
|
+
this.activityId = activityId;
|
|
33
|
+
this.activityStatus = activityStatus;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function createAccountWithAddress(input) {
|
|
37
|
+
const { client, organizationId, signWith } = input;
|
|
38
|
+
let { ethereumAddress } = input;
|
|
39
|
+
if (!signWith) {
|
|
40
|
+
throw new ZeroXKeyActivityError$1({
|
|
41
|
+
message: `Missing signWith parameter`,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (isAddress(signWith)) {
|
|
45
|
+
// override provided `ethereumAddress`
|
|
46
|
+
ethereumAddress = signWith;
|
|
47
|
+
}
|
|
48
|
+
else if (!ethereumAddress) {
|
|
49
|
+
throw new ZeroXKeyActivityError({
|
|
50
|
+
message: `Missing ethereumAddress parameter`,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return toAccount({
|
|
54
|
+
address: ethereumAddress,
|
|
55
|
+
sign: function ({ hash }) {
|
|
56
|
+
return signMessage(client, hash, organizationId, signWith);
|
|
57
|
+
},
|
|
58
|
+
signMessage: function ({ message, }) {
|
|
59
|
+
const hashedMessage = hashMessage(message);
|
|
60
|
+
return signMessage(client, hashedMessage, organizationId, signWith);
|
|
61
|
+
},
|
|
62
|
+
signTransaction: function (transaction, options) {
|
|
63
|
+
const serializer = options?.serializer ??
|
|
64
|
+
serializeTransaction;
|
|
65
|
+
return signTransaction(client, transaction, serializer, organizationId, signWith);
|
|
66
|
+
},
|
|
67
|
+
signTypedData: function (typedData) {
|
|
68
|
+
return signTypedData(client, typedData, organizationId, signWith);
|
|
69
|
+
},
|
|
70
|
+
signAuthorization: function (parameters) {
|
|
71
|
+
return signAuthorization(client, parameters, organizationId, signWith);
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
async function createAccount(input) {
|
|
76
|
+
const { client, organizationId, signWith } = input;
|
|
77
|
+
let { ethereumAddress } = input;
|
|
78
|
+
if (!signWith) {
|
|
79
|
+
throw new ZeroXKeyActivityError({
|
|
80
|
+
message: `Missing signWith parameter`,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (isAddress(signWith)) {
|
|
84
|
+
// override provided `ethereumAddress`
|
|
85
|
+
ethereumAddress = signWith;
|
|
86
|
+
}
|
|
87
|
+
else if (!ethereumAddress) {
|
|
88
|
+
// we have a private key ID, but not an ethereumAddress
|
|
89
|
+
const data = await client.getPrivateKey({
|
|
90
|
+
privateKeyId: signWith,
|
|
91
|
+
organizationId: organizationId,
|
|
92
|
+
});
|
|
93
|
+
ethereumAddress = data.privateKey.addresses.find((item) => item.format === "ADDRESS_FORMAT_ETHEREUM")?.address;
|
|
94
|
+
if (typeof ethereumAddress !== "string" || !ethereumAddress) {
|
|
95
|
+
throw new ZeroXKeyActivityError({
|
|
96
|
+
message: `Unable to find Ethereum address for key ${signWith} under organization ${organizationId}`,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return createAccountWithAddress({
|
|
101
|
+
client,
|
|
102
|
+
organizationId,
|
|
103
|
+
signWith,
|
|
104
|
+
ethereumAddress,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Creates a new Custom Account backed by a ZeroXKey API key.
|
|
109
|
+
* @deprecated use {@link createAccount} instead.
|
|
110
|
+
*/
|
|
111
|
+
async function createApiKeyAccount(config) {
|
|
112
|
+
const { apiPublicKey, apiPrivateKey, baseUrl, organizationId, privateKeyId } = config;
|
|
113
|
+
const stamper = new ApiKeyStamper({
|
|
114
|
+
apiPublicKey: apiPublicKey,
|
|
115
|
+
apiPrivateKey: apiPrivateKey,
|
|
116
|
+
});
|
|
117
|
+
const client = new ZeroXKeyClient({
|
|
118
|
+
baseUrl: baseUrl,
|
|
119
|
+
}, stamper);
|
|
120
|
+
const data = await client.getPrivateKey({
|
|
121
|
+
privateKeyId: privateKeyId,
|
|
122
|
+
organizationId: organizationId,
|
|
123
|
+
});
|
|
124
|
+
const ethereumAddress = data.privateKey.addresses.find((item) => item.format === "ADDRESS_FORMAT_ETHEREUM")?.address;
|
|
125
|
+
if (typeof ethereumAddress !== "string" || !ethereumAddress) {
|
|
126
|
+
throw new ZeroXKeyActivityError$1({
|
|
127
|
+
message: `Unable to find Ethereum address for key ${privateKeyId} under organization ${organizationId}`,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
return toAccount({
|
|
131
|
+
address: ethereumAddress,
|
|
132
|
+
sign: function ({ hash }) {
|
|
133
|
+
return signMessage(client, hash, organizationId, privateKeyId);
|
|
134
|
+
},
|
|
135
|
+
signMessage: function ({ message, }) {
|
|
136
|
+
const hashedMessage = hashMessage(message);
|
|
137
|
+
return signMessage(client, hashedMessage, organizationId, privateKeyId);
|
|
138
|
+
},
|
|
139
|
+
signTransaction: function (transaction, options) {
|
|
140
|
+
const serializer = options?.serializer ??
|
|
141
|
+
serializeTransaction;
|
|
142
|
+
return signTransaction(client, transaction, serializer, organizationId, privateKeyId);
|
|
143
|
+
},
|
|
144
|
+
signTypedData: function (typedData) {
|
|
145
|
+
return signTypedData(client, typedData, organizationId, privateKeyId);
|
|
146
|
+
},
|
|
147
|
+
signAuthorization: function (parameters) {
|
|
148
|
+
return signAuthorization(client, parameters, organizationId, privateKeyId);
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
async function signAuthorization(client, parameters, organizationId, signWith) {
|
|
153
|
+
const { chainId, nonce, to = "object" } = parameters;
|
|
154
|
+
const address = parameters.contractAddress ?? parameters.address;
|
|
155
|
+
if (!address) {
|
|
156
|
+
throw new ZeroXKeyActivityError({
|
|
157
|
+
message: "Unable to sign authorization: address is undefined.",
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
const signature = await signMessageWithErrorWrapping(client, JSON.stringify({
|
|
161
|
+
address,
|
|
162
|
+
chainId,
|
|
163
|
+
nonce,
|
|
164
|
+
}), organizationId, signWith, "PAYLOAD_ENCODING_EIP7702_AUTHORIZATION", to);
|
|
165
|
+
if (to === "object")
|
|
166
|
+
return {
|
|
167
|
+
address,
|
|
168
|
+
chainId,
|
|
169
|
+
nonce,
|
|
170
|
+
r: `${signature.r}`,
|
|
171
|
+
s: `${signature.s}`,
|
|
172
|
+
v: BigInt(signature.v),
|
|
173
|
+
yParity: Number(signature.v),
|
|
174
|
+
};
|
|
175
|
+
return signature;
|
|
176
|
+
}
|
|
177
|
+
async function signMessage(client, message, organizationId, signWith) {
|
|
178
|
+
const signedMessage = await signMessageWithErrorWrapping(client, message, organizationId, signWith);
|
|
179
|
+
return `${signedMessage}`;
|
|
180
|
+
}
|
|
181
|
+
async function signTransaction(client, transaction, serializer, organizationId, signWith) {
|
|
182
|
+
// Note: for Type 3 transactions, we are specifically handling parsing for payloads containing only the transaction payload body, without any wrappers around blobs, commitments, or proofs.
|
|
183
|
+
// See more: https://github.com/wevm/viem/blob/3ef19eac4963014fb20124d1e46d1715bed5509f/src/accounts/utils/signTransaction.ts#L54-L55
|
|
184
|
+
const signableTransaction = transaction.type === "eip4844"
|
|
185
|
+
? { ...transaction, sidecars: false }
|
|
186
|
+
: transaction;
|
|
187
|
+
const serializedTx = await serializer(signableTransaction);
|
|
188
|
+
const nonHexPrefixedSerializedTx = serializedTx.replace(/^0x/, "");
|
|
189
|
+
// Automatically detect transaction type from the serialized payload
|
|
190
|
+
const transactionType = detectTransactionType(nonHexPrefixedSerializedTx);
|
|
191
|
+
const signedTx = await signTransactionWithErrorWrapping(client, nonHexPrefixedSerializedTx, organizationId, signWith, transactionType);
|
|
192
|
+
if (transaction.type === "eip4844") {
|
|
193
|
+
// Grab components of the signature
|
|
194
|
+
const { r, s, v } = parseTransaction(signedTx);
|
|
195
|
+
// Recombine with the original transaction
|
|
196
|
+
return serializeTransaction(transaction, {
|
|
197
|
+
r: r,
|
|
198
|
+
s: s,
|
|
199
|
+
v: v,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
return signedTx;
|
|
203
|
+
}
|
|
204
|
+
async function signTypedData(client, data, organizationId, signWith) {
|
|
205
|
+
return (await signMessageWithErrorWrapping(client, serializeTypedData(data), organizationId, signWith, "PAYLOAD_ENCODING_EIP712", "hex"));
|
|
206
|
+
}
|
|
207
|
+
async function signTransactionWithErrorWrapping(client, unsignedTransaction, organizationId, signWith, transactionType) {
|
|
208
|
+
let signedTx;
|
|
209
|
+
try {
|
|
210
|
+
signedTx = await signTransactionImpl(client, unsignedTransaction, organizationId, signWith, transactionType);
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
// Wrap ZeroXKey error in Viem-specific error
|
|
214
|
+
if (error instanceof ZeroXKeyActivityError$1) {
|
|
215
|
+
throw new ZeroXKeyActivityError({
|
|
216
|
+
message: error.message,
|
|
217
|
+
activityId: error.activityId,
|
|
218
|
+
activityStatus: error.activityStatus,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
if (error instanceof ZeroXKeyActivityConsensusNeededError) {
|
|
222
|
+
throw new ZeroXKeyConsensusNeededError({
|
|
223
|
+
message: error.message,
|
|
224
|
+
activityId: error.activityId,
|
|
225
|
+
activityStatus: error.activityStatus,
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
throw new ZeroXKeyActivityError({
|
|
229
|
+
message: `Failed to sign: ${error.message}`,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
return `0x${signedTx}`;
|
|
233
|
+
}
|
|
234
|
+
async function signTransactionImpl(client, unsignedTransaction, organizationId, signWith, transactionType) {
|
|
235
|
+
if (isHttpClient(client)) {
|
|
236
|
+
const { activity } = await client.signTransaction({
|
|
237
|
+
type: "ACTIVITY_TYPE_SIGN_TRANSACTION_V2",
|
|
238
|
+
organizationId: organizationId,
|
|
239
|
+
parameters: {
|
|
240
|
+
signWith,
|
|
241
|
+
type: transactionType ?? "TRANSACTION_TYPE_ETHEREUM",
|
|
242
|
+
unsignedTransaction: unsignedTransaction,
|
|
243
|
+
},
|
|
244
|
+
timestampMs: String(Date.now()), // millisecond timestamp
|
|
245
|
+
});
|
|
246
|
+
assertActivityCompleted(activity);
|
|
247
|
+
return assertNonNull(activity?.result?.signTransactionResult?.signedTransaction);
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
const { activity, signedTransaction } = await client.signTransaction({
|
|
251
|
+
organizationId,
|
|
252
|
+
signWith,
|
|
253
|
+
type: transactionType ?? "TRANSACTION_TYPE_ETHEREUM",
|
|
254
|
+
unsignedTransaction: unsignedTransaction,
|
|
255
|
+
});
|
|
256
|
+
assertActivityCompleted(activity /* Type casting is ok here. The invalid types are both actually strings. TS is too strict here! */);
|
|
257
|
+
return assertNonNull(signedTransaction);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
async function signMessageWithErrorWrapping(client, message, organizationId, signWith, payloadEncoding = "PAYLOAD_ENCODING_HEXADECIMAL", to = "hex") {
|
|
261
|
+
let signedMessage;
|
|
262
|
+
try {
|
|
263
|
+
signedMessage = await signMessageImpl(client, message, organizationId, signWith, payloadEncoding, to);
|
|
264
|
+
}
|
|
265
|
+
catch (error) {
|
|
266
|
+
// Wrap ZeroXKey error in Viem-specific error
|
|
267
|
+
if (error instanceof ZeroXKeyActivityError$1) {
|
|
268
|
+
throw new ZeroXKeyActivityError({
|
|
269
|
+
message: error.message,
|
|
270
|
+
activityId: error.activityId,
|
|
271
|
+
activityStatus: error.activityStatus,
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
if (error instanceof ZeroXKeyActivityConsensusNeededError) {
|
|
275
|
+
throw new ZeroXKeyConsensusNeededError({
|
|
276
|
+
message: error.message,
|
|
277
|
+
activityId: error.activityId,
|
|
278
|
+
activityStatus: error.activityStatus,
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
throw new ZeroXKeyActivityError({
|
|
282
|
+
message: `Failed to sign: ${error.message}`,
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
return signedMessage;
|
|
286
|
+
}
|
|
287
|
+
async function signMessageImpl(client, message, organizationId, signWith, payloadEncoding, to) {
|
|
288
|
+
let result;
|
|
289
|
+
if (isHttpClient(client)) {
|
|
290
|
+
const { activity } = await client.signRawPayload({
|
|
291
|
+
type: "ACTIVITY_TYPE_SIGN_RAW_PAYLOAD_V2",
|
|
292
|
+
organizationId: organizationId,
|
|
293
|
+
parameters: {
|
|
294
|
+
signWith,
|
|
295
|
+
payload: message,
|
|
296
|
+
encoding: payloadEncoding,
|
|
297
|
+
hashFunction: "HASH_FUNCTION_NO_OP",
|
|
298
|
+
},
|
|
299
|
+
timestampMs: String(Date.now()), // millisecond timestamp
|
|
300
|
+
});
|
|
301
|
+
assertActivityCompleted(activity);
|
|
302
|
+
result = assertNonNull(activity?.result?.signRawPayloadResult);
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
const { activity, r, s, v } = await client.signRawPayload({
|
|
306
|
+
organizationId,
|
|
307
|
+
signWith,
|
|
308
|
+
payload: message,
|
|
309
|
+
encoding: payloadEncoding,
|
|
310
|
+
hashFunction: "HASH_FUNCTION_NO_OP",
|
|
311
|
+
});
|
|
312
|
+
assertActivityCompleted(activity /* Type casting is ok here. The invalid types are both actually strings. TS is too strict here! */);
|
|
313
|
+
result = {
|
|
314
|
+
r,
|
|
315
|
+
s,
|
|
316
|
+
v,
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
if (to === "object") {
|
|
320
|
+
return {
|
|
321
|
+
r: `0x${result.r}`,
|
|
322
|
+
s: `0x${result.s}`,
|
|
323
|
+
v: BigInt(result.v),
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
return assertNonNull(serializeSignature(result, to));
|
|
327
|
+
}
|
|
328
|
+
// Modified from Viem implementation:
|
|
329
|
+
// https://github.com/wevm/viem/blob/c8378d22f692f48edde100693159874702f36330/src/utils/signature/serializeSignature.ts#L38-L39
|
|
330
|
+
function serializeSignature(sig, to = "hex") {
|
|
331
|
+
const { r: rString, s: sString, v: vString } = sig;
|
|
332
|
+
const r = `0x${rString}`;
|
|
333
|
+
const s = `0x${sString}`;
|
|
334
|
+
const v = BigInt(vString);
|
|
335
|
+
// ZeroXKey's `v` returned can be used as a proxy for yParity
|
|
336
|
+
const yParity_ = v;
|
|
337
|
+
const signature = `0x${new secp256k1.Signature(hexToBigInt(r), hexToBigInt(s)).toCompactHex()}${yParity_ === 0n ? "1b" : "1c"}`;
|
|
338
|
+
if (to === "hex")
|
|
339
|
+
return signature;
|
|
340
|
+
return hexToBytes(signature);
|
|
341
|
+
}
|
|
342
|
+
function isZeroXKeyActivityConsensusNeededError(error) {
|
|
343
|
+
return (typeof error.walk === "function" &&
|
|
344
|
+
error.walk((e) => {
|
|
345
|
+
return e instanceof ZeroXKeyConsensusNeededError;
|
|
346
|
+
}));
|
|
347
|
+
}
|
|
348
|
+
function isZeroXKeyActivityError(error) {
|
|
349
|
+
return (typeof error.walk === "function" &&
|
|
350
|
+
error.walk((e) => {
|
|
351
|
+
return e instanceof ZeroXKeyActivityError;
|
|
352
|
+
}));
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export { ZeroXKeyActivityError, ZeroXKeyConsensusNeededError, createAccount, createAccountWithAddress, createApiKeyAccount, isZeroXKeyActivityConsensusNeededError, isZeroXKeyActivityError, serializeSignature, signAuthorization, signMessage, signTransaction, signTypedData };
|
|
356
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":[null],"names":["ZeroXKeyHttpActivityError","ZeroXKeyHttpActivityConsensusNeededError"],"mappings":";;;;;;AAoEA;;;;AAIG;AACH,SAAS,qBAAqB,CAAC,YAAoB,EAAA;;AAEjD,IAAA,IAAI,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;AACjC,QAAA,OAAO,wBAA4C;IACrD;;AAGA,IAAA,OAAO,2BAA2B;AACpC;AAEM,MAAO,4BAA6B,SAAQ,SAAS,CAAA;IAMzD,WAAA,CAAY,EACV,OAAO,GAAG,uCAAuC,EACjD,UAAU,EACV,cAAc,GAKf,EAAA;QACC,KAAK,CAAC,OAAO,CAAC;QAdP,IAAA,CAAA,IAAI,GAAG,8BAA8B;AAe5C,QAAA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AG,CAAC;AAElB,IAAA,MAAM,SAAS,GAAG,CAAA,EAAA,EAAK,IAAI,SAAS,CAAC,SAAS,CAC5C,WAAW,CAAC,CAAC,CAAC,EACd,WAAW,CAAC,CAAC,CAAC,CACf,CAAC,YAAY,EAAE,CAAA,EAAG,QAAQ,KAAK,EAAE,GAAG,IAAI,GAAG,IAAI,EAAW;IAE3D,IAAI,EAAE,KAAK,KAAK;AAAE,QAAA,OAAO,SAAS;AAClC,IAAA,OAAO,UAAU,CAAC,SAAS,CAAC;AAC9B;AAEM,SAAU,sCAAsC,CAAC,KAAU,EAAA;AAC/D,IAAA,QACE,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU;AAChC,QAAA,KAAK,CAAC,IAAI,CAAC,CAAC,CAAM,KAAI;YACpB,OAAO,CAAC,YAAY,4BAA4B;QAClD,CAAC,CAAC;AAEN;AAEM,SAAU,uBAAuB,CAAC,KAAU,EAAA;AAChD,IAAA,QACE,OAAO,KAAK,CAAC,IAAI,KAAK,UAAU;AAChC,QAAA,KAAK,CAAC,IAAI,CAAC,CAAC,CAAM,KAAI;YACpB,OAAO,CAAC,YAAY,qBAAqB;QAC3C,CAAC,CAAC;AAEN;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@0xkey-io/viem",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"module": "./dist/index.mjs",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.mjs",
|
|
10
|
+
"require": "./dist/index.js",
|
|
11
|
+
"default": "./dist/index.mjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"license": "Apache-2.0",
|
|
16
|
+
"description": "0xkey Helpers to work with Viem",
|
|
17
|
+
"keywords": [
|
|
18
|
+
"0xkey",
|
|
19
|
+
"Viem",
|
|
20
|
+
"custom account",
|
|
21
|
+
"account",
|
|
22
|
+
"wallet",
|
|
23
|
+
"signer"
|
|
24
|
+
],
|
|
25
|
+
"author": {
|
|
26
|
+
"name": "0xkey",
|
|
27
|
+
"url": "https://0xkey.com/"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/0xkey-io/sdk-js/tree/main/packages/viem",
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/0xkey-io/sdk-js/issues"
|
|
32
|
+
},
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/0xkey-io/sdk-js.git",
|
|
36
|
+
"directory": "packages/viem"
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist/",
|
|
40
|
+
"CHANGELOG.md",
|
|
41
|
+
"README.md"
|
|
42
|
+
],
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"viem": "^1.16.6 || ^2.24.2"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@noble/curves": "1.8.0",
|
|
51
|
+
"@openzeppelin/contracts": "^5.0.2",
|
|
52
|
+
"cross-fetch": "^4.0.0",
|
|
53
|
+
"@0xkey-io/api-key-stamper": "0.1.0",
|
|
54
|
+
"@0xkey-io/sdk-browser": "0.1.0",
|
|
55
|
+
"@0xkey-io/http": "0.1.0",
|
|
56
|
+
"@0xkey-io/sdk-server": "0.1.0",
|
|
57
|
+
"@0xkey-io/core": "0.1.0"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@types/jest": "^29.5.3",
|
|
61
|
+
"jest": "^29.3.1",
|
|
62
|
+
"typescript": "5.4.3",
|
|
63
|
+
"viem": "^2.24.2"
|
|
64
|
+
},
|
|
65
|
+
"engines": {
|
|
66
|
+
"node": ">=18.0.0"
|
|
67
|
+
},
|
|
68
|
+
"scripts": {
|
|
69
|
+
"build": "rollup -c",
|
|
70
|
+
"clean": "rimraf ./dist ./.cache",
|
|
71
|
+
"test": "jest --detectOpenHandles",
|
|
72
|
+
"anvil": "anvil",
|
|
73
|
+
"typecheck": "tsc -p tsconfig.typecheck.json",
|
|
74
|
+
"compile:contracts": "hardhat compile"
|
|
75
|
+
}
|
|
76
|
+
}
|