@universal-everything/sdk-core-viem 1.0.0-dev.cb4e80f
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/LICENSE +201 -0
- package/README.md +81 -0
- package/dist/index.d.ts +193 -0
- package/dist/index.js +239 -0
- package/package.json +38 -0
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 2023 LUKSO Blockchain GmbH
|
|
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,81 @@
|
|
|
1
|
+
# @universal-everything/sdk-core-viem
|
|
2
|
+
|
|
3
|
+
Drop-in [viem](https://viem.sh) `LocalAccount` adapter for a
|
|
4
|
+
WalletKit-managed wallet. The server-held private key appears as an
|
|
5
|
+
ordinary viem account — every `viem` helper that takes an account
|
|
6
|
+
works unchanged.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pnpm add @universal-everything/sdk-core @universal-everything/sdk-core-viem viem
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Quick start
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { WalletKitClient } from "@universal-everything/sdk-core";
|
|
18
|
+
import { createWalletKitAccount } from "@universal-everything/sdk-core-viem";
|
|
19
|
+
import { createWalletClient, http } from "viem";
|
|
20
|
+
import { lukso, luksoTestnet } from "viem/chains";
|
|
21
|
+
|
|
22
|
+
const client = new WalletKitClient({ baseUrl, getAccessToken });
|
|
23
|
+
const [wallet] = await client.listWallets();
|
|
24
|
+
|
|
25
|
+
const account = createWalletKitAccount(client, wallet);
|
|
26
|
+
|
|
27
|
+
const walletClient = createWalletClient({
|
|
28
|
+
account,
|
|
29
|
+
chain: luksoTestnet,
|
|
30
|
+
transport: http(),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const hash = await walletClient.sendTransaction({
|
|
34
|
+
to: "0x…",
|
|
35
|
+
value: 1_000_000_000_000_000n,
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Method routing
|
|
40
|
+
|
|
41
|
+
| viem call | Server endpoint |
|
|
42
|
+
| ------------------------- | ------------------------------- |
|
|
43
|
+
| `account.signMessage` | `POST /v1/sign/message` |
|
|
44
|
+
| `account.signTransaction` | `POST /v1/sign/transaction` |
|
|
45
|
+
| `account.signTypedData` | *(not supported yet — throws)* |
|
|
46
|
+
|
|
47
|
+
`signMessage` handles both forms of viem's `SignableMessage`:
|
|
48
|
+
|
|
49
|
+
- `{ message: "hello" }` → sent as `utf-8` encoding.
|
|
50
|
+
- `{ message: { raw: Uint8Array } }` → hex-encoded.
|
|
51
|
+
- `{ message: { raw: "0xdead…" } }` → passed through as hex.
|
|
52
|
+
|
|
53
|
+
`signTransaction` maps viem's bigint fields to decimal strings on the
|
|
54
|
+
wire, then returns the RLP-serialized signed tx verbatim so
|
|
55
|
+
`viem`'s `sendRawTransaction` / `recoverTransactionAddress` work
|
|
56
|
+
unchanged.
|
|
57
|
+
|
|
58
|
+
`signTypedData` throws because the relayer has no
|
|
59
|
+
`/v1/sign/typed-data` endpoint yet. Track in M11.
|
|
60
|
+
|
|
61
|
+
## Privy per-op authorization
|
|
62
|
+
|
|
63
|
+
For user-owned Privy wallets, each sign call needs a fresh per-op
|
|
64
|
+
authorization signature. Pass `getOpContext` — it's invoked
|
|
65
|
+
immediately before each call:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
const account = createWalletKitAccount(client, wallet, {
|
|
69
|
+
getOpContext: async () => {
|
|
70
|
+
const sig = await privy.generateAuthorizationSignature(payload);
|
|
71
|
+
return {
|
|
72
|
+
authorizationSignature: sig,
|
|
73
|
+
requestExpiry: Date.now() + 60_000,
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Return `null` from `getOpContext` (or omit it entirely) for
|
|
80
|
+
unauthenticated / non-Privy signing contexts — typically
|
|
81
|
+
`LocalKeyCustody` in tests and local dev.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { Hex, ControlProof, OpContext, WalletKitClient, Wallet } from '@universal-everything/sdk-core';
|
|
2
|
+
import { LocalAccount } from 'viem';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A1 control-proof helper. The relayer's external-controller deploy requires
|
|
6
|
+
* the caller to prove they hold `controllerAddress` by signing a canonical,
|
|
7
|
+
* nonce-bound message. This builds that exact message (byte-identical to the
|
|
8
|
+
* relayer's `buildControlProofMessage`) and packages the signature.
|
|
9
|
+
*
|
|
10
|
+
* The signing itself is caller-supplied (`signMessage`) so this works with any
|
|
11
|
+
* key source — a Privy embedded wallet, a wagmi `signMessage`, or a viem
|
|
12
|
+
* account — without this package depending on any of them.
|
|
13
|
+
*/
|
|
14
|
+
type ControlProofClaims = {
|
|
15
|
+
/** The Privy `did:privy:*` account the profile will be recorded under. */
|
|
16
|
+
subject: string;
|
|
17
|
+
/** The user-held controller being proven. */
|
|
18
|
+
controllerAddress: Hex;
|
|
19
|
+
/** CREATE2-predicted UP address for this deploy. */
|
|
20
|
+
predictedAddress: Hex;
|
|
21
|
+
/** Target chain id. */
|
|
22
|
+
chainId: number;
|
|
23
|
+
/** Exact deployment calldata (bound as a keccak256 hash). */
|
|
24
|
+
deploymentCalldata: Hex;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* The exact string the controller signs. MUST stay byte-identical to the
|
|
28
|
+
* relayer's `buildControlProofMessage` (apps/relayer/src/services/control-proof.ts)
|
|
29
|
+
* or the recovered signer won't match and the deploy is rejected.
|
|
30
|
+
*/
|
|
31
|
+
declare function buildControlProofMessage(claims: ControlProofClaims, nonce: string, issuedAtUnix: number): string;
|
|
32
|
+
/**
|
|
33
|
+
* Build a {@link ControlProof} by signing the canonical message. Pair with
|
|
34
|
+
* `client.getNonce()` for the nonce and `Math.floor(Date.now() / 1000)` for
|
|
35
|
+
* `issuedAtUnix`. `signMessage` should EIP-191 personal_sign the string (e.g.
|
|
36
|
+
* wagmi `signMessage({ message })`, viem `account.signMessage({ message })`,
|
|
37
|
+
* or Privy).
|
|
38
|
+
*/
|
|
39
|
+
declare function buildControlProof(claims: ControlProofClaims, nonce: string, issuedAtUnix: number, signMessage: (message: string) => Promise<Hex>): Promise<ControlProof>;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Client-side LSP-23 CREATE2 helpers — build the `deployERC1167Proxies`
|
|
43
|
+
* calldata for a given salt and derive the resulting Universal Profile
|
|
44
|
+
* address WITHOUT a chain roundtrip. This lets an onboarding client "vary the
|
|
45
|
+
* salt" to offer a choice of profile addresses (identicons) before deploying.
|
|
46
|
+
*
|
|
47
|
+
* The derivation is byte-identical to the relayer's server-side check
|
|
48
|
+
* (`apps/relayer/src/services/up-create2.ts`): same salt construction, same
|
|
49
|
+
* EIP-1167 minimal-proxy bytecode template. A `predictedAddress` computed here
|
|
50
|
+
* will match what the relayer independently re-derives from the same calldata.
|
|
51
|
+
*/
|
|
52
|
+
/**
|
|
53
|
+
* LSP-23 `deployERC1167Proxies` ABI fragment (stable per the LSP-23 spec —
|
|
54
|
+
* hardcoded to avoid the `@lukso/lsp23-contracts` artifact dependency).
|
|
55
|
+
*/
|
|
56
|
+
declare const DEPLOY_ERC1167_PROXIES_ABI: readonly [{
|
|
57
|
+
readonly type: "function";
|
|
58
|
+
readonly name: "deployERC1167Proxies";
|
|
59
|
+
readonly stateMutability: "payable";
|
|
60
|
+
readonly inputs: readonly [{
|
|
61
|
+
readonly name: "primaryContractDeploymentInit";
|
|
62
|
+
readonly type: "tuple";
|
|
63
|
+
readonly components: readonly [{
|
|
64
|
+
readonly name: "salt";
|
|
65
|
+
readonly type: "bytes32";
|
|
66
|
+
}, {
|
|
67
|
+
readonly name: "fundingAmount";
|
|
68
|
+
readonly type: "uint256";
|
|
69
|
+
}, {
|
|
70
|
+
readonly name: "implementationContract";
|
|
71
|
+
readonly type: "address";
|
|
72
|
+
}, {
|
|
73
|
+
readonly name: "initializationCalldata";
|
|
74
|
+
readonly type: "bytes";
|
|
75
|
+
}];
|
|
76
|
+
}, {
|
|
77
|
+
readonly name: "secondaryContractDeploymentInit";
|
|
78
|
+
readonly type: "tuple";
|
|
79
|
+
readonly components: readonly [{
|
|
80
|
+
readonly name: "fundingAmount";
|
|
81
|
+
readonly type: "uint256";
|
|
82
|
+
}, {
|
|
83
|
+
readonly name: "implementationContract";
|
|
84
|
+
readonly type: "address";
|
|
85
|
+
}, {
|
|
86
|
+
readonly name: "initializationCalldata";
|
|
87
|
+
readonly type: "bytes";
|
|
88
|
+
}, {
|
|
89
|
+
readonly name: "addPrimaryContractAddress";
|
|
90
|
+
readonly type: "bool";
|
|
91
|
+
}, {
|
|
92
|
+
readonly name: "extraInitializationParams";
|
|
93
|
+
readonly type: "bytes";
|
|
94
|
+
}];
|
|
95
|
+
}, {
|
|
96
|
+
readonly name: "postDeploymentModule";
|
|
97
|
+
readonly type: "address";
|
|
98
|
+
}, {
|
|
99
|
+
readonly name: "postDeploymentModuleCalldata";
|
|
100
|
+
readonly type: "bytes";
|
|
101
|
+
}];
|
|
102
|
+
readonly outputs: readonly [{
|
|
103
|
+
readonly name: "primaryContractAddress";
|
|
104
|
+
readonly type: "address";
|
|
105
|
+
}, {
|
|
106
|
+
readonly name: "secondaryContractAddress";
|
|
107
|
+
readonly type: "address";
|
|
108
|
+
}];
|
|
109
|
+
}];
|
|
110
|
+
/** Inputs to build a `deployERC1167Proxies` calldata. Only `salt` typically
|
|
111
|
+
* varies between identicon candidates; the rest are fixed per chain/profile. */
|
|
112
|
+
type Lsp23DeploymentParams = {
|
|
113
|
+
/** CREATE2 salt — vary this to get different profile addresses. */
|
|
114
|
+
salt: Hex;
|
|
115
|
+
/** Primary proxy (UP) implementation. */
|
|
116
|
+
primaryImplementation: Hex;
|
|
117
|
+
/** Primary proxy init calldata (default "0x"). */
|
|
118
|
+
primaryInitializationCalldata?: Hex;
|
|
119
|
+
/** Primary funding amount (default 0). */
|
|
120
|
+
primaryFundingAmount?: bigint;
|
|
121
|
+
/** Secondary proxy (Key Manager) implementation. */
|
|
122
|
+
secondaryImplementation: Hex;
|
|
123
|
+
/** Secondary proxy init calldata (default "0x"). */
|
|
124
|
+
secondaryInitializationCalldata?: Hex;
|
|
125
|
+
/** Secondary funding amount (default 0). */
|
|
126
|
+
secondaryFundingAmount?: bigint;
|
|
127
|
+
/** Append the primary (UP) address to the secondary init (default true). */
|
|
128
|
+
addPrimaryContractAddress?: boolean;
|
|
129
|
+
/** Secondary extra init params (default "0x"). */
|
|
130
|
+
secondaryExtraInitializationParams?: Hex;
|
|
131
|
+
/** Post-deployment module (sets LSP-6 permissions / LSP-3 data). */
|
|
132
|
+
postDeploymentModule: Hex;
|
|
133
|
+
/** Post-deployment module calldata (the setData payload). */
|
|
134
|
+
postDeploymentModuleCalldata: Hex;
|
|
135
|
+
};
|
|
136
|
+
/** Encode `deployERC1167Proxies` calldata from the given params. */
|
|
137
|
+
declare function encodeDeploymentCalldata(params: Lsp23DeploymentParams): Hex;
|
|
138
|
+
/**
|
|
139
|
+
* Independently derive the LSP-23 CREATE2 profile address from
|
|
140
|
+
* `deploymentCalldata` + the chain's LSP-23 factory. Returns the lowercased
|
|
141
|
+
* `0x…` address. Throws if the calldata doesn't decode as
|
|
142
|
+
* `deployERC1167Proxies`.
|
|
143
|
+
*/
|
|
144
|
+
declare function deriveLsp23ProxyAddress(opts: {
|
|
145
|
+
factoryAddress: Hex;
|
|
146
|
+
deploymentCalldata: Hex;
|
|
147
|
+
}): Hex;
|
|
148
|
+
/**
|
|
149
|
+
* Build the calldata AND derive the predicted address in one call — the unit
|
|
150
|
+
* an onboarding client repeats while varying `params.salt` to render identicon
|
|
151
|
+
* candidates.
|
|
152
|
+
*/
|
|
153
|
+
declare function predictProfileAddress(factoryAddress: Hex, params: Lsp23DeploymentParams): {
|
|
154
|
+
deploymentCalldata: Hex;
|
|
155
|
+
predictedAddress: Hex;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* viem `LocalAccount` adapter for a WalletKit-managed wallet.
|
|
160
|
+
*
|
|
161
|
+
* Wraps an existing `Wallet` record so the server-held private key
|
|
162
|
+
* appears as an ordinary viem account. Drops into any viem
|
|
163
|
+
* `WalletClient`:
|
|
164
|
+
*
|
|
165
|
+
* ```ts
|
|
166
|
+
* const client = new WalletKitClient({ baseUrl, getAccessToken });
|
|
167
|
+
* const [wallet] = await client.listWallets();
|
|
168
|
+
* const account = createWalletKitAccount(client, wallet);
|
|
169
|
+
* const walletClient = createWalletClient({ account, transport: http(...), chain });
|
|
170
|
+
* const hash = await walletClient.sendTransaction({ ... });
|
|
171
|
+
* ```
|
|
172
|
+
*
|
|
173
|
+
* Method routing:
|
|
174
|
+
* - `signMessage({ message })` → `POST /v1/sign/message`
|
|
175
|
+
* - `signTransaction(tx)` → `POST /v1/sign/transaction`
|
|
176
|
+
* - `signTypedData(typedData)` → throws (not supported server-side yet)
|
|
177
|
+
*
|
|
178
|
+
* Privy per-op authorization: if a caller needs to forward a Privy
|
|
179
|
+
* authorization signature (required for user-owned Privy wallets),
|
|
180
|
+
* pass a `getOpContext` callback. It's invoked fresh per sign
|
|
181
|
+
* operation so each request gets a fresh signature.
|
|
182
|
+
*/
|
|
183
|
+
type CreateWalletKitAccountOptions = {
|
|
184
|
+
/**
|
|
185
|
+
* Resolve a per-op Privy authorization context. Invoked immediately
|
|
186
|
+
* before each sign call. Return `null` (or omit) for unauthenticated
|
|
187
|
+
* / non-Privy signing contexts.
|
|
188
|
+
*/
|
|
189
|
+
getOpContext?: () => OpContext | null | Promise<OpContext | null>;
|
|
190
|
+
};
|
|
191
|
+
declare function createWalletKitAccount(client: WalletKitClient, wallet: Wallet, opts?: CreateWalletKitAccountOptions): LocalAccount;
|
|
192
|
+
|
|
193
|
+
export { type ControlProofClaims, type CreateWalletKitAccountOptions, DEPLOY_ERC1167_PROXIES_ABI, type Lsp23DeploymentParams, buildControlProof, buildControlProofMessage, createWalletKitAccount, deriveLsp23ProxyAddress, encodeDeploymentCalldata, predictProfileAddress };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
// src/control-proof.ts
|
|
2
|
+
import { keccak256 } from "viem";
|
|
3
|
+
function buildControlProofMessage(claims, nonce, issuedAtUnix) {
|
|
4
|
+
return [
|
|
5
|
+
"Universal Relayer \u2014 authorize profile deploy",
|
|
6
|
+
`account: ${claims.subject}`,
|
|
7
|
+
`controller: ${claims.controllerAddress.toLowerCase()}`,
|
|
8
|
+
`profile: ${claims.predictedAddress.toLowerCase()}`,
|
|
9
|
+
`chainId: ${claims.chainId}`,
|
|
10
|
+
`calldata: ${keccak256(claims.deploymentCalldata)}`,
|
|
11
|
+
`nonce: ${nonce}`,
|
|
12
|
+
`issuedAt: ${issuedAtUnix}`
|
|
13
|
+
].join("\n");
|
|
14
|
+
}
|
|
15
|
+
async function buildControlProof(claims, nonce, issuedAtUnix, signMessage) {
|
|
16
|
+
const message = buildControlProofMessage(claims, nonce, issuedAtUnix);
|
|
17
|
+
const signature = await signMessage(message);
|
|
18
|
+
return { signature, nonce, issuedAtUnix };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// src/up-create2.ts
|
|
22
|
+
import {
|
|
23
|
+
decodeFunctionData,
|
|
24
|
+
encodeAbiParameters,
|
|
25
|
+
encodeFunctionData,
|
|
26
|
+
getCreate2Address,
|
|
27
|
+
keccak256 as keccak2562,
|
|
28
|
+
parseAbiParameters
|
|
29
|
+
} from "viem";
|
|
30
|
+
var DEPLOY_ERC1167_PROXIES_ABI = [
|
|
31
|
+
{
|
|
32
|
+
type: "function",
|
|
33
|
+
name: "deployERC1167Proxies",
|
|
34
|
+
stateMutability: "payable",
|
|
35
|
+
inputs: [
|
|
36
|
+
{
|
|
37
|
+
name: "primaryContractDeploymentInit",
|
|
38
|
+
type: "tuple",
|
|
39
|
+
components: [
|
|
40
|
+
{ name: "salt", type: "bytes32" },
|
|
41
|
+
{ name: "fundingAmount", type: "uint256" },
|
|
42
|
+
{ name: "implementationContract", type: "address" },
|
|
43
|
+
{ name: "initializationCalldata", type: "bytes" }
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: "secondaryContractDeploymentInit",
|
|
48
|
+
type: "tuple",
|
|
49
|
+
components: [
|
|
50
|
+
{ name: "fundingAmount", type: "uint256" },
|
|
51
|
+
{ name: "implementationContract", type: "address" },
|
|
52
|
+
{ name: "initializationCalldata", type: "bytes" },
|
|
53
|
+
{ name: "addPrimaryContractAddress", type: "bool" },
|
|
54
|
+
{ name: "extraInitializationParams", type: "bytes" }
|
|
55
|
+
]
|
|
56
|
+
},
|
|
57
|
+
{ name: "postDeploymentModule", type: "address" },
|
|
58
|
+
{ name: "postDeploymentModuleCalldata", type: "bytes" }
|
|
59
|
+
],
|
|
60
|
+
outputs: [
|
|
61
|
+
{ name: "primaryContractAddress", type: "address" },
|
|
62
|
+
{ name: "secondaryContractAddress", type: "address" }
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
];
|
|
66
|
+
function encodeDeploymentCalldata(params) {
|
|
67
|
+
return encodeFunctionData({
|
|
68
|
+
abi: DEPLOY_ERC1167_PROXIES_ABI,
|
|
69
|
+
functionName: "deployERC1167Proxies",
|
|
70
|
+
args: [
|
|
71
|
+
{
|
|
72
|
+
salt: params.salt,
|
|
73
|
+
fundingAmount: params.primaryFundingAmount ?? 0n,
|
|
74
|
+
implementationContract: params.primaryImplementation,
|
|
75
|
+
initializationCalldata: params.primaryInitializationCalldata ?? "0x"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
fundingAmount: params.secondaryFundingAmount ?? 0n,
|
|
79
|
+
implementationContract: params.secondaryImplementation,
|
|
80
|
+
initializationCalldata: params.secondaryInitializationCalldata ?? "0x",
|
|
81
|
+
addPrimaryContractAddress: params.addPrimaryContractAddress ?? true,
|
|
82
|
+
extraInitializationParams: params.secondaryExtraInitializationParams ?? "0x"
|
|
83
|
+
},
|
|
84
|
+
params.postDeploymentModule,
|
|
85
|
+
params.postDeploymentModuleCalldata
|
|
86
|
+
]
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function deriveLsp23ProxyAddress(opts) {
|
|
90
|
+
let decoded;
|
|
91
|
+
try {
|
|
92
|
+
decoded = decodeFunctionData({
|
|
93
|
+
abi: DEPLOY_ERC1167_PROXIES_ABI,
|
|
94
|
+
data: opts.deploymentCalldata
|
|
95
|
+
});
|
|
96
|
+
} catch (err) {
|
|
97
|
+
throw new Error(
|
|
98
|
+
`deploymentCalldata is not a valid deployERC1167Proxies call: ${err instanceof Error ? err.message : String(err)}`
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
if (decoded.functionName !== "deployERC1167Proxies") {
|
|
102
|
+
throw new Error(
|
|
103
|
+
`deploymentCalldata is not a deployERC1167Proxies call: got ${decoded.functionName}`
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
const [
|
|
107
|
+
primary,
|
|
108
|
+
secondary,
|
|
109
|
+
postDeploymentModule,
|
|
110
|
+
postDeploymentModuleCalldata
|
|
111
|
+
] = decoded.args;
|
|
112
|
+
const create2Salt = keccak2562(
|
|
113
|
+
encodeAbiParameters(
|
|
114
|
+
parseAbiParameters(
|
|
115
|
+
"bytes32, address, bytes, bool, bytes, address, bytes"
|
|
116
|
+
),
|
|
117
|
+
[
|
|
118
|
+
primary.salt,
|
|
119
|
+
secondary.implementationContract,
|
|
120
|
+
secondary.initializationCalldata,
|
|
121
|
+
secondary.addPrimaryContractAddress,
|
|
122
|
+
secondary.extraInitializationParams,
|
|
123
|
+
postDeploymentModule,
|
|
124
|
+
postDeploymentModuleCalldata
|
|
125
|
+
]
|
|
126
|
+
)
|
|
127
|
+
);
|
|
128
|
+
const primaryImplHex = primary.implementationContract.slice(2).toLowerCase();
|
|
129
|
+
const bytecode = `0x3d602d80600a3d3981f3363d3d373d3d3d363d73${primaryImplHex}5af43d82803e903d91602b57fd5bf3`;
|
|
130
|
+
return getCreate2Address({
|
|
131
|
+
from: opts.factoryAddress,
|
|
132
|
+
salt: create2Salt,
|
|
133
|
+
bytecode
|
|
134
|
+
}).toLowerCase();
|
|
135
|
+
}
|
|
136
|
+
function predictProfileAddress(factoryAddress, params) {
|
|
137
|
+
const deploymentCalldata = encodeDeploymentCalldata(params);
|
|
138
|
+
return {
|
|
139
|
+
deploymentCalldata,
|
|
140
|
+
predictedAddress: deriveLsp23ProxyAddress({
|
|
141
|
+
factoryAddress,
|
|
142
|
+
deploymentCalldata
|
|
143
|
+
})
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// src/index.ts
|
|
148
|
+
import { bytesToHex } from "viem";
|
|
149
|
+
import { toAccount } from "viem/accounts";
|
|
150
|
+
function createWalletKitAccount(client, wallet, opts = {}) {
|
|
151
|
+
const resolveOpContext = async () => {
|
|
152
|
+
if (!opts.getOpContext) return void 0;
|
|
153
|
+
const ctx = await opts.getOpContext();
|
|
154
|
+
return ctx ?? void 0;
|
|
155
|
+
};
|
|
156
|
+
return toAccount({
|
|
157
|
+
address: wallet.address,
|
|
158
|
+
async signMessage({ message }) {
|
|
159
|
+
const opContext = await resolveOpContext();
|
|
160
|
+
let payload;
|
|
161
|
+
let encoding;
|
|
162
|
+
if (typeof message === "string") {
|
|
163
|
+
payload = message;
|
|
164
|
+
encoding = "utf-8";
|
|
165
|
+
} else {
|
|
166
|
+
const raw = message.raw;
|
|
167
|
+
if (typeof raw === "string") {
|
|
168
|
+
payload = raw;
|
|
169
|
+
encoding = "hex";
|
|
170
|
+
} else {
|
|
171
|
+
payload = bytesToHex(raw);
|
|
172
|
+
encoding = "hex";
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const res = await client.signMessage(payload, {
|
|
176
|
+
walletId: wallet.walletId,
|
|
177
|
+
encoding,
|
|
178
|
+
...opContext ? { opContext } : {}
|
|
179
|
+
});
|
|
180
|
+
return res.signature;
|
|
181
|
+
},
|
|
182
|
+
async signTransaction(transaction) {
|
|
183
|
+
const opContext = await resolveOpContext();
|
|
184
|
+
const chainId = Number(transaction.chainId ?? 0);
|
|
185
|
+
if (!chainId || !Number.isInteger(chainId) || chainId <= 0) {
|
|
186
|
+
throw new Error(
|
|
187
|
+
"signTransaction: transaction.chainId required and must be a positive integer"
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
const type = mapViemTxType(transaction.type);
|
|
191
|
+
const input = {
|
|
192
|
+
chainId,
|
|
193
|
+
...transaction.to ? { to: transaction.to } : {},
|
|
194
|
+
..."data" in transaction && transaction.data ? { data: transaction.data } : {},
|
|
195
|
+
...transaction.value !== void 0 ? { value: transaction.value.toString() } : {},
|
|
196
|
+
...transaction.gas !== void 0 ? { gas: transaction.gas.toString() } : {},
|
|
197
|
+
..."maxFeePerGas" in transaction && transaction.maxFeePerGas !== void 0 ? { maxFeePerGas: transaction.maxFeePerGas.toString() } : {},
|
|
198
|
+
..."maxPriorityFeePerGas" in transaction && transaction.maxPriorityFeePerGas !== void 0 ? {
|
|
199
|
+
maxPriorityFeePerGas: transaction.maxPriorityFeePerGas.toString()
|
|
200
|
+
} : {},
|
|
201
|
+
...transaction.nonce !== void 0 ? { nonce: Number(transaction.nonce) } : {},
|
|
202
|
+
...type !== void 0 ? { type } : {}
|
|
203
|
+
};
|
|
204
|
+
const res = await client.signTransaction(input, {
|
|
205
|
+
walletId: wallet.walletId,
|
|
206
|
+
...opContext ? { opContext } : {}
|
|
207
|
+
});
|
|
208
|
+
return res.rawTx;
|
|
209
|
+
},
|
|
210
|
+
async signTypedData() {
|
|
211
|
+
throw new Error(
|
|
212
|
+
"signTypedData is not yet supported by WalletKit \u2014 the relayer needs a dedicated /v1/sign/typed-data endpoint first. Track in M11 SDK polish."
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
function mapViemTxType(type) {
|
|
218
|
+
switch (type) {
|
|
219
|
+
case "eip1559":
|
|
220
|
+
case "legacy":
|
|
221
|
+
case "eip2930":
|
|
222
|
+
return type;
|
|
223
|
+
// viem supports more exotic types (eip4844, eip7702) that our
|
|
224
|
+
// server doesn't expose yet. Falling through to undefined lets
|
|
225
|
+
// the server pick its default (eip1559). If a caller needs
|
|
226
|
+
// blob txs, they'll get a server-side 400 until we add support.
|
|
227
|
+
default:
|
|
228
|
+
return void 0;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
export {
|
|
232
|
+
DEPLOY_ERC1167_PROXIES_ABI,
|
|
233
|
+
buildControlProof,
|
|
234
|
+
buildControlProofMessage,
|
|
235
|
+
createWalletKitAccount,
|
|
236
|
+
deriveLsp23ProxyAddress,
|
|
237
|
+
encodeDeploymentCalldata,
|
|
238
|
+
predictProfileAddress
|
|
239
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@universal-everything/sdk-core-viem",
|
|
3
|
+
"version": "1.0.0-dev.cb4e80f",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/universal-everything/universal-relayer.git",
|
|
7
|
+
"directory": "packages/sdk-core-viem"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"viem": "^2.21.0",
|
|
26
|
+
"@universal-everything/sdk-core": "1.0.0-dev.cb4e80f"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"typescript": "^5.7.0",
|
|
30
|
+
"vitest": "^4.1.10",
|
|
31
|
+
"tsup": "^8.5.0"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"typecheck": "tsc --noEmit",
|
|
35
|
+
"test": "vitest run",
|
|
36
|
+
"build": "tsup"
|
|
37
|
+
}
|
|
38
|
+
}
|