getcofund 0.1.0 → 0.2.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/README.md +57 -0
- package/dist/api-types.d.ts +201 -0
- package/dist/api-types.js +124 -5
- package/dist/cli/context.d.ts +1 -1
- package/dist/cli/context.js +5 -0
- package/dist/cli/invite.d.ts +10 -1
- package/dist/cli/invite.js +81 -3
- package/dist/cli/policies.d.ts +17 -0
- package/dist/cli/policies.js +100 -0
- package/dist/cli.d.ts +5 -0
- package/dist/cli.js +25 -1
- package/dist/client.d.ts +63 -1
- package/dist/client.js +25 -1
- package/dist/eip712.d.ts +14 -0
- package/dist/eip712.js +16 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/invite.d.ts +28 -1
- package/dist/invite.js +40 -1
- package/dist/policies.d.ts +69 -0
- package/dist/policies.js +132 -0
- package/dist/requests.d.ts +1 -1
- package/dist/requests.js +21 -60
- package/package.json +1 -1
package/dist/requests.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { sha256 } from "@noble/hashes/sha2";
|
|
2
|
-
import { bytesToHex } from "@noble/hashes/utils";
|
|
3
1
|
import { ethers } from "ethers";
|
|
4
|
-
import { btcPolicyActivationMessage
|
|
2
|
+
import { btcPolicyActivationMessage } from "./btc-policy-activation.js";
|
|
5
3
|
import { pinnedDomain, sameDomain } from "./chains.js";
|
|
6
|
-
import { inviteUserTypes,
|
|
4
|
+
import { inviteUserTypes, transactionTypes, transferTypes, WRAPPER_ENTRYPOINT, } from "./eip712.js";
|
|
7
5
|
import { inviteWindowProblem } from "./invite.js";
|
|
8
|
-
import {
|
|
6
|
+
import { btcPolicyActivation, evmPolicyActivation, } from "./policies.js";
|
|
9
7
|
import { decodeStockSwap, encodeV4SwapInstructions, STOCK_POOLS, STOCK_SWAP_WRAPPER_MAINNET, swapLegs, } from "./stocks/index.js";
|
|
10
8
|
const sameAddress = (a, b) => a.toLowerCase() === b.toLowerCase();
|
|
11
9
|
/**
|
|
@@ -83,60 +81,17 @@ export function decodeRequest(request) {
|
|
|
83
81
|
};
|
|
84
82
|
}
|
|
85
83
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
* The activation the policy's fields commit to: a transaction policy names its
|
|
89
|
-
* wrapper and `entry`; a transfer policy its token, cap and allowlist.
|
|
90
|
-
*/
|
|
91
|
-
function policyActivation(company, request) {
|
|
92
|
-
const common = {
|
|
93
|
-
company,
|
|
94
|
-
policyId: request.id,
|
|
95
|
-
title: request.name,
|
|
96
|
-
policyType: request.type,
|
|
97
|
-
signerIds: request.signers.map((s) => s.onchainId).sort(byCodepoint),
|
|
98
|
-
threshold: String(request.threshold),
|
|
99
|
-
authId: request.id,
|
|
100
|
-
};
|
|
101
|
-
if (request.wrapper) {
|
|
102
|
-
return {
|
|
103
|
-
types: transactionPolicyActivationTypes(),
|
|
104
|
-
message: {
|
|
105
|
-
...common,
|
|
106
|
-
wrapper: request.wrapper,
|
|
107
|
-
func: WRAPPER_ENTRYPOINT,
|
|
108
|
-
},
|
|
109
|
-
};
|
|
110
|
-
}
|
|
84
|
+
/** What a policy request's activation commits to, from its own fields. */
|
|
85
|
+
function activationFields(request) {
|
|
111
86
|
return {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
/** The BTC activation the fields commit to; signer keys are derived here from their xpubs. */
|
|
122
|
-
function btcPolicyActivation(company, request) {
|
|
123
|
-
const isTransaction = request.wrapper !== null;
|
|
124
|
-
return {
|
|
125
|
-
clientId: bytesToHex(sha256(new TextEncoder().encode(company))),
|
|
126
|
-
policyId: request.id,
|
|
127
|
-
authId: request.id,
|
|
128
|
-
policyType: request.type,
|
|
129
|
-
policyTitle: request.name,
|
|
130
|
-
policySignerKeys: request.signers
|
|
131
|
-
.map((s) => btcCofundLeafKey(s.key))
|
|
132
|
-
.sort(byCodepoint),
|
|
133
|
-
policyThreshold: request.threshold,
|
|
134
|
-
txWrapper: request.wrapper ?? "",
|
|
135
|
-
txFunc: isTransaction ? WRAPPER_ENTRYPOINT : "",
|
|
136
|
-
isTransaction,
|
|
137
|
-
maxAmount: isTransaction ? "0" : (request.maxAmount ?? "0"),
|
|
138
|
-
tokenIdentifier: isTransaction ? "" : (request.token?.address ?? ""),
|
|
139
|
-
recipients: isTransaction ? [] : [...request.recipients].sort(byCodepoint),
|
|
87
|
+
id: request.id,
|
|
88
|
+
name: request.name,
|
|
89
|
+
type: request.type,
|
|
90
|
+
threshold: request.threshold,
|
|
91
|
+
token: request.token?.address ?? null,
|
|
92
|
+
maxAmount: request.maxAmount,
|
|
93
|
+
recipients: request.recipients,
|
|
94
|
+
wrapper: request.wrapper,
|
|
140
95
|
};
|
|
141
96
|
}
|
|
142
97
|
/**
|
|
@@ -211,7 +166,10 @@ function rebuildTypedData(request, company, now) {
|
|
|
211
166
|
}),
|
|
212
167
|
};
|
|
213
168
|
case "policy":
|
|
214
|
-
return
|
|
169
|
+
return evmPolicyActivation(company, {
|
|
170
|
+
...activationFields(request),
|
|
171
|
+
signerIds: request.signers.map((s) => s.onchainId),
|
|
172
|
+
});
|
|
215
173
|
default:
|
|
216
174
|
return {
|
|
217
175
|
types: inviteUserTypes(),
|
|
@@ -252,7 +210,10 @@ export async function checkRequest(request, expected, pins) {
|
|
|
252
210
|
* a request for another cofund hashes differently.
|
|
253
211
|
*/
|
|
254
212
|
async function checkBtcPolicy(request, expected) {
|
|
255
|
-
const rebuilt = btcPolicyActivationMessage(btcPolicyActivation(expected.company,
|
|
213
|
+
const rebuilt = btcPolicyActivationMessage(btcPolicyActivation(expected.company, {
|
|
214
|
+
...activationFields(request),
|
|
215
|
+
signerXpubs: request.signers.map((s) => s.key),
|
|
216
|
+
}));
|
|
256
217
|
if (rebuilt !== request.message) {
|
|
257
218
|
throw new Error(DIFFERS);
|
|
258
219
|
}
|
package/package.json
CHANGED