@latticexyz/common 2.2.18-8d0ce55e964e646a1c804c401df01c4deb866f30 → 2.2.18-9fa07c8489f1fbf167d0db01cd9aaa645a29c8e2
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/dist/actions.cjs +334 -0
- package/dist/actions.cjs.map +1 -0
- package/dist/actions.d.cts +27 -0
- package/dist/actions.js +39 -1
- package/dist/actions.js.map +1 -1
- package/dist/chains.cjs +106 -0
- package/dist/chains.cjs.map +1 -0
- package/dist/chains.d.cts +968 -0
- package/dist/chains.js +75 -1
- package/dist/chains.js.map +1 -1
- package/dist/chunk-D4GDXAMP.js +64 -0
- package/dist/{chunk-ZIUX7JCQ.js.map → chunk-D4GDXAMP.js.map} +1 -1
- package/dist/chunk-IYZZFDNO.js +16 -0
- package/dist/{chunk-ZV2KGJCD.js.map → chunk-IYZZFDNO.js.map} +1 -1
- package/dist/chunk-MF5NFUW7.js +12 -0
- package/dist/{chunk-QQCZY3XJ.js.map → chunk-MF5NFUW7.js.map} +1 -1
- package/dist/chunk-MK6UECU7.js +11 -0
- package/dist/{chunk-TCWGPC6G.js.map → chunk-MK6UECU7.js.map} +1 -1
- package/dist/chunk-MYWRXQQH.js +208 -0
- package/dist/{chunk-6FIKI2CG.js.map → chunk-MYWRXQQH.js.map} +1 -1
- package/dist/chunk-Z6SVAIZN.js +70 -0
- package/dist/{chunk-DPUUE7NM.js.map → chunk-Z6SVAIZN.js.map} +1 -1
- package/dist/codegen.cjs +889 -0
- package/dist/codegen.cjs.map +1 -0
- package/dist/codegen.d.cts +228 -0
- package/dist/codegen.js +706 -49
- package/dist/codegen.js.map +1 -1
- package/dist/errors.cjs +38 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +5 -0
- package/dist/errors.js +6 -1
- package/dist/foundry.cjs +105 -0
- package/dist/foundry.cjs.map +1 -0
- package/dist/foundry.d.cts +69 -0
- package/dist/foundry.js +71 -2
- package/dist/foundry.js.map +1 -1
- package/dist/getContract-CA0EdVg6.d.cts +20 -0
- package/dist/index.cjs +597 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +160 -0
- package/dist/index.js +233 -1
- package/dist/index.js.map +1 -1
- package/dist/internal.cjs +459 -0
- package/dist/internal.cjs.map +1 -0
- package/dist/internal.d.cts +36 -0
- package/dist/internal.js +205 -9
- package/dist/internal.js.map +1 -1
- package/dist/kms.cjs +204 -0
- package/dist/kms.cjs.map +1 -0
- package/dist/kms.d.cts +18 -0
- package/dist/kms.js +168 -1
- package/dist/kms.js.map +1 -1
- package/dist/type-utils.cjs +19 -0
- package/dist/type-utils.cjs.map +1 -0
- package/dist/type-utils.d.cts +19 -0
- package/dist/utils.cjs +174 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +40 -0
- package/dist/utils.js +122 -1
- package/dist/utils.js.map +1 -1
- package/package.json +102 -12
- package/dist/chunk-6FIKI2CG.js +0 -2
- package/dist/chunk-DPUUE7NM.js +0 -2
- package/dist/chunk-QQCZY3XJ.js +0 -2
- package/dist/chunk-TCWGPC6G.js +0 -2
- package/dist/chunk-ZIUX7JCQ.js +0 -2
- package/dist/chunk-ZV2KGJCD.js +0 -2
package/dist/internal.js
CHANGED
|
@@ -1,13 +1,209 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import {
|
|
2
|
+
sendTransaction
|
|
3
|
+
} from "./chunk-MYWRXQQH.js";
|
|
4
|
+
import {
|
|
5
|
+
debug
|
|
6
|
+
} from "./chunk-MK6UECU7.js";
|
|
7
|
+
import {
|
|
8
|
+
uniqueBy
|
|
9
|
+
} from "./chunk-IYZZFDNO.js";
|
|
10
|
+
|
|
11
|
+
// src/waitForTransactions.ts
|
|
12
|
+
import { waitForTransactionReceipt } from "viem/actions";
|
|
13
|
+
async function waitForTransactions({
|
|
14
|
+
client,
|
|
15
|
+
hashes,
|
|
16
|
+
debugLabel = "transactions"
|
|
17
|
+
}) {
|
|
18
|
+
if (!hashes.length) return;
|
|
19
|
+
debug(`waiting for ${debugLabel} to confirm`);
|
|
20
|
+
for (const hash of hashes) {
|
|
21
|
+
const receipt = await waitForTransactionReceipt(client, { hash });
|
|
22
|
+
if (receipt.status === "reverted") {
|
|
23
|
+
throw new Error(`Transaction reverted: ${hash}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// src/deploy/ensureContract.ts
|
|
29
|
+
import { concatHex, getCreate2Address } from "viem";
|
|
30
|
+
import { getCode } from "viem/actions";
|
|
31
|
+
|
|
32
|
+
// src/deploy/common.ts
|
|
33
|
+
import { stringToHex } from "viem";
|
|
34
|
+
var singletonSalt = stringToHex("", { size: 32 });
|
|
35
|
+
var contractSizeLimit = parseInt("6000", 16);
|
|
36
|
+
|
|
37
|
+
// src/deploy/debug.ts
|
|
38
|
+
var debug2 = debug.extend("deploy");
|
|
39
|
+
var error = debug.extend("deploy");
|
|
40
|
+
debug2.log = console.debug.bind(console);
|
|
41
|
+
error.log = console.error.bind(console);
|
|
42
|
+
|
|
43
|
+
// src/deploy/ensureContract.ts
|
|
44
|
+
async function ensureContract({
|
|
45
|
+
client,
|
|
46
|
+
deployerAddress,
|
|
47
|
+
bytecode,
|
|
48
|
+
deployedBytecodeSize,
|
|
49
|
+
debugLabel = "contract",
|
|
50
|
+
salt = singletonSalt
|
|
51
|
+
}) {
|
|
52
|
+
if (bytecode.includes("__$")) {
|
|
53
|
+
throw new Error(`Found unlinked public library in ${debugLabel} bytecode`);
|
|
54
|
+
}
|
|
55
|
+
const address = getCreate2Address({ from: deployerAddress, salt, bytecode });
|
|
56
|
+
const contractCode = await getCode(client, { address, blockTag: "pending" });
|
|
57
|
+
if (contractCode) {
|
|
58
|
+
debug2("found", debugLabel, "at", address);
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
if (deployedBytecodeSize != null) {
|
|
62
|
+
if (deployedBytecodeSize > contractSizeLimit) {
|
|
63
|
+
console.warn(
|
|
64
|
+
`
|
|
65
|
+
Bytecode for ${debugLabel} (${deployedBytecodeSize} bytes) is over the contract size limit (${contractSizeLimit} bytes). Run \`forge build --sizes\` for more info.
|
|
66
|
+
`
|
|
67
|
+
);
|
|
68
|
+
} else if (deployedBytecodeSize > contractSizeLimit * 0.95) {
|
|
69
|
+
console.warn(
|
|
70
|
+
// eslint-disable-next-line max-len
|
|
71
|
+
`
|
|
72
|
+
Bytecode for ${debugLabel} (${deployedBytecodeSize} bytes) is almost over the contract size limit (${contractSizeLimit} bytes). Run \`forge build --sizes\` for more info.
|
|
73
|
+
`
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
debug2("deploying", debugLabel, "at", address);
|
|
78
|
+
return [
|
|
79
|
+
await sendTransaction(client, {
|
|
80
|
+
chain: client.chain ?? null,
|
|
81
|
+
to: deployerAddress,
|
|
82
|
+
data: concatHex([salt, bytecode])
|
|
83
|
+
})
|
|
84
|
+
];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// src/deploy/ensureContractsDeployed.ts
|
|
88
|
+
async function ensureContractsDeployed({
|
|
89
|
+
client,
|
|
90
|
+
deployerAddress,
|
|
91
|
+
contracts
|
|
92
|
+
}) {
|
|
93
|
+
const uniqueContracts = uniqueBy(contracts, (contract) => contract.bytecode);
|
|
94
|
+
const txs = (await Promise.all(uniqueContracts.map((contract) => ensureContract({ client, deployerAddress, ...contract })))).flat();
|
|
95
|
+
await waitForTransactions({
|
|
96
|
+
client,
|
|
97
|
+
hashes: txs,
|
|
98
|
+
debugLabel: "contract deploys"
|
|
99
|
+
});
|
|
100
|
+
return txs;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// src/deploy/ensureDeployer.ts
|
|
104
|
+
import { getBalance, sendRawTransaction, sendTransaction as sendTransaction2, waitForTransactionReceipt as waitForTransactionReceipt2 } from "viem/actions";
|
|
105
|
+
|
|
106
|
+
// src/deploy/create2/deployment.json
|
|
107
|
+
var deployment_default = {
|
|
108
|
+
gasPrice: 1e11,
|
|
109
|
+
gasLimit: 1e5,
|
|
110
|
+
signerAddress: "3fab184622dc19b6109349b94811493bf2a45362",
|
|
111
|
+
transaction: "f8a58085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222",
|
|
112
|
+
address: "4e59b44847b379578588920ca78fbf26c0b4956c",
|
|
113
|
+
creationCode: "604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf3"
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// src/deploy/getDeployer.ts
|
|
117
|
+
import { sliceHex } from "viem";
|
|
118
|
+
import { getCode as getCode2 } from "viem/actions";
|
|
119
|
+
var deployer = `0x${deployment_default.address}`;
|
|
120
|
+
async function getDeployer(client) {
|
|
121
|
+
const bytecode = await getCode2(client, { address: deployer });
|
|
122
|
+
if (bytecode) {
|
|
123
|
+
debug2("found deployer bytecode at", deployer);
|
|
124
|
+
if (bytecode !== sliceHex(`0x${deployment_default.creationCode}`, 14)) {
|
|
125
|
+
console.warn(
|
|
126
|
+
`
|
|
127
|
+
\u26A0\uFE0F Bytecode for deployer at ${deployer} did not match the expected CREATE2 bytecode. You may have unexpected results.
|
|
128
|
+
`
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
return deployer;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// src/deploy/ensureDeployer.ts
|
|
136
|
+
var deployer2 = `0x${deployment_default.address}`;
|
|
137
|
+
async function ensureDeployer(client) {
|
|
138
|
+
const existingDeployer = await getDeployer(client);
|
|
139
|
+
if (existingDeployer !== void 0) {
|
|
140
|
+
return existingDeployer;
|
|
141
|
+
}
|
|
142
|
+
const gasRequired = BigInt(deployment_default.gasLimit) * BigInt(deployment_default.gasPrice);
|
|
143
|
+
const currentBalance = await getBalance(client, { address: `0x${deployment_default.signerAddress}` });
|
|
144
|
+
const gasNeeded = gasRequired - currentBalance;
|
|
145
|
+
if (gasNeeded > 0) {
|
|
146
|
+
debug2("sending gas for CREATE2 deployer to signer at", deployment_default.signerAddress);
|
|
147
|
+
const gasTx = await sendTransaction2(client, {
|
|
148
|
+
chain: client.chain ?? null,
|
|
149
|
+
to: `0x${deployment_default.signerAddress}`,
|
|
150
|
+
value: gasNeeded
|
|
151
|
+
});
|
|
152
|
+
const gasReceipt = await waitForTransactionReceipt2(client, { hash: gasTx });
|
|
153
|
+
if (gasReceipt.status !== "success") {
|
|
154
|
+
console.error("failed to send gas to deployer signer", gasReceipt);
|
|
155
|
+
throw new Error("failed to send gas to deployer signer");
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
debug2("deploying CREATE2 deployer at", deployer2);
|
|
159
|
+
const deployTx = await sendRawTransaction(client, { serializedTransaction: `0x${deployment_default.transaction}` }).catch(
|
|
160
|
+
(error2) => {
|
|
161
|
+
if (String(error2).includes("only replay-protected (EIP-155) transactions allowed over RPC")) {
|
|
162
|
+
console.warn(
|
|
163
|
+
// eslint-disable-next-line max-len
|
|
164
|
+
`
|
|
8
165
|
\u26A0\uFE0F Your chain or RPC does not allow for non EIP-155 signed transactions, so your deploys will not be determinstic and contract addresses may change between deploys.
|
|
9
166
|
|
|
10
167
|
We recommend running your chain's node with \`--rpc.allow-unprotected-txs\` to enable determinstic deployments.
|
|
11
|
-
`
|
|
12
|
-
|
|
168
|
+
`
|
|
169
|
+
);
|
|
170
|
+
debug2("deploying CREATE2 deployer");
|
|
171
|
+
return sendTransaction2(client, {
|
|
172
|
+
chain: client.chain ?? null,
|
|
173
|
+
data: `0x${deployment_default.creationCode}`
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
throw error2;
|
|
177
|
+
}
|
|
178
|
+
);
|
|
179
|
+
const deployReceipt = await waitForTransactionReceipt2(client, { hash: deployTx });
|
|
180
|
+
if (!deployReceipt.contractAddress) {
|
|
181
|
+
throw new Error("Deploy receipt did not have contract address, was the deployer not deployed?");
|
|
182
|
+
}
|
|
183
|
+
if (deployReceipt.contractAddress !== deployer2) {
|
|
184
|
+
console.warn(
|
|
185
|
+
`
|
|
186
|
+
\u26A0\uFE0F CREATE2 deployer created at ${deployReceipt.contractAddress} does not match the CREATE2 determinstic deployer we expected (${deployer2})`
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
return deployReceipt.contractAddress;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// src/deploy/getContractAddress.ts
|
|
193
|
+
import { getCreate2Address as getCreate2Address2 } from "viem";
|
|
194
|
+
function getContractAddress({
|
|
195
|
+
deployerAddress,
|
|
196
|
+
bytecode,
|
|
197
|
+
salt = singletonSalt
|
|
198
|
+
}) {
|
|
199
|
+
return getCreate2Address2({ from: deployerAddress, bytecode, salt });
|
|
200
|
+
}
|
|
201
|
+
export {
|
|
202
|
+
ensureContract,
|
|
203
|
+
ensureContractsDeployed,
|
|
204
|
+
ensureDeployer,
|
|
205
|
+
getContractAddress,
|
|
206
|
+
getDeployer,
|
|
207
|
+
waitForTransactions
|
|
208
|
+
};
|
|
13
209
|
//# sourceMappingURL=internal.js.map
|
package/dist/internal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/waitForTransactions.ts","../src/deploy/ensureContract.ts","../src/deploy/common.ts","../src/deploy/debug.ts","../src/deploy/ensureContractsDeployed.ts","../src/deploy/ensureDeployer.ts","../src/deploy/create2/deployment.json","../src/deploy/getDeployer.ts","../src/deploy/getContractAddress.ts"],"sourcesContent":["import { Client, Transport, Chain, Account, Hex } from \"viem\";\nimport { debug } from \"./debug\";\nimport { waitForTransactionReceipt } from \"viem/actions\";\n\nexport async function waitForTransactions({\n client,\n hashes,\n debugLabel = \"transactions\",\n}: {\n readonly client: Client<Transport, Chain | undefined, Account>;\n readonly hashes: readonly Hex[];\n readonly debugLabel?: string;\n}): Promise<void> {\n if (!hashes.length) return;\n\n debug(`waiting for ${debugLabel} to confirm`);\n // wait for each tx separately/serially, because parallelizing results in RPC errors\n for (const hash of hashes) {\n const receipt = await waitForTransactionReceipt(client, { hash });\n // TODO: handle user op failures?\n if (receipt.status === \"reverted\") {\n throw new Error(`Transaction reverted: ${hash}`);\n }\n }\n}\n","import { Client, Transport, Chain, Account, concatHex, getCreate2Address, Hex } from \"viem\";\nimport { getCode } from \"viem/actions\";\nimport { contractSizeLimit, singletonSalt } from \"./common\";\nimport { debug } from \"./debug\";\nimport { sendTransaction } from \"../sendTransaction\";\n\nexport type Contract = {\n bytecode: Hex;\n deployedBytecodeSize?: number;\n debugLabel?: string;\n salt?: Hex;\n};\n\nexport async function ensureContract({\n client,\n deployerAddress,\n bytecode,\n deployedBytecodeSize,\n debugLabel = \"contract\",\n salt = singletonSalt,\n}: {\n readonly client: Client<Transport, Chain | undefined, Account>;\n readonly deployerAddress: Hex;\n} & Contract): Promise<readonly Hex[]> {\n if (bytecode.includes(\"__$\")) {\n throw new Error(`Found unlinked public library in ${debugLabel} bytecode`);\n }\n\n const address = getCreate2Address({ from: deployerAddress, salt, bytecode });\n\n const contractCode = await getCode(client, { address, blockTag: \"pending\" });\n if (contractCode) {\n debug(\"found\", debugLabel, \"at\", address);\n return [];\n }\n\n if (deployedBytecodeSize != null) {\n if (deployedBytecodeSize > contractSizeLimit) {\n console.warn(\n `\\nBytecode for ${debugLabel} (${deployedBytecodeSize} bytes) is over the contract size limit (${contractSizeLimit} bytes). Run \\`forge build --sizes\\` for more info.\\n`,\n );\n } else if (deployedBytecodeSize > contractSizeLimit * 0.95) {\n console.warn(\n // eslint-disable-next-line max-len\n `\\nBytecode for ${debugLabel} (${deployedBytecodeSize} bytes) is almost over the contract size limit (${contractSizeLimit} bytes). Run \\`forge build --sizes\\` for more info.\\n`,\n );\n }\n }\n\n debug(\"deploying\", debugLabel, \"at\", address);\n return [\n await sendTransaction(client, {\n chain: client.chain ?? null,\n to: deployerAddress,\n data: concatHex([salt, bytecode]),\n }),\n ];\n}\n","import { stringToHex } from \"viem\";\n\n// salt for deterministic deploys of singleton contracts\nexport const singletonSalt = stringToHex(\"\", { size: 32 });\n\n// https://eips.ethereum.org/EIPS/eip-170\nexport const contractSizeLimit = parseInt(\"6000\", 16);\n","import { debug as parentDebug } from \"../debug\";\n\nexport const debug = parentDebug.extend(\"deploy\");\nexport const error = parentDebug.extend(\"deploy\");\n\n// Pipe debug output to stdout instead of stderr\ndebug.log = console.debug.bind(console);\n\n// Pipe error output to stderr\nerror.log = console.error.bind(console);\n","import { Client, Transport, Chain, Account, Hex } from \"viem\";\nimport { Contract, ensureContract } from \"./ensureContract\";\nimport { waitForTransactions } from \"../waitForTransactions\";\nimport { uniqueBy } from \"../utils/uniqueBy\";\n\nexport async function ensureContractsDeployed({\n client,\n deployerAddress,\n contracts,\n}: {\n readonly client: Client<Transport, Chain | undefined, Account>;\n readonly deployerAddress: Hex;\n readonly contracts: readonly Contract[];\n}): Promise<readonly Hex[]> {\n // Deployments assume a deterministic deployer, so we only need to deploy the unique bytecode\n const uniqueContracts = uniqueBy(contracts, (contract) => contract.bytecode);\n\n const txs = (\n await Promise.all(uniqueContracts.map((contract) => ensureContract({ client, deployerAddress, ...contract })))\n ).flat();\n\n await waitForTransactions({\n client,\n hashes: txs,\n debugLabel: \"contract deploys\",\n });\n\n return txs;\n}\n","import { Account, Address, Chain, Client, Transport } from \"viem\";\nimport { getBalance, sendRawTransaction, sendTransaction, waitForTransactionReceipt } from \"viem/actions\";\nimport deployment from \"./create2/deployment.json\";\nimport { debug } from \"./debug\";\nimport { getDeployer } from \"./getDeployer\";\n\nconst deployer = `0x${deployment.address}` as const;\n\nexport async function ensureDeployer(client: Client<Transport, Chain | undefined, Account>): Promise<Address> {\n const existingDeployer = await getDeployer(client);\n if (existingDeployer !== undefined) {\n return existingDeployer;\n }\n\n // There's not really a way to simulate a pre-EIP-155 (no chain ID) transaction,\n // so we have to attempt to create the deployer first and, if it fails, fall back\n // to a regular deploy.\n\n // Send gas to deployment signer\n const gasRequired = BigInt(deployment.gasLimit) * BigInt(deployment.gasPrice);\n const currentBalance = await getBalance(client, { address: `0x${deployment.signerAddress}` });\n const gasNeeded = gasRequired - currentBalance;\n if (gasNeeded > 0) {\n debug(\"sending gas for CREATE2 deployer to signer at\", deployment.signerAddress);\n const gasTx = await sendTransaction(client, {\n chain: client.chain ?? null,\n to: `0x${deployment.signerAddress}`,\n value: gasNeeded,\n });\n const gasReceipt = await waitForTransactionReceipt(client, { hash: gasTx });\n if (gasReceipt.status !== \"success\") {\n console.error(\"failed to send gas to deployer signer\", gasReceipt);\n throw new Error(\"failed to send gas to deployer signer\");\n }\n }\n\n // Deploy the deployer\n debug(\"deploying CREATE2 deployer at\", deployer);\n const deployTx = await sendRawTransaction(client, { serializedTransaction: `0x${deployment.transaction}` }).catch(\n (error) => {\n // Do a regular contract create if the presigned transaction doesn't work due to replay protection\n if (String(error).includes(\"only replay-protected (EIP-155) transactions allowed over RPC\")) {\n console.warn(\n // eslint-disable-next-line max-len\n `\\n ⚠️ Your chain or RPC does not allow for non EIP-155 signed transactions, so your deploys will not be determinstic and contract addresses may change between deploys.\\n\\n We recommend running your chain's node with \\`--rpc.allow-unprotected-txs\\` to enable determinstic deployments.\\n`,\n );\n debug(\"deploying CREATE2 deployer\");\n return sendTransaction(client, {\n chain: client.chain ?? null,\n data: `0x${deployment.creationCode}`,\n });\n }\n throw error;\n },\n );\n\n const deployReceipt = await waitForTransactionReceipt(client, { hash: deployTx });\n if (!deployReceipt.contractAddress) {\n throw new Error(\"Deploy receipt did not have contract address, was the deployer not deployed?\");\n }\n\n if (deployReceipt.contractAddress !== deployer) {\n console.warn(\n `\\n ⚠️ CREATE2 deployer created at ${deployReceipt.contractAddress} does not match the CREATE2 determinstic deployer we expected (${deployer})`,\n );\n }\n\n return deployReceipt.contractAddress;\n}\n","{\n \"gasPrice\": 100000000000,\n \"gasLimit\": 100000,\n \"signerAddress\": \"3fab184622dc19b6109349b94811493bf2a45362\",\n \"transaction\": \"f8a58085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222\",\n \"address\": \"4e59b44847b379578588920ca78fbf26c0b4956c\",\n \"creationCode\": \"604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf3\"\n}\n","import { Address, Chain, Client, Transport, sliceHex } from \"viem\";\nimport { getCode } from \"viem/actions\";\nimport deployment from \"./create2/deployment.json\";\nimport { debug } from \"./debug\";\n\nconst deployer = `0x${deployment.address}` as const;\n\nexport async function getDeployer(client: Client<Transport, Chain | undefined>): Promise<Address | undefined> {\n const bytecode = await getCode(client, { address: deployer });\n if (bytecode) {\n debug(\"found deployer bytecode at\", deployer);\n // check if deployed bytecode is the same as the expected bytecode (minus 14-bytes creation code prefix)\n if (bytecode !== sliceHex(`0x${deployment.creationCode}`, 14)) {\n console.warn(\n `\\n ⚠️ Bytecode for deployer at ${deployer} did not match the expected CREATE2 bytecode. You may have unexpected results.\\n`,\n );\n }\n return deployer;\n }\n}\n","import { Hex, getCreate2Address } from \"viem\";\nimport { singletonSalt } from \"./common\";\n\nexport function getContractAddress({\n deployerAddress,\n bytecode,\n salt = singletonSalt,\n}: {\n readonly deployerAddress: Hex;\n readonly bytecode: Hex;\n readonly salt?: Hex;\n}): Hex {\n return getCreate2Address({ from: deployerAddress, bytecode, salt });\n}\n"],"mappings":"wHAEA,OAAS,6BAAAA,MAAiC,eAE1C,eAAsBC,EAAoB,CACxC,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,OAAOC,EAAkB,CAAE,KAAMJ,EAAiB,SAAAC,EAAU,KAAAC,CAAK,CAAC,CACpE","names":["waitForTransactionReceipt","waitForTransactions","client","hashes","debugLabel","debug","hash","concatHex","getCreate2Address","getCode","stringToHex","singletonSalt","contractSizeLimit","debug","error","ensureContract","client","deployerAddress","bytecode","deployedBytecodeSize","debugLabel","salt","singletonSalt","address","getCreate2Address","getCode","debug","contractSizeLimit","sendTransaction","concatHex","ensureContractsDeployed","client","deployerAddress","contracts","uniqueContracts","uniqueBy","contract","txs","ensureContract","waitForTransactions","getBalance","sendRawTransaction","sendTransaction","waitForTransactionReceipt","deployment_default","sliceHex","getCode","deployer","deployment_default","getDeployer","client","bytecode","getCode","debug","sliceHex","deployer","deployment_default","ensureDeployer","client","existingDeployer","getDeployer","gasRequired","currentBalance","getBalance","gasNeeded","debug","gasTx","sendTransaction","gasReceipt","waitForTransactionReceipt","deployTx","sendRawTransaction","error","deployReceipt","getCreate2Address","getContractAddress","deployerAddress","bytecode","salt","singletonSalt","getCreate2Address"]}
|
|
1
|
+
{"version":3,"sources":["../src/waitForTransactions.ts","../src/deploy/ensureContract.ts","../src/deploy/common.ts","../src/deploy/debug.ts","../src/deploy/ensureContractsDeployed.ts","../src/deploy/ensureDeployer.ts","../src/deploy/create2/deployment.json","../src/deploy/getDeployer.ts","../src/deploy/getContractAddress.ts"],"sourcesContent":["import { Client, Transport, Chain, Account, Hex } from \"viem\";\nimport { debug } from \"./debug\";\nimport { waitForTransactionReceipt } from \"viem/actions\";\n\nexport async function waitForTransactions({\n client,\n hashes,\n debugLabel = \"transactions\",\n}: {\n readonly client: Client<Transport, Chain | undefined, Account>;\n readonly hashes: readonly Hex[];\n readonly debugLabel?: string;\n}): Promise<void> {\n if (!hashes.length) return;\n\n debug(`waiting for ${debugLabel} to confirm`);\n // wait for each tx separately/serially, because parallelizing results in RPC errors\n for (const hash of hashes) {\n const receipt = await waitForTransactionReceipt(client, { hash });\n // TODO: handle user op failures?\n if (receipt.status === \"reverted\") {\n throw new Error(`Transaction reverted: ${hash}`);\n }\n }\n}\n","import { Client, Transport, Chain, Account, concatHex, getCreate2Address, Hex } from \"viem\";\nimport { getCode } from \"viem/actions\";\nimport { contractSizeLimit, singletonSalt } from \"./common\";\nimport { debug } from \"./debug\";\nimport { sendTransaction } from \"../sendTransaction\";\n\nexport type Contract = {\n bytecode: Hex;\n deployedBytecodeSize?: number;\n debugLabel?: string;\n salt?: Hex;\n};\n\nexport async function ensureContract({\n client,\n deployerAddress,\n bytecode,\n deployedBytecodeSize,\n debugLabel = \"contract\",\n salt = singletonSalt,\n}: {\n readonly client: Client<Transport, Chain | undefined, Account>;\n readonly deployerAddress: Hex;\n} & Contract): Promise<readonly Hex[]> {\n if (bytecode.includes(\"__$\")) {\n throw new Error(`Found unlinked public library in ${debugLabel} bytecode`);\n }\n\n const address = getCreate2Address({ from: deployerAddress, salt, bytecode });\n\n const contractCode = await getCode(client, { address, blockTag: \"pending\" });\n if (contractCode) {\n debug(\"found\", debugLabel, \"at\", address);\n return [];\n }\n\n if (deployedBytecodeSize != null) {\n if (deployedBytecodeSize > contractSizeLimit) {\n console.warn(\n `\\nBytecode for ${debugLabel} (${deployedBytecodeSize} bytes) is over the contract size limit (${contractSizeLimit} bytes). Run \\`forge build --sizes\\` for more info.\\n`,\n );\n } else if (deployedBytecodeSize > contractSizeLimit * 0.95) {\n console.warn(\n // eslint-disable-next-line max-len\n `\\nBytecode for ${debugLabel} (${deployedBytecodeSize} bytes) is almost over the contract size limit (${contractSizeLimit} bytes). Run \\`forge build --sizes\\` for more info.\\n`,\n );\n }\n }\n\n debug(\"deploying\", debugLabel, \"at\", address);\n return [\n await sendTransaction(client, {\n chain: client.chain ?? null,\n to: deployerAddress,\n data: concatHex([salt, bytecode]),\n }),\n ];\n}\n","import { stringToHex } from \"viem\";\n\n// salt for deterministic deploys of singleton contracts\nexport const singletonSalt = stringToHex(\"\", { size: 32 });\n\n// https://eips.ethereum.org/EIPS/eip-170\nexport const contractSizeLimit = parseInt(\"6000\", 16);\n","import { debug as parentDebug } from \"../debug\";\n\nexport const debug = parentDebug.extend(\"deploy\");\nexport const error = parentDebug.extend(\"deploy\");\n\n// Pipe debug output to stdout instead of stderr\ndebug.log = console.debug.bind(console);\n\n// Pipe error output to stderr\nerror.log = console.error.bind(console);\n","import { Client, Transport, Chain, Account, Hex } from \"viem\";\nimport { Contract, ensureContract } from \"./ensureContract\";\nimport { waitForTransactions } from \"../waitForTransactions\";\nimport { uniqueBy } from \"../utils/uniqueBy\";\n\nexport async function ensureContractsDeployed({\n client,\n deployerAddress,\n contracts,\n}: {\n readonly client: Client<Transport, Chain | undefined, Account>;\n readonly deployerAddress: Hex;\n readonly contracts: readonly Contract[];\n}): Promise<readonly Hex[]> {\n // Deployments assume a deterministic deployer, so we only need to deploy the unique bytecode\n const uniqueContracts = uniqueBy(contracts, (contract) => contract.bytecode);\n\n const txs = (\n await Promise.all(uniqueContracts.map((contract) => ensureContract({ client, deployerAddress, ...contract })))\n ).flat();\n\n await waitForTransactions({\n client,\n hashes: txs,\n debugLabel: \"contract deploys\",\n });\n\n return txs;\n}\n","import { Account, Address, Chain, Client, Transport } from \"viem\";\nimport { getBalance, sendRawTransaction, sendTransaction, waitForTransactionReceipt } from \"viem/actions\";\nimport deployment from \"./create2/deployment.json\";\nimport { debug } from \"./debug\";\nimport { getDeployer } from \"./getDeployer\";\n\nconst deployer = `0x${deployment.address}` as const;\n\nexport async function ensureDeployer(client: Client<Transport, Chain | undefined, Account>): Promise<Address> {\n const existingDeployer = await getDeployer(client);\n if (existingDeployer !== undefined) {\n return existingDeployer;\n }\n\n // There's not really a way to simulate a pre-EIP-155 (no chain ID) transaction,\n // so we have to attempt to create the deployer first and, if it fails, fall back\n // to a regular deploy.\n\n // Send gas to deployment signer\n const gasRequired = BigInt(deployment.gasLimit) * BigInt(deployment.gasPrice);\n const currentBalance = await getBalance(client, { address: `0x${deployment.signerAddress}` });\n const gasNeeded = gasRequired - currentBalance;\n if (gasNeeded > 0) {\n debug(\"sending gas for CREATE2 deployer to signer at\", deployment.signerAddress);\n const gasTx = await sendTransaction(client, {\n chain: client.chain ?? null,\n to: `0x${deployment.signerAddress}`,\n value: gasNeeded,\n });\n const gasReceipt = await waitForTransactionReceipt(client, { hash: gasTx });\n if (gasReceipt.status !== \"success\") {\n console.error(\"failed to send gas to deployer signer\", gasReceipt);\n throw new Error(\"failed to send gas to deployer signer\");\n }\n }\n\n // Deploy the deployer\n debug(\"deploying CREATE2 deployer at\", deployer);\n const deployTx = await sendRawTransaction(client, { serializedTransaction: `0x${deployment.transaction}` }).catch(\n (error) => {\n // Do a regular contract create if the presigned transaction doesn't work due to replay protection\n if (String(error).includes(\"only replay-protected (EIP-155) transactions allowed over RPC\")) {\n console.warn(\n // eslint-disable-next-line max-len\n `\\n ⚠️ Your chain or RPC does not allow for non EIP-155 signed transactions, so your deploys will not be determinstic and contract addresses may change between deploys.\\n\\n We recommend running your chain's node with \\`--rpc.allow-unprotected-txs\\` to enable determinstic deployments.\\n`,\n );\n debug(\"deploying CREATE2 deployer\");\n return sendTransaction(client, {\n chain: client.chain ?? null,\n data: `0x${deployment.creationCode}`,\n });\n }\n throw error;\n },\n );\n\n const deployReceipt = await waitForTransactionReceipt(client, { hash: deployTx });\n if (!deployReceipt.contractAddress) {\n throw new Error(\"Deploy receipt did not have contract address, was the deployer not deployed?\");\n }\n\n if (deployReceipt.contractAddress !== deployer) {\n console.warn(\n `\\n ⚠️ CREATE2 deployer created at ${deployReceipt.contractAddress} does not match the CREATE2 determinstic deployer we expected (${deployer})`,\n );\n }\n\n return deployReceipt.contractAddress;\n}\n","{\n \"gasPrice\": 100000000000,\n \"gasLimit\": 100000,\n \"signerAddress\": \"3fab184622dc19b6109349b94811493bf2a45362\",\n \"transaction\": \"f8a58085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222\",\n \"address\": \"4e59b44847b379578588920ca78fbf26c0b4956c\",\n \"creationCode\": \"604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf3\"\n}\n","import { Address, Chain, Client, Transport, sliceHex } from \"viem\";\nimport { getCode } from \"viem/actions\";\nimport deployment from \"./create2/deployment.json\";\nimport { debug } from \"./debug\";\n\nconst deployer = `0x${deployment.address}` as const;\n\nexport async function getDeployer(client: Client<Transport, Chain | undefined>): Promise<Address | undefined> {\n const bytecode = await getCode(client, { address: deployer });\n if (bytecode) {\n debug(\"found deployer bytecode at\", deployer);\n // check if deployed bytecode is the same as the expected bytecode (minus 14-bytes creation code prefix)\n if (bytecode !== sliceHex(`0x${deployment.creationCode}`, 14)) {\n console.warn(\n `\\n ⚠️ Bytecode for deployer at ${deployer} did not match the expected CREATE2 bytecode. You may have unexpected results.\\n`,\n );\n }\n return deployer;\n }\n}\n","import { Hex, getCreate2Address } from \"viem\";\nimport { singletonSalt } from \"./common\";\n\nexport function getContractAddress({\n deployerAddress,\n bytecode,\n salt = singletonSalt,\n}: {\n readonly deployerAddress: Hex;\n readonly bytecode: Hex;\n readonly salt?: Hex;\n}): Hex {\n return getCreate2Address({ from: deployerAddress, bytecode, salt });\n}\n"],"mappings":";;;;;;;;;;;AAEA,SAAS,iCAAiC;AAE1C,eAAsB,oBAAoB;AAAA,EACxC;AAAA,EACA;AAAA,EACA,aAAa;AACf,GAIkB;AAChB,MAAI,CAAC,OAAO,OAAQ;AAEpB,QAAM,eAAe,UAAU,aAAa;AAE5C,aAAW,QAAQ,QAAQ;AACzB,UAAM,UAAU,MAAM,0BAA0B,QAAQ,EAAE,KAAK,CAAC;AAEhE,QAAI,QAAQ,WAAW,YAAY;AACjC,YAAM,IAAI,MAAM,yBAAyB,IAAI,EAAE;AAAA,IACjD;AAAA,EACF;AACF;;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;AAAA,IAC/I;AAAA,EACF;AAEA,SAAO,cAAc;AACvB;;;AGpEA,SAAc,qBAAAK,0BAAyB;AAGhC,SAAS,mBAAmB;AAAA,EACjC;AAAA,EACA;AAAA,EACA,OAAO;AACT,GAIQ;AACN,SAAOC,mBAAkB,EAAE,MAAM,iBAAiB,UAAU,KAAK,CAAC;AACpE;","names":["debug","debug","sendTransaction","waitForTransactionReceipt","getCode","getCode","debug","deployer","debug","sendTransaction","waitForTransactionReceipt","error","getCreate2Address","getCreate2Address"]}
|
package/dist/kms.cjs
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/exports/kms.ts
|
|
31
|
+
var kms_exports = {};
|
|
32
|
+
__export(kms_exports, {
|
|
33
|
+
kmsKeyToAccount: () => kmsKeyToAccount
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(kms_exports);
|
|
36
|
+
|
|
37
|
+
// src/account/kms/kmsKeyToAccount.ts
|
|
38
|
+
var import_client_kms3 = require("@aws-sdk/client-kms");
|
|
39
|
+
var import_viem4 = require("viem");
|
|
40
|
+
var import_accounts = require("viem/accounts");
|
|
41
|
+
|
|
42
|
+
// src/account/kms/signWithKms.ts
|
|
43
|
+
var import_viem2 = require("viem");
|
|
44
|
+
var import_utils = require("viem/utils");
|
|
45
|
+
|
|
46
|
+
// src/account/kms/sign.ts
|
|
47
|
+
var import_client_kms = require("@aws-sdk/client-kms");
|
|
48
|
+
var import_viem = require("viem");
|
|
49
|
+
async function sign({
|
|
50
|
+
keyId,
|
|
51
|
+
hash,
|
|
52
|
+
client
|
|
53
|
+
}) {
|
|
54
|
+
const formatted = Buffer.from((0, import_viem.fromHex)(hash, "bytes"));
|
|
55
|
+
const command = new import_client_kms.SignCommand({
|
|
56
|
+
KeyId: keyId,
|
|
57
|
+
Message: formatted,
|
|
58
|
+
SigningAlgorithm: "ECDSA_SHA_256",
|
|
59
|
+
MessageType: "DIGEST"
|
|
60
|
+
});
|
|
61
|
+
return client.send(command);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/account/kms/signWithKms.ts
|
|
65
|
+
var import_asn1 = __toESM(require("asn1.js"), 1);
|
|
66
|
+
var EcdsaSigAsnParse = import_asn1.default.define("EcdsaSig", function() {
|
|
67
|
+
this.seq().obj(this.key("r").int(), this.key("s").int());
|
|
68
|
+
});
|
|
69
|
+
async function getRS(signParams) {
|
|
70
|
+
const signature = await sign(signParams);
|
|
71
|
+
if (signature.Signature === void 0) {
|
|
72
|
+
throw new Error("Signature is undefined.");
|
|
73
|
+
}
|
|
74
|
+
const decoded = EcdsaSigAsnParse.decode(Buffer.from(signature.Signature), "der");
|
|
75
|
+
const r = BigInt(decoded.r);
|
|
76
|
+
let s = BigInt(decoded.s);
|
|
77
|
+
const secp256k1N = BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141");
|
|
78
|
+
const secp256k1halfN = secp256k1N / 2n;
|
|
79
|
+
if (s > secp256k1halfN) {
|
|
80
|
+
s = secp256k1N - s;
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
r: (0, import_viem2.toHex)(r),
|
|
84
|
+
s: (0, import_viem2.toHex)(s)
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
async function getRecovery(hash, r, s, expectedAddress) {
|
|
88
|
+
let recovery;
|
|
89
|
+
for (recovery = 0; recovery <= 1; recovery++) {
|
|
90
|
+
const signature = (0, import_viem2.signatureToHex)({
|
|
91
|
+
r,
|
|
92
|
+
s,
|
|
93
|
+
v: recovery ? 28n : 27n,
|
|
94
|
+
yParity: recovery
|
|
95
|
+
});
|
|
96
|
+
const address = await (0, import_utils.recoverAddress)({ hash, signature });
|
|
97
|
+
if ((0, import_viem2.isAddressEqual)(address, expectedAddress)) {
|
|
98
|
+
return recovery;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
throw new Error("Failed to calculate recovery param");
|
|
102
|
+
}
|
|
103
|
+
async function signWithKms({ hash, address, keyId, client }) {
|
|
104
|
+
const { r, s } = await getRS({ keyId, hash, client });
|
|
105
|
+
const recovery = await getRecovery(hash, r, s, address);
|
|
106
|
+
return {
|
|
107
|
+
r,
|
|
108
|
+
s,
|
|
109
|
+
v: recovery ? 28n : 27n,
|
|
110
|
+
yParity: recovery
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// src/account/kms/getAddressFromKms.ts
|
|
115
|
+
var import_viem3 = require("viem");
|
|
116
|
+
var import_utils2 = require("viem/utils");
|
|
117
|
+
|
|
118
|
+
// src/account/kms/getPublicKey.ts
|
|
119
|
+
var import_client_kms2 = require("@aws-sdk/client-kms");
|
|
120
|
+
function getPublicKey({
|
|
121
|
+
keyId,
|
|
122
|
+
client
|
|
123
|
+
}) {
|
|
124
|
+
const command = new import_client_kms2.GetPublicKeyCommand({ KeyId: keyId });
|
|
125
|
+
return client.send(command);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// src/account/kms/getAddressFromKms.ts
|
|
129
|
+
var import_asn12 = __toESM(require("asn1.js"), 1);
|
|
130
|
+
var EcdsaPubKey = import_asn12.default.define("EcdsaPubKey", function() {
|
|
131
|
+
this.seq().obj(this.key("algo").seq().obj(this.key("a").objid(), this.key("b").objid()), this.key("pubKey").bitstr());
|
|
132
|
+
});
|
|
133
|
+
function publicKeyKmsToAddress(publicKey) {
|
|
134
|
+
const res = EcdsaPubKey.decode(Buffer.from(publicKey));
|
|
135
|
+
const publicKeyBuffer = res.pubKey.data;
|
|
136
|
+
const publicKeyHex = (0, import_viem3.toHex)(publicKeyBuffer);
|
|
137
|
+
const address = (0, import_utils2.publicKeyToAddress)(publicKeyHex);
|
|
138
|
+
return address;
|
|
139
|
+
}
|
|
140
|
+
async function getAddressFromKms({
|
|
141
|
+
keyId,
|
|
142
|
+
client
|
|
143
|
+
}) {
|
|
144
|
+
const KMSKey = await getPublicKey({ keyId, client });
|
|
145
|
+
return publicKeyKmsToAddress(KMSKey.PublicKey);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// src/account/kms/kmsKeyToAccount.ts
|
|
149
|
+
async function kmsKeyToAccount({
|
|
150
|
+
keyId,
|
|
151
|
+
client = new import_client_kms3.KMSClient()
|
|
152
|
+
}) {
|
|
153
|
+
const address = await getAddressFromKms({ keyId, client });
|
|
154
|
+
const account = (0, import_accounts.toAccount)({
|
|
155
|
+
address,
|
|
156
|
+
async signMessage({ message }) {
|
|
157
|
+
const signature = await signWithKms({
|
|
158
|
+
client,
|
|
159
|
+
keyId,
|
|
160
|
+
hash: (0, import_viem4.hashMessage)(message),
|
|
161
|
+
address
|
|
162
|
+
});
|
|
163
|
+
return (0, import_viem4.signatureToHex)(signature);
|
|
164
|
+
},
|
|
165
|
+
// The logic of this function should be align with viem's signTransaction
|
|
166
|
+
// https://github.com/wevm/viem/blob/main/src/accounts/utils/signTransaction.ts
|
|
167
|
+
async signTransaction(transaction, { serializer = import_viem4.serializeTransaction } = {}) {
|
|
168
|
+
const signableTransaction = (() => {
|
|
169
|
+
if (transaction.type === "eip4844")
|
|
170
|
+
return {
|
|
171
|
+
...transaction,
|
|
172
|
+
sidecars: false
|
|
173
|
+
};
|
|
174
|
+
return transaction;
|
|
175
|
+
})();
|
|
176
|
+
const signature = await signWithKms({
|
|
177
|
+
client,
|
|
178
|
+
keyId,
|
|
179
|
+
hash: (0, import_viem4.keccak256)(serializer(signableTransaction)),
|
|
180
|
+
address
|
|
181
|
+
});
|
|
182
|
+
return serializer(transaction, signature);
|
|
183
|
+
},
|
|
184
|
+
async signTypedData(typedData) {
|
|
185
|
+
const signature = await signWithKms({
|
|
186
|
+
client,
|
|
187
|
+
keyId,
|
|
188
|
+
hash: (0, import_viem4.hashTypedData)(typedData),
|
|
189
|
+
address
|
|
190
|
+
});
|
|
191
|
+
return (0, import_viem4.signatureToHex)(signature);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
return {
|
|
195
|
+
...account,
|
|
196
|
+
source: "aws-kms",
|
|
197
|
+
getKeyId: () => keyId
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
201
|
+
0 && (module.exports = {
|
|
202
|
+
kmsKeyToAccount
|
|
203
|
+
});
|
|
204
|
+
//# sourceMappingURL=kms.cjs.map
|
package/dist/kms.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/exports/kms.ts","../src/account/kms/kmsKeyToAccount.ts","../src/account/kms/signWithKms.ts","../src/account/kms/sign.ts","../src/account/kms/getAddressFromKms.ts","../src/account/kms/getPublicKey.ts"],"sourcesContent":["export { kmsKeyToAccount, type KmsKeyToAccountOptions, type KmsAccount } from \"../account/kms/kmsKeyToAccount\";\n","import { KMSClient } from \"@aws-sdk/client-kms\";\nimport { LocalAccount, hashMessage, hashTypedData, keccak256, serializeTransaction, signatureToHex } from \"viem\";\nimport { toAccount } from \"viem/accounts\";\nimport { signWithKms } from \"./signWithKms\";\nimport { getAddressFromKms } from \"./getAddressFromKms\";\n\nexport type KmsKeyToAccountOptions = {\n keyId: string;\n client?: KMSClient;\n};\n\nexport type KmsAccount = LocalAccount<\"aws-kms\"> & {\n getKeyId(): string;\n};\n\n/**\n * @description Creates an Account from a KMS key.\n *\n * @returns A Local Account.\n */\nexport async function kmsKeyToAccount({\n keyId,\n client = new KMSClient(),\n}: KmsKeyToAccountOptions): Promise<KmsAccount> {\n const address = await getAddressFromKms({ keyId, client });\n\n const account = toAccount({\n address,\n async signMessage({ message }) {\n const signature = await signWithKms({\n client,\n keyId,\n hash: hashMessage(message),\n address,\n });\n\n return signatureToHex(signature);\n },\n // The logic of this function should be align with viem's signTransaction\n // https://github.com/wevm/viem/blob/main/src/accounts/utils/signTransaction.ts\n async signTransaction(transaction, { serializer = serializeTransaction } = {}) {\n // eslint-disable-next-line @typescript-eslint/explicit-function-return-type\n const signableTransaction = (() => {\n // For EIP-4844 Transactions, we want to sign the transaction payload body (tx_payload_body) without the sidecars (ie. without the network wrapper).\n // See: https://github.com/ethereum/EIPs/blob/e00f4daa66bd56e2dbd5f1d36d09fd613811a48b/EIPS/eip-4844.md#networking\n if (transaction.type === \"eip4844\")\n return {\n ...transaction,\n sidecars: false,\n };\n return transaction;\n })();\n\n const signature = await signWithKms({\n client,\n keyId,\n hash: keccak256(serializer(signableTransaction)),\n address,\n });\n\n return serializer(transaction, signature);\n },\n async signTypedData(typedData) {\n const signature = await signWithKms({\n client,\n keyId,\n hash: hashTypedData(typedData),\n address,\n });\n\n return signatureToHex(signature);\n },\n });\n\n return {\n ...account,\n source: \"aws-kms\",\n getKeyId: () => keyId,\n };\n}\n","import { Hex, Signature, isAddressEqual, signatureToHex, toHex } from \"viem\";\nimport { recoverAddress } from \"viem/utils\";\nimport { KMSClient, SignCommandInput } from \"@aws-sdk/client-kms\";\nimport { sign } from \"./sign\";\n// @ts-expect-error Could not find a declaration file for module 'asn1.js'.\nimport asn1 from \"asn1.js\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst EcdsaSigAsnParse = asn1.define(\"EcdsaSig\", function (this: any) {\n this.seq().obj(this.key(\"r\").int(), this.key(\"s\").int());\n});\n\nasync function getRS(signParams: {\n hash: Hex;\n keyId: SignCommandInput[\"KeyId\"];\n client: KMSClient;\n}): Promise<{ r: Hex; s: Hex }> {\n const signature = await sign(signParams);\n\n if (signature.Signature === undefined) {\n throw new Error(\"Signature is undefined.\");\n }\n\n const decoded = EcdsaSigAsnParse.decode(Buffer.from(signature.Signature), \"der\");\n\n const r = BigInt(decoded.r);\n let s = BigInt(decoded.s);\n\n const secp256k1N = BigInt(\"0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141\");\n const secp256k1halfN = secp256k1N / 2n;\n\n if (s > secp256k1halfN) {\n s = secp256k1N - s;\n }\n\n return {\n r: toHex(r),\n s: toHex(s),\n };\n}\n\nasync function getRecovery(hash: Hex, r: Hex, s: Hex, expectedAddress: Hex): Promise<number> {\n let recovery: number;\n for (recovery = 0; recovery <= 1; recovery++) {\n const signature = signatureToHex({\n r,\n s,\n v: recovery ? 28n : 27n,\n yParity: recovery,\n });\n\n const address = await recoverAddress({ hash, signature });\n\n if (isAddressEqual(address, expectedAddress)) {\n return recovery;\n }\n }\n throw new Error(\"Failed to calculate recovery param\");\n}\n\ntype SignParameters = {\n hash: Hex;\n keyId: SignCommandInput[\"KeyId\"];\n client: KMSClient;\n address: Hex;\n};\n\ntype SignReturnType = Signature;\n\n/**\n * @description Signs a hash with a given KMS key.\n *\n * @param hash The hash to sign.\n *\n * @returns The signature.\n */\nexport async function signWithKms({ hash, address, keyId, client }: SignParameters): Promise<SignReturnType> {\n const { r, s } = await getRS({ keyId, hash, client });\n const recovery = await getRecovery(hash, r, s, address);\n\n return {\n r,\n s,\n v: recovery ? 28n : 27n,\n yParity: recovery,\n };\n}\n","import { KMSClient, SignCommand, SignCommandInput, SignCommandOutput } from \"@aws-sdk/client-kms\";\nimport { Hex, fromHex } from \"viem\";\n\nexport async function sign({\n keyId,\n hash,\n client,\n}: {\n hash: Hex;\n keyId: SignCommandInput[\"KeyId\"];\n client: KMSClient;\n}): Promise<SignCommandOutput> {\n const formatted = Buffer.from(fromHex(hash, \"bytes\"));\n\n const command = new SignCommand({\n KeyId: keyId,\n Message: formatted,\n SigningAlgorithm: \"ECDSA_SHA_256\",\n MessageType: \"DIGEST\",\n });\n\n return client.send(command);\n}\n","import { Address, toHex } from \"viem\";\nimport { publicKeyToAddress } from \"viem/utils\";\nimport { GetPublicKeyCommandInput, KMSClient } from \"@aws-sdk/client-kms\";\nimport { getPublicKey } from \"./getPublicKey\";\n// @ts-expect-error Could not find a declaration file for module 'asn1.js'.\nimport asn1 from \"asn1.js\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst EcdsaPubKey = asn1.define(\"EcdsaPubKey\", function (this: any) {\n this.seq().obj(this.key(\"algo\").seq().obj(this.key(\"a\").objid(), this.key(\"b\").objid()), this.key(\"pubKey\").bitstr());\n});\n\nfunction publicKeyKmsToAddress(publicKey: Uint8Array): Address {\n const res = EcdsaPubKey.decode(Buffer.from(publicKey));\n\n const publicKeyBuffer: Buffer = res.pubKey.data;\n\n const publicKeyHex = toHex(publicKeyBuffer);\n const address = publicKeyToAddress(publicKeyHex);\n\n return address;\n}\n\nexport async function getAddressFromKms({\n keyId,\n client,\n}: {\n keyId: GetPublicKeyCommandInput[\"KeyId\"];\n client: KMSClient;\n}): Promise<Address> {\n const KMSKey = await getPublicKey({ keyId, client });\n\n return publicKeyKmsToAddress(KMSKey.PublicKey as Uint8Array);\n}\n","import {\n GetPublicKeyCommand,\n GetPublicKeyCommandInput,\n GetPublicKeyCommandOutput,\n KMSClient,\n} from \"@aws-sdk/client-kms\";\n\nexport function getPublicKey({\n keyId,\n client,\n}: {\n keyId: GetPublicKeyCommandInput[\"KeyId\"];\n client: KMSClient;\n}): Promise<GetPublicKeyCommandOutput> {\n const command = new GetPublicKeyCommand({ KeyId: keyId });\n\n return client.send(command);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,qBAA0B;AAC1B,IAAAC,eAA0G;AAC1G,sBAA0B;;;ACF1B,IAAAC,eAAsE;AACtE,mBAA+B;;;ACD/B,wBAA4E;AAC5E,kBAA6B;AAE7B,eAAsB,KAAK;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AACF,GAI+B;AAC7B,QAAM,YAAY,OAAO,SAAK,qBAAQ,MAAM,OAAO,CAAC;AAEpD,QAAM,UAAU,IAAI,8BAAY;AAAA,IAC9B,OAAO;AAAA,IACP,SAAS;AAAA,IACT,kBAAkB;AAAA,IAClB,aAAa;AAAA,EACf,CAAC;AAED,SAAO,OAAO,KAAK,OAAO;AAC5B;;;ADjBA,kBAAiB;AAGjB,IAAM,mBAAmB,YAAAC,QAAK,OAAO,YAAY,WAAqB;AACpE,OAAK,IAAI,EAAE,IAAI,KAAK,IAAI,GAAG,EAAE,IAAI,GAAG,KAAK,IAAI,GAAG,EAAE,IAAI,CAAC;AACzD,CAAC;AAED,eAAe,MAAM,YAIW;AAC9B,QAAM,YAAY,MAAM,KAAK,UAAU;AAEvC,MAAI,UAAU,cAAc,QAAW;AACrC,UAAM,IAA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F,eAAO;AAAA,MACT,GAAG;AAEH,YAAM,YAAY,MAAM,YAAY;AAAA,QAClC;AAAA,QACA;AAAA,QACA,UAAM,wBAAU,WAAW,mBAAmB,CAAC;AAAA,QAC/C;AAAA,MACF,CAAC;AAED,aAAO,WAAW,aAAa,SAAS;AAAA,IAC1C;AAAA,IACA,MAAM,cAAc,WAAW;AAC7B,YAAM,YAAY,MAAM,YAAY;AAAA,QAClC;AAAA,QACA;AAAA,QACA,UAAM,4BAAc,SAAS;AAAA,QAC7B;AAAA,MACF,CAAC;AAED,iBAAO,6BAAe,SAAS;AAAA,IACjC;AAAA,EACF,CAAC;AAED,SAAO;AAAA,IACL,GAAG;AAAA,IACH,QAAQ;AAAA,IACR,UAAU,MAAM;AAAA,EAClB;AACF;","names":["import_client_kms","import_viem","import_viem","asn1","import_viem","import_utils","import_client_kms","import_asn1","asn1"]}
|
package/dist/kms.d.cts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { KMSClient } from '@aws-sdk/client-kms';
|
|
2
|
+
import { LocalAccount } from 'viem';
|
|
3
|
+
|
|
4
|
+
type KmsKeyToAccountOptions = {
|
|
5
|
+
keyId: string;
|
|
6
|
+
client?: KMSClient;
|
|
7
|
+
};
|
|
8
|
+
type KmsAccount = LocalAccount<"aws-kms"> & {
|
|
9
|
+
getKeyId(): string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* @description Creates an Account from a KMS key.
|
|
13
|
+
*
|
|
14
|
+
* @returns A Local Account.
|
|
15
|
+
*/
|
|
16
|
+
declare function kmsKeyToAccount({ keyId, client, }: KmsKeyToAccountOptions): Promise<KmsAccount>;
|
|
17
|
+
|
|
18
|
+
export { type KmsAccount, type KmsKeyToAccountOptions, kmsKeyToAccount };
|