@rhinestone/sdk 2.2.2 → 2.3.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 +35 -0
- package/dist/src/accounts/adapters/kernel.d.ts.map +1 -1
- package/dist/src/accounts/adapters/kernel.js +3 -6
- package/dist/src/accounts/adapters/nexus.d.ts.map +1 -1
- package/dist/src/accounts/adapters/nexus.js +3 -6
- package/dist/src/accounts/adapters/safe.d.ts.map +1 -1
- package/dist/src/accounts/adapters/safe.js +7 -5
- package/dist/src/accounts/adapters/shared.d.ts +1 -0
- package/dist/src/accounts/adapters/shared.d.ts.map +1 -1
- package/dist/src/accounts/adapters/shared.js +7 -0
- package/dist/src/accounts/adapters/startale.d.ts.map +1 -1
- package/dist/src/accounts/adapters/startale.js +2 -5
- package/dist/src/accounts/construction.d.ts +1 -1
- package/dist/src/accounts/construction.d.ts.map +1 -1
- package/dist/src/accounts/construction.js +63 -15
- package/dist/src/accounts/deployment.d.ts +13 -1
- package/dist/src/accounts/deployment.d.ts.map +1 -1
- package/dist/src/accounts/deployment.js +11 -0
- package/dist/src/accounts/error.d.ts +8 -1
- package/dist/src/accounts/error.d.ts.map +1 -1
- package/dist/src/accounts/error.js +9 -1
- package/dist/src/accounts/passkey-install.d.ts +25 -0
- package/dist/src/accounts/passkey-install.d.ts.map +1 -0
- package/dist/src/accounts/passkey-install.js +105 -0
- package/dist/src/api/direct-signing.d.ts.map +1 -1
- package/dist/src/api/direct-signing.js +112 -98
- package/dist/src/clients/orchestrator/client.js +1 -1
- package/dist/src/clients/orchestrator/mappers.d.ts +4 -3
- package/dist/src/clients/orchestrator/mappers.d.ts.map +1 -1
- package/dist/src/clients/orchestrator/mappers.js +21 -13
- package/dist/src/clients/orchestrator/serialization.d.ts +5 -0
- package/dist/src/clients/orchestrator/serialization.d.ts.map +1 -0
- package/dist/src/clients/orchestrator/serialization.js +11 -0
- package/dist/src/clients/orchestrator/wire.d.ts +15 -0
- package/dist/src/clients/orchestrator/wire.d.ts.map +1 -1
- package/dist/src/clients/orchestrator/wire.gen.d.ts +556 -39
- package/dist/src/clients/orchestrator/wire.gen.d.ts.map +1 -1
- package/dist/src/config/account.d.ts +36 -2
- package/dist/src/config/account.d.ts.map +1 -1
- package/dist/src/errors/index.d.ts +2 -2
- package/dist/src/errors/index.d.ts.map +1 -1
- package/dist/src/errors/index.js +2 -2
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/modules/validators/ens.d.ts.map +1 -1
- package/dist/src/modules/validators/ens.js +2 -1
- package/dist/src/modules/validators/ordering.d.ts +3 -0
- package/dist/src/modules/validators/ordering.d.ts.map +1 -0
- package/dist/src/modules/validators/ordering.js +11 -0
- package/dist/src/modules/validators/resolve.d.ts +3 -2
- package/dist/src/modules/validators/resolve.d.ts.map +1 -1
- package/dist/src/modules/validators/resolve.js +8 -5
- package/dist/src/modules/validators/smart-sessions/erc7739.d.ts +8 -0
- package/dist/src/modules/validators/smart-sessions/erc7739.d.ts.map +1 -0
- package/dist/src/modules/validators/smart-sessions/erc7739.js +17 -0
- package/dist/src/modules/validators/smart-sessions/resolve.d.ts.map +1 -1
- package/dist/src/modules/validators/smart-sessions/resolve.js +7 -6
- package/dist/src/modules/validators/smart-sessions/signing.d.ts +8 -0
- package/dist/src/modules/validators/smart-sessions/signing.d.ts.map +1 -0
- package/dist/src/modules/validators/smart-sessions/signing.js +146 -0
- package/dist/src/modules/validators/smart-sessions/types.d.ts +19 -1
- package/dist/src/modules/validators/smart-sessions/types.d.ts.map +1 -1
- package/dist/src/modules/validators/webauthn.d.ts +20 -1
- package/dist/src/modules/validators/webauthn.d.ts.map +1 -1
- package/dist/src/modules/validators/webauthn.js +58 -7
- package/dist/src/signing/message.d.ts +2 -0
- package/dist/src/signing/message.d.ts.map +1 -1
- package/dist/src/signing/message.js +1 -1
- package/dist/src/signing/protocols/erc7739.d.ts +2 -0
- package/dist/src/signing/protocols/erc7739.d.ts.map +1 -1
- package/dist/src/signing/protocols/erc7739.js +6 -24
- package/dist/src/signing/typed-data.d.ts.map +1 -1
- package/dist/src/signing/typed-data.js +5 -10
- package/dist/src/signing/types.d.ts +0 -4
- package/dist/src/signing/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { encodePacked, hashMessage, pad, zeroHash, } from 'viem';
|
|
1
|
+
import { encodePacked, hashMessage, hashTypedData, pad, zeroHash, } from 'viem';
|
|
2
2
|
import { wrapKernelMessageHash } from '../accounts/adapters/kernel.js';
|
|
3
3
|
import { defineValidator } from '../modules/validators/definition.js';
|
|
4
4
|
import { getPermissionId } from '../modules/validators/smart-sessions/digest.js';
|
|
@@ -8,35 +8,34 @@ import { signAccountMessage } from '../signing/message.js';
|
|
|
8
8
|
import { createValidatorSigningTasks, signingTopology } from '../signing/plan.js';
|
|
9
9
|
import { resolveAccountTypedDataSigning, signAccountTypedData, } from '../signing/typed-data.js';
|
|
10
10
|
export async function signRuntimeMessage(input) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
if (input.session) {
|
|
12
|
+
return signSessionErc1271({
|
|
13
|
+
runtime: input.runtime,
|
|
14
|
+
signerInvoker: input.signerInvoker,
|
|
15
|
+
checkpoints: input.checkpoints,
|
|
16
|
+
chain: input.chain,
|
|
17
|
+
session: input.session,
|
|
18
|
+
contentHash: hashMessage(input.message),
|
|
19
|
+
nominalMessage: input.message,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
14
22
|
const context = createAccountSigningContext({
|
|
15
23
|
runtime: input.runtime,
|
|
16
24
|
purpose: 'erc1271',
|
|
17
25
|
signerInvoker: input.signerInvoker,
|
|
18
|
-
...(selection ? { selection } : {}),
|
|
26
|
+
...(input.selection ? { selection: input.selection } : {}),
|
|
19
27
|
});
|
|
20
|
-
const topology = signingTopology(context.validator, selection?.signerIds);
|
|
28
|
+
const topology = signingTopology(context.validator, input.selection?.signerIds);
|
|
21
29
|
const payload = hashMessage(input.message);
|
|
22
30
|
const accountHash = input.runtime.construction.account.kind === 'kernel'
|
|
23
31
|
? wrapKernelMessageHash(payload, context.account.address)
|
|
24
32
|
: payload;
|
|
25
|
-
const signingMaterial = input.
|
|
33
|
+
const signingMaterial = input.runtime.construction.account.kind === 'kernel'
|
|
26
34
|
? {
|
|
27
35
|
kind: 'message',
|
|
28
|
-
message: {
|
|
29
|
-
raw: hashMessage({
|
|
30
|
-
raw: encodePacked(['bytes32', 'bytes32'], [pad(context.account.address, { size: 32 }), accountHash]),
|
|
31
|
-
}),
|
|
32
|
-
},
|
|
36
|
+
message: { raw: accountHash },
|
|
33
37
|
}
|
|
34
|
-
:
|
|
35
|
-
? {
|
|
36
|
-
kind: 'message',
|
|
37
|
-
message: { raw: accountHash },
|
|
38
|
-
}
|
|
39
|
-
: undefined;
|
|
38
|
+
: undefined;
|
|
40
39
|
const route = getAccountSignatureRoute(input.runtime, context);
|
|
41
40
|
return signAccountMessage({
|
|
42
41
|
context,
|
|
@@ -52,43 +51,39 @@ export async function signRuntimeMessage(input) {
|
|
|
52
51
|
taskPrefix: 'message',
|
|
53
52
|
ecdsaInvocation: 'ecdsa-sign-message',
|
|
54
53
|
webauthnInvocation: 'webauthn-sign-hash',
|
|
55
|
-
...(selection
|
|
54
|
+
...(input.selection
|
|
55
|
+
? { selectedSignerIds: input.selection.signerIds }
|
|
56
|
+
: {}),
|
|
56
57
|
}),
|
|
57
|
-
route
|
|
58
|
-
? {
|
|
59
|
-
...route,
|
|
60
|
-
validatorCodec: {
|
|
61
|
-
kind: 'smart-session',
|
|
62
|
-
validator: {
|
|
63
|
-
kind: 'validator',
|
|
64
|
-
address: getSmartSessionEmissaryAddress(input.runtime.construction.sessions.environment),
|
|
65
|
-
},
|
|
66
|
-
mode: 'notarized',
|
|
67
|
-
permissionId: getPermissionId(input.session.session),
|
|
68
|
-
signerCodec: requireSessionOwnerCodec(getSigningValidatorCodec(context)),
|
|
69
|
-
},
|
|
70
|
-
accountEnvelope: smartSessionEnvelope(route.accountEnvelope, input.runtime.construction.sessions.environment),
|
|
71
|
-
}
|
|
72
|
-
: route,
|
|
58
|
+
route,
|
|
73
59
|
},
|
|
74
60
|
});
|
|
75
61
|
}
|
|
76
62
|
export async function signRuntimeTypedData(input) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
63
|
+
if (input.session) {
|
|
64
|
+
// Sessions sign an account-bound digest in direct (notarized) mode, the
|
|
65
|
+
// same shape signRuntimeMessage produces, so external ERC-1271 verifiers
|
|
66
|
+
// resolve the session validator directly.
|
|
67
|
+
const contentHash = hashTypedData(input.typedData);
|
|
68
|
+
return signSessionErc1271({
|
|
69
|
+
runtime: input.runtime,
|
|
70
|
+
signerInvoker: input.signerInvoker,
|
|
71
|
+
checkpoints: input.checkpoints,
|
|
72
|
+
chain: input.chain,
|
|
73
|
+
session: input.session,
|
|
74
|
+
contentHash,
|
|
75
|
+
nominalMessage: { raw: contentHash },
|
|
76
|
+
});
|
|
77
|
+
}
|
|
80
78
|
const context = createAccountSigningContext({
|
|
81
79
|
runtime: input.runtime,
|
|
82
80
|
purpose: 'erc1271',
|
|
83
81
|
signerInvoker: input.signerInvoker,
|
|
84
|
-
...(selection ? { selection } : {}),
|
|
82
|
+
...(input.selection ? { selection: input.selection } : {}),
|
|
85
83
|
});
|
|
86
|
-
const topology = signingTopology(context.validator, selection?.signerIds);
|
|
87
|
-
const typedData = input.session
|
|
88
|
-
? sessionTypedData(input.typedData, input.runtime, input.chain)
|
|
89
|
-
: input.typedData;
|
|
84
|
+
const topology = signingTopology(context.validator, input.selection?.signerIds);
|
|
90
85
|
const route = resolveAccountTypedDataSigning({
|
|
91
|
-
typedData,
|
|
86
|
+
typedData: input.typedData,
|
|
92
87
|
chain: input.chain,
|
|
93
88
|
context,
|
|
94
89
|
});
|
|
@@ -97,7 +92,7 @@ export async function signRuntimeTypedData(input) {
|
|
|
97
92
|
context,
|
|
98
93
|
checkpoints: input.checkpoints,
|
|
99
94
|
planInput: {
|
|
100
|
-
typedData,
|
|
95
|
+
typedData: input.typedData,
|
|
101
96
|
signingMaterial: route.material,
|
|
102
97
|
chain: input.chain,
|
|
103
98
|
...topology,
|
|
@@ -107,22 +102,83 @@ export async function signRuntimeTypedData(input) {
|
|
|
107
102
|
taskPrefix: 'typed-data',
|
|
108
103
|
ecdsaInvocation: route.ecdsaInvocation,
|
|
109
104
|
webauthnInvocation: route.webauthnInvocation,
|
|
110
|
-
...(selection
|
|
105
|
+
...(input.selection
|
|
106
|
+
? { selectedSignerIds: input.selection.signerIds }
|
|
107
|
+
: {}),
|
|
111
108
|
}),
|
|
112
|
-
route:
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
109
|
+
route: accountRoute,
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
// Shared ERC-1271 signing for a session: the session owner signs an
|
|
114
|
+
// account-bound digest (keccak of account ‖ contentHash) in the smart-session
|
|
115
|
+
// "notarized" (direct) mode. Used by both message and typed-data signing so
|
|
116
|
+
// they produce the identical on-chain-verifiable shape.
|
|
117
|
+
async function signSessionErc1271(input) {
|
|
118
|
+
assertDirectSessionSigning(input.session);
|
|
119
|
+
const selection = sessionOwnerSelection(input.session);
|
|
120
|
+
const context = createAccountSigningContext({
|
|
121
|
+
runtime: input.runtime,
|
|
122
|
+
purpose: 'erc1271',
|
|
123
|
+
signerInvoker: input.signerInvoker,
|
|
124
|
+
selection,
|
|
125
|
+
});
|
|
126
|
+
const topology = signingTopology(context.validator, selection.signerIds);
|
|
127
|
+
const accountHash = input.runtime.construction.account.kind === 'kernel'
|
|
128
|
+
? wrapKernelMessageHash(input.contentHash, context.account.address)
|
|
129
|
+
: input.contentHash;
|
|
130
|
+
const route = getAccountSignatureRoute(input.runtime, context);
|
|
131
|
+
return signAccountMessage({
|
|
132
|
+
context,
|
|
133
|
+
checkpoints: input.checkpoints,
|
|
134
|
+
planInput: {
|
|
135
|
+
message: input.nominalMessage,
|
|
136
|
+
signingMaterial: {
|
|
137
|
+
kind: 'message',
|
|
138
|
+
message: {
|
|
139
|
+
raw: hashMessage({
|
|
140
|
+
raw: encodePacked(['bytes32', 'bytes32'], [pad(context.account.address, { size: 32 }), accountHash]),
|
|
141
|
+
}),
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
chain: input.chain,
|
|
145
|
+
...topology,
|
|
146
|
+
tasks: createValidatorSigningTasks({
|
|
147
|
+
validator: context.validator,
|
|
148
|
+
signerReferences: context.signerReferences,
|
|
149
|
+
taskPrefix: 'message',
|
|
150
|
+
ecdsaInvocation: 'ecdsa-sign-message',
|
|
151
|
+
webauthnInvocation: 'webauthn-sign-hash',
|
|
152
|
+
selectedSignerIds: selection.signerIds,
|
|
153
|
+
}),
|
|
154
|
+
route: {
|
|
155
|
+
...route,
|
|
156
|
+
validatorCodec: {
|
|
157
|
+
kind: 'smart-session',
|
|
158
|
+
validator: {
|
|
159
|
+
kind: 'validator',
|
|
160
|
+
address: getSmartSessionEmissaryAddress(input.runtime.construction.sessions.environment),
|
|
119
161
|
},
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
162
|
+
mode: 'notarized',
|
|
163
|
+
permissionId: getPermissionId(input.session.session),
|
|
164
|
+
signerCodec: requireSessionOwnerCodec(getSigningValidatorCodec(context)),
|
|
165
|
+
},
|
|
166
|
+
accountEnvelope: smartSessionEnvelope(route.accountEnvelope, input.runtime.construction.sessions.environment),
|
|
167
|
+
},
|
|
123
168
|
},
|
|
124
169
|
});
|
|
125
170
|
}
|
|
171
|
+
function assertDirectSessionSigning(session) {
|
|
172
|
+
const allowedContents = session.session.erc7739Policies.allowedERC7739Content;
|
|
173
|
+
const allowsDirectSigning = allowedContents.some((content) => content.appDomainSeparator === zeroHash &&
|
|
174
|
+
content.contentNames.includes(''));
|
|
175
|
+
if (allowsDirectSigning)
|
|
176
|
+
return;
|
|
177
|
+
if (allowedContents.length === 0) {
|
|
178
|
+
throw new Error('This Smart Session has signing disabled');
|
|
179
|
+
}
|
|
180
|
+
throw new Error('Scoped Smart Session signing requires safe ERC-7739 emission, which is not available in this SDK');
|
|
181
|
+
}
|
|
126
182
|
function sessionOwnerSelection(session) {
|
|
127
183
|
const validator = defineValidator(session.session.owners, 'smart-session-validator');
|
|
128
184
|
return {
|
|
@@ -147,45 +203,3 @@ function smartSessionEnvelope(envelope, environment) {
|
|
|
147
203
|
? { ...envelope, validator, isRoot: false }
|
|
148
204
|
: { ...envelope, validator };
|
|
149
205
|
}
|
|
150
|
-
function sessionTypedData(typedData, runtime, chain) {
|
|
151
|
-
const verifier = sessionVerifierDomain(runtime, chain);
|
|
152
|
-
return {
|
|
153
|
-
domain: typedData.domain,
|
|
154
|
-
primaryType: 'TypedDataSign',
|
|
155
|
-
types: {
|
|
156
|
-
...typedData.types,
|
|
157
|
-
TypedDataSign: [
|
|
158
|
-
{ name: 'contents', type: typedData.primaryType },
|
|
159
|
-
{ name: 'name', type: 'string' },
|
|
160
|
-
{ name: 'version', type: 'string' },
|
|
161
|
-
{ name: 'chainId', type: 'uint256' },
|
|
162
|
-
{ name: 'verifyingContract', type: 'address' },
|
|
163
|
-
{ name: 'salt', type: 'bytes32' },
|
|
164
|
-
],
|
|
165
|
-
},
|
|
166
|
-
message: {
|
|
167
|
-
contents: typedData.message,
|
|
168
|
-
...verifier,
|
|
169
|
-
},
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
function sessionVerifierDomain(runtime, chain) {
|
|
173
|
-
const common = {
|
|
174
|
-
chainId: chain.id,
|
|
175
|
-
verifyingContract: runtime.identity.address,
|
|
176
|
-
salt: zeroHash,
|
|
177
|
-
};
|
|
178
|
-
switch (runtime.construction.account.kind) {
|
|
179
|
-
case 'safe':
|
|
180
|
-
return { ...common, name: 'rhinestone safe7579', version: 'v1.0.0' };
|
|
181
|
-
case 'nexus':
|
|
182
|
-
case 'hca':
|
|
183
|
-
return { ...common, name: 'Nexus', version: '1.2.0' };
|
|
184
|
-
case 'kernel':
|
|
185
|
-
return { ...common, name: 'Kernel', version: '0.3.3' };
|
|
186
|
-
case 'startale':
|
|
187
|
-
return { ...common, name: 'Startale', version: '1.0.0' };
|
|
188
|
-
case 'eoa':
|
|
189
|
-
throw new Error('EOA accounts do not have an EIP-712 domain');
|
|
190
|
-
}
|
|
191
|
-
}
|
|
@@ -3,7 +3,7 @@ import { createOrchestratorAuth } from './auth.js';
|
|
|
3
3
|
import { ChainCatalog, parseChains } from './chain-catalog.js';
|
|
4
4
|
import { fetchOrchestratorJson } from './fetch.js';
|
|
5
5
|
import { mapIntentRequestToWire, mapIntentStatusFromWire, mapPortfolioFromWire, mapQuoteResponseFromWire, mapSignedIntentToWire, mapSplitRequestToWire, mapSplitResultFromWire, } from './mappers.js';
|
|
6
|
-
const SDK_VERSION = '2.
|
|
6
|
+
const SDK_VERSION = '2.3.0';
|
|
7
7
|
const API_VERSION = '2026-04.blanc';
|
|
8
8
|
export function createOrchestratorClient(options) {
|
|
9
9
|
const fetchPort = options.fetch ?? globalThis.fetch;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { OrchestratorIntentRequest, OrchestratorIntentStatus, OrchestratorPortfolio, OrchestratorQuoteResponse, OrchestratorSignedIntent, OrchestratorSplitRequest, OrchestratorSplitResult } from './types.js';
|
|
2
|
-
|
|
2
|
+
import type { WireIntentRequestInternal, WireQuoteRequest, WireSplitRequest } from './wire.js';
|
|
3
|
+
export declare function mapIntentRequestToWire(input: OrchestratorIntentRequest): WireQuoteRequest;
|
|
3
4
|
export declare function mapQuoteResponseFromWire(value: unknown): OrchestratorQuoteResponse;
|
|
4
|
-
export declare function mapSignedIntentToWire(input: OrchestratorSignedIntent):
|
|
5
|
+
export declare function mapSignedIntentToWire(input: OrchestratorSignedIntent): WireIntentRequestInternal;
|
|
5
6
|
export declare function mapIntentStatusFromWire(intentId: string, value: unknown): OrchestratorIntentStatus;
|
|
6
7
|
export declare function mapPortfolioFromWire(value: unknown): OrchestratorPortfolio;
|
|
7
|
-
export declare function mapSplitRequestToWire(input: OrchestratorSplitRequest):
|
|
8
|
+
export declare function mapSplitRequestToWire(input: OrchestratorSplitRequest): WireSplitRequest;
|
|
8
9
|
export declare function mapSplitResultFromWire(value: unknown): OrchestratorSplitResult;
|
|
9
10
|
//# sourceMappingURL=mappers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mappers.d.ts","sourceRoot":"","sources":["../../../../clients/orchestrator/mappers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mappers.d.ts","sourceRoot":"","sources":["../../../../clients/orchestrator/mappers.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EACV,yBAAyB,EACzB,wBAAwB,EACxB,qBAAqB,EAErB,yBAAyB,EACzB,wBAAwB,EACxB,wBAAwB,EACxB,uBAAuB,EACxB,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,EAEV,yBAAyB,EAIzB,gBAAgB,EAEhB,gBAAgB,EAEjB,MAAM,QAAQ,CAAA;AAEf,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,yBAAyB,GAC/B,gBAAgB,CA2BlB;AAED,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,OAAO,GACb,yBAAyB,CAM3B;AAED,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,wBAAwB,GAC9B,yBAAyB,CA0B3B;AAED,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,OAAO,GACb,wBAAwB,CAwB1B;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,qBAAqB,CAuB1E;AAED,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,wBAAwB,GAC9B,gBAAgB,CAMlB;AAED,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,GACb,uBAAuB,CAgBzB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { chainIdFromReference, formatCaip2, parseCaip2, } from '../../chains/caip2.js';
|
|
1
|
+
import { chainIdFromReference, formatCaip2, isHyperCoreWireId, isNonEvmChainId, parseCaip2, } from '../../chains/caip2.js';
|
|
2
|
+
import { serializeBigInts } from './serialization.js';
|
|
2
3
|
export function mapIntentRequestToWire(input) {
|
|
3
4
|
return serializeBigInts({
|
|
4
5
|
account: input.account,
|
|
@@ -9,6 +10,8 @@ export function mapIntentRequestToWire(input) {
|
|
|
9
10
|
accountAccessList: mapAccessList(input.accountAccessList),
|
|
10
11
|
options: {
|
|
11
12
|
...input.options,
|
|
13
|
+
settlementLayers: mapSettlementLayers(input.options.settlementLayers),
|
|
14
|
+
signatureMode: input.options.signatureMode,
|
|
12
15
|
...(input.options.auxiliaryFunds
|
|
13
16
|
? {
|
|
14
17
|
auxiliaryFunds: mapChainRecord(input.options.auxiliaryFunds),
|
|
@@ -86,7 +89,7 @@ export function mapSplitRequestToWire(input) {
|
|
|
86
89
|
return serializeBigInts({
|
|
87
90
|
chainId: formatCaip2(input.chainId),
|
|
88
91
|
tokens: input.tokens,
|
|
89
|
-
settlementLayers: input.settlementLayers,
|
|
92
|
+
settlementLayers: mapSettlementLayers(input.settlementLayers),
|
|
90
93
|
});
|
|
91
94
|
}
|
|
92
95
|
export function mapSplitResultFromWire(value) {
|
|
@@ -149,7 +152,7 @@ function mapBridgeFillFromWire(value) {
|
|
|
149
152
|
}
|
|
150
153
|
function mapAuthorizationToWire(authorization) {
|
|
151
154
|
return {
|
|
152
|
-
chainId:
|
|
155
|
+
chainId: mapAuthorizationChainIdToWire(authorization.chainId),
|
|
153
156
|
address: authorization.address,
|
|
154
157
|
nonce: authorization.nonce,
|
|
155
158
|
yParity: authorization.yParity ?? 0,
|
|
@@ -157,6 +160,17 @@ function mapAuthorizationToWire(authorization) {
|
|
|
157
160
|
s: authorization.s,
|
|
158
161
|
};
|
|
159
162
|
}
|
|
163
|
+
function mapAuthorizationChainIdToWire(chainId) {
|
|
164
|
+
if (chainId === 0)
|
|
165
|
+
return 0;
|
|
166
|
+
if (!Number.isSafeInteger(chainId) ||
|
|
167
|
+
chainId < 0 ||
|
|
168
|
+
isHyperCoreWireId(chainId) ||
|
|
169
|
+
isNonEvmChainId(chainId)) {
|
|
170
|
+
throw new Error(`Invalid EIP-7702 authorization chain ID: ${chainId}`);
|
|
171
|
+
}
|
|
172
|
+
return `eip155:${chainId}`;
|
|
173
|
+
}
|
|
160
174
|
function mapAccessList(input) {
|
|
161
175
|
if (!input)
|
|
162
176
|
return undefined;
|
|
@@ -171,6 +185,10 @@ function mapAccessList(input) {
|
|
|
171
185
|
: {}),
|
|
172
186
|
};
|
|
173
187
|
}
|
|
188
|
+
function mapSettlementLayers(input) {
|
|
189
|
+
// Keep the legacy public string arrays while checking the rest of the wire shape.
|
|
190
|
+
return input;
|
|
191
|
+
}
|
|
174
192
|
function mapChainRecord(input) {
|
|
175
193
|
return Object.fromEntries(Object.entries(input).map(([chainId, value]) => [
|
|
176
194
|
formatCaip2(Number(chainId)),
|
|
@@ -186,13 +204,3 @@ function parseChainValue(value) {
|
|
|
186
204
|
return Number(value);
|
|
187
205
|
return chainIdFromReference(parseCaip2(value));
|
|
188
206
|
}
|
|
189
|
-
function serializeBigInts(value) {
|
|
190
|
-
if (typeof value === 'bigint')
|
|
191
|
-
return value.toString();
|
|
192
|
-
if (Array.isArray(value))
|
|
193
|
-
return value.map(serializeBigInts);
|
|
194
|
-
if (value && typeof value === 'object') {
|
|
195
|
-
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, serializeBigInts(item)]));
|
|
196
|
-
}
|
|
197
|
-
return value;
|
|
198
|
-
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type Serialized<T> = T extends bigint ? string : T extends readonly (infer Item)[] ? Serialized<Item>[] : T extends string | number | boolean | null | undefined ? T : T extends object ? {
|
|
2
|
+
[Key in keyof T]: Serialized<T[Key]>;
|
|
3
|
+
} : T;
|
|
4
|
+
export declare function serializeBigInts<T>(value: T): Serialized<T>;
|
|
5
|
+
//# sourceMappingURL=serialization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialization.d.ts","sourceRoot":"","sources":["../../../../clients/orchestrator/serialization.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GACxC,MAAM,GACN,CAAC,SAAS,SAAS,CAAC,MAAM,IAAI,CAAC,EAAE,GAC/B,UAAU,CAAC,IAAI,CAAC,EAAE,GAClB,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,GACpD,CAAC,GACD,CAAC,SAAS,MAAM,GACd;KAAG,GAAG,IAAI,MAAM,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;CAAE,GACxC,CAAC,CAAA;AAEX,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAW3D"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function serializeBigInts(value) {
|
|
2
|
+
if (typeof value === 'bigint')
|
|
3
|
+
return value.toString();
|
|
4
|
+
if (Array.isArray(value)) {
|
|
5
|
+
return value.map(serializeBigInts);
|
|
6
|
+
}
|
|
7
|
+
if (value && typeof value === 'object') {
|
|
8
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, serializeBigInts(item)]));
|
|
9
|
+
}
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import type { operations } from './wire.gen.js';
|
|
2
|
+
type JsonRequest<Operation extends keyof operations> = operations[Operation] extends {
|
|
3
|
+
requestBody: {
|
|
4
|
+
content: {
|
|
5
|
+
'application/json': infer Body;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
} ? Body : never;
|
|
2
9
|
type JsonResponse<Operation extends keyof operations> = NonNullable<operations[Operation]['responses'] extends {
|
|
3
10
|
200: infer Ok;
|
|
4
11
|
} ? Ok extends {
|
|
@@ -9,6 +16,14 @@ type JsonResponse<Operation extends keyof operations> = NonNullable<operations[O
|
|
|
9
16
|
type Folded<Body> = Body & {
|
|
10
17
|
readonly traceId?: string;
|
|
11
18
|
};
|
|
19
|
+
export type WireQuoteRequest = JsonRequest<'createQuote'>;
|
|
20
|
+
export type WireIntentRequest = JsonRequest<'createIntent'>;
|
|
21
|
+
export type WireIntentRequestInternal = WireIntentRequest & {
|
|
22
|
+
readonly options?: {
|
|
23
|
+
readonly dryRun?: boolean;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export type WireSplitRequest = JsonRequest<'getSplit'>;
|
|
12
27
|
export type WireQuoteResponse = Folded<JsonResponse<'createQuote'>>;
|
|
13
28
|
export type WireQuote = WireQuoteResponse['routes'][number];
|
|
14
29
|
export type WirePortfolioResponse = Folded<JsonResponse<'getPortfolio'>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wire.d.ts","sourceRoot":"","sources":["../../../../clients/orchestrator/wire.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAE5C,KAAK,YAAY,CAAC,SAAS,SAAS,MAAM,UAAU,IAAI,WAAW,CACjE,UAAU,CAAC,SAAS,CAAC,CAAC,WAAW,CAAC,SAAS;IAAE,GAAG,EAAE,MAAM,EAAE,CAAA;CAAE,GACxD,EAAE,SAAS;IAAE,OAAO,EAAE;QAAE,kBAAkB,EAAE,MAAM,IAAI,CAAA;KAAE,CAAA;CAAE,GACxD,IAAI,GACJ,KAAK,GACP,KAAK,CACV,CAAA;AAID,KAAK,MAAM,CAAC,IAAI,IAAI,IAAI,GAAG;IAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAExD,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,YAAY,CAAC,aAA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