@appliedblockchain/silentdatarollup-core 1.0.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 +17 -0
- package/dist/chunk-BIZ7KJDG.mjs +561 -0
- package/dist/index.d.mts +205 -0
- package/dist/index.d.ts +205 -0
- package/dist/index.js +621 -0
- package/dist/index.mjs +60 -0
- package/dist/tests.d.mts +29 -0
- package/dist/tests.d.ts +29 -0
- package/dist/tests.js +109 -0
- package/dist/tests.mjs +56 -0
- package/package.json +49 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { Signer, JsonRpcPayload, Contract, TypedDataDomain, TypedDataField, InterfaceAbi, ContractRunner } from 'ethers';
|
|
2
|
+
|
|
3
|
+
declare const SIGN_RPC_METHODS: string[];
|
|
4
|
+
declare const eip721Domain: {
|
|
5
|
+
name: string;
|
|
6
|
+
version: string;
|
|
7
|
+
};
|
|
8
|
+
declare const delegateEIP721Types: {
|
|
9
|
+
Ticket: {
|
|
10
|
+
name: string;
|
|
11
|
+
type: string;
|
|
12
|
+
}[];
|
|
13
|
+
};
|
|
14
|
+
declare const DEBUG_NAMESPACE = "silentdata:core";
|
|
15
|
+
declare const DEBUG_NAMESPACE_SILENTDATA_INTERCEPTOR = "silentdata:interceptor";
|
|
16
|
+
declare const HEADER_SIGNATURE = "x-signature";
|
|
17
|
+
declare const HEADER_TIMESTAMP = "x-timestamp";
|
|
18
|
+
declare const HEADER_EIP712_SIGNATURE = "x-eip712-signature";
|
|
19
|
+
declare const HEADER_DELEGATE = "x-delegate";
|
|
20
|
+
declare const HEADER_DELEGATE_SIGNATURE = "x-delegate-signature";
|
|
21
|
+
declare const HEADER_EIP712_DELEGATE_SIGNATURE = "x-eip712-delegate-signature";
|
|
22
|
+
declare const DEFAULT_DELEGATE_EXPIRES: number;
|
|
23
|
+
/**
|
|
24
|
+
* A buffer time (in seconds) added to the current time when verifying the validity of a delegate.
|
|
25
|
+
* This ensures that if the current time plus the buffer exceeds the delegate's expiry date,
|
|
26
|
+
* the delegate is considered expired.
|
|
27
|
+
*/
|
|
28
|
+
declare const DELEGATE_EXPIRATION_THRESHOLD_BUFFER = 5;
|
|
29
|
+
declare const WHITELISTED_METHODS: string[];
|
|
30
|
+
|
|
31
|
+
declare enum ChainId {
|
|
32
|
+
MAINNET = 51966,
|
|
33
|
+
TESTNET = 1001
|
|
34
|
+
}
|
|
35
|
+
declare enum NetworkName {
|
|
36
|
+
MAINNET = "sdr",
|
|
37
|
+
TESTNET = "sdr-testnet"
|
|
38
|
+
}
|
|
39
|
+
declare enum SignatureType {
|
|
40
|
+
Raw = "RAW",
|
|
41
|
+
EIP191 = "EIP191",
|
|
42
|
+
EIP712 = "EIP712"
|
|
43
|
+
}
|
|
44
|
+
interface SilentDataProviderOptions {
|
|
45
|
+
authSignatureType?: SignatureType;
|
|
46
|
+
}
|
|
47
|
+
interface SilentdataNetworkConfig {
|
|
48
|
+
authSignatureType?: SignatureType;
|
|
49
|
+
}
|
|
50
|
+
type DelegateConfig = {
|
|
51
|
+
getDelegate: (provider: any) => Promise<Signer>;
|
|
52
|
+
expires: number;
|
|
53
|
+
};
|
|
54
|
+
type BaseConfig = {
|
|
55
|
+
/**
|
|
56
|
+
* Enables auth header signing by a delegate signer.
|
|
57
|
+
* Configuration for optional delegate functionality.
|
|
58
|
+
* - true: Uses default delegate configuration.
|
|
59
|
+
* - object: Allows customization of delegate behavior.
|
|
60
|
+
* - undefined/false: Disables delegate functionality.
|
|
61
|
+
*/
|
|
62
|
+
delegate?: boolean | {
|
|
63
|
+
/**
|
|
64
|
+
* Custom function to get a delegate signer.
|
|
65
|
+
* If not provided, defaults to the defaultGetDelegate function.
|
|
66
|
+
*/
|
|
67
|
+
getDelegate?: (provider: any) => Promise<Signer>;
|
|
68
|
+
/**
|
|
69
|
+
* Expiration time for the delegate in seconds.
|
|
70
|
+
* If not provided, defaults to DEFAULT_DELEGATE_EXPIRES.
|
|
71
|
+
*/
|
|
72
|
+
expires?: number;
|
|
73
|
+
};
|
|
74
|
+
authSignatureType?: SignatureType;
|
|
75
|
+
};
|
|
76
|
+
type DelegateSignerMessage = {
|
|
77
|
+
expires: string;
|
|
78
|
+
ephemeralAddress: string;
|
|
79
|
+
};
|
|
80
|
+
type AuthSignatureMessage = {
|
|
81
|
+
request: AuthSignatureMessageRequest | AuthSignatureMessageRequest[];
|
|
82
|
+
timestamp: string;
|
|
83
|
+
};
|
|
84
|
+
type AuthSignatureMessageRequest = Omit<JsonRpcPayload, 'params'> & {
|
|
85
|
+
params: string;
|
|
86
|
+
};
|
|
87
|
+
type AuthHeaders = {
|
|
88
|
+
[HEADER_TIMESTAMP]: string;
|
|
89
|
+
[HEADER_SIGNATURE]?: string;
|
|
90
|
+
[HEADER_EIP712_SIGNATURE]?: string;
|
|
91
|
+
};
|
|
92
|
+
type DelegateHeaders = {
|
|
93
|
+
[HEADER_DELEGATE]: string;
|
|
94
|
+
[HEADER_DELEGATE_SIGNATURE]?: string;
|
|
95
|
+
[HEADER_EIP712_DELEGATE_SIGNATURE]?: string;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
declare class SilentDataRollupBase {
|
|
99
|
+
config: BaseConfig;
|
|
100
|
+
private delegateConfig;
|
|
101
|
+
private currentDelegateSigner;
|
|
102
|
+
private delegateSignerExpires;
|
|
103
|
+
private cachedDelegateHeaders;
|
|
104
|
+
private cachedHeadersExpiry;
|
|
105
|
+
contract: Contract | null;
|
|
106
|
+
contractMethodsToSign: string[];
|
|
107
|
+
constructor(config: BaseConfig);
|
|
108
|
+
private resolveDelegateConfig;
|
|
109
|
+
getDelegateSigner(provider: any): Promise<Signer | null>;
|
|
110
|
+
getDelegateSignerMessage(provider: any): Promise<DelegateSignerMessage | null>;
|
|
111
|
+
/**
|
|
112
|
+
* Signs a raw delegate header message.
|
|
113
|
+
* This method can be overridden by extending classes to customize the signing process.
|
|
114
|
+
* @param provider - The provider used for signing
|
|
115
|
+
* @param message - The delegate signer message to be signed
|
|
116
|
+
* @returns A promise that resolves to the signature string
|
|
117
|
+
*/
|
|
118
|
+
protected signRawDelegateHeader(provider: any, message: DelegateSignerMessage): Promise<string>;
|
|
119
|
+
/**
|
|
120
|
+
* Signs a typed delegate header message.
|
|
121
|
+
* This method can be overridden by extending classes to customize the signing process.
|
|
122
|
+
* @param provider - The provider used for signing
|
|
123
|
+
* @param message - The delegate signer message to be signed
|
|
124
|
+
* @returns A promise that resolves to the signature string
|
|
125
|
+
*/
|
|
126
|
+
protected signTypedDelegateHeader(provider: any, message: DelegateSignerMessage): Promise<string>;
|
|
127
|
+
getDelegateHeaders(provider: any): Promise<DelegateHeaders>;
|
|
128
|
+
getAuthHeaders(provider: any, payload: JsonRpcPayload | JsonRpcPayload[]): Promise<AuthHeaders>;
|
|
129
|
+
signAuthHeaderRawMessage(provider: any, payload: JsonRpcPayload | JsonRpcPayload[], timestamp: string): Promise<string>;
|
|
130
|
+
signAuthHeaderTypedData(provider: any, payload: JsonRpcPayload | JsonRpcPayload[], timestamp: string): Promise<string>;
|
|
131
|
+
/**
|
|
132
|
+
* Signs a message using the provided signer.
|
|
133
|
+
* This method can be overridden to customize the signing process.
|
|
134
|
+
* @param signer - The signer to use
|
|
135
|
+
* @param message - The message to sign
|
|
136
|
+
* @returns A promise that resolves to the signature string
|
|
137
|
+
*/
|
|
138
|
+
protected signMessage(signer: any, message: string): Promise<string>;
|
|
139
|
+
/**
|
|
140
|
+
* Signs typed data using the provided signer.
|
|
141
|
+
* This method can be overridden to customize the signing process.
|
|
142
|
+
* @param signer - The signer to use
|
|
143
|
+
* @param domain - The EIP-712 domain
|
|
144
|
+
* @param types - The EIP-712 types
|
|
145
|
+
* @param message - The message to sign
|
|
146
|
+
* @returns A promise that resolves to the signature string
|
|
147
|
+
*/
|
|
148
|
+
protected signTypedData(signer: any, domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, message: Record<string, any>): Promise<string>;
|
|
149
|
+
setContract(contract: Contract, contractMethodsToSign: string[]): void;
|
|
150
|
+
/**
|
|
151
|
+
* Prepares the message to be signed for the x-signature header.
|
|
152
|
+
*/
|
|
153
|
+
prepareSignatureMessage(payload: JsonRpcPayload | JsonRpcPayload[], timestamp: string): string;
|
|
154
|
+
/**
|
|
155
|
+
* Prepares the message to be signed for the x-eip712-signature header.
|
|
156
|
+
*/
|
|
157
|
+
prepareSignatureTypedData(payload: JsonRpcPayload | JsonRpcPayload[], timestamp: string): AuthSignatureMessage;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
declare class SilentDataRollupContract extends Contract {
|
|
161
|
+
constructor(address: string, abi: InterfaceAbi, runner: ContractRunner, contractMethodsToSign: string[]);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
declare function getAuthEIP721Types(payload: JsonRpcPayload | JsonRpcPayload[]): {
|
|
165
|
+
Call: {
|
|
166
|
+
name: string;
|
|
167
|
+
type: string;
|
|
168
|
+
}[];
|
|
169
|
+
JsonRPCRequest: {
|
|
170
|
+
name: string;
|
|
171
|
+
type: string;
|
|
172
|
+
}[];
|
|
173
|
+
};
|
|
174
|
+
declare function signAuthHeaderTypedData(signer: any, payload: JsonRpcPayload | JsonRpcPayload[], timestamp: string): Promise<string>;
|
|
175
|
+
declare function signAuthHeaderRawMessage(signer: any, payload: JsonRpcPayload | JsonRpcPayload[], timestamp: string): Promise<string>;
|
|
176
|
+
declare function signTypedDelegateHeader(signer: any, message: DelegateSignerMessage): Promise<any>;
|
|
177
|
+
declare function signRawDelegateHeader(signer: any, message: DelegateSignerMessage): Promise<string>;
|
|
178
|
+
declare function getAuthHeaders(signer: Signer, payload: JsonRpcPayload | JsonRpcPayload[], signatureType: SignatureType): Promise<AuthHeaders>;
|
|
179
|
+
/**
|
|
180
|
+
* Determines if a given JSON-RPC payload represents a call to a contract method that requires signing.
|
|
181
|
+
*
|
|
182
|
+
* This function is crucial for identifying "private" read calls on smart contracts - methods that
|
|
183
|
+
* require authenticated `msg.sender`. It helps ensure proper authentication for accessing
|
|
184
|
+
* sensitive data or functionality on the contract side.
|
|
185
|
+
*
|
|
186
|
+
* The function performs the following checks:
|
|
187
|
+
* 1. Verifies if the payload is an `eth_call`.
|
|
188
|
+
* 2. Extracts the method signature from the call data.
|
|
189
|
+
* 3. Compares the signature against a provided list of methods requiring signing.
|
|
190
|
+
* 4. Uses the contract's ABI to match the method signature with known methods.
|
|
191
|
+
*
|
|
192
|
+
* By accurately identifying these calls, we can add appropriate authentication headers
|
|
193
|
+
* to the request, enabling the smart contract to verify the caller's identity.
|
|
194
|
+
*
|
|
195
|
+
* @param payload - The JSON-RPC payload to analyze.
|
|
196
|
+
* @param contractMethodsToSign - An array of method names that require signing.
|
|
197
|
+
* @param contract - The contract instance containing the ABI information.
|
|
198
|
+
* @returns {boolean} True if the call is to a method that requires signing, false otherwise.
|
|
199
|
+
* @throws {Error} If contractMethodsToSign or contract is not provided.
|
|
200
|
+
*/
|
|
201
|
+
declare function isSignableContractCall(payload: JsonRpcPayload, contractMethodsToSign?: string[], contract?: Contract | null): boolean;
|
|
202
|
+
declare const defaultGetDelegate: (provider: any) => Promise<Signer>;
|
|
203
|
+
declare const prepareTypedDataPayload: (p: JsonRpcPayload) => AuthSignatureMessageRequest;
|
|
204
|
+
|
|
205
|
+
export { type AuthHeaders, type AuthSignatureMessage, type AuthSignatureMessageRequest, type BaseConfig, ChainId, DEBUG_NAMESPACE, DEBUG_NAMESPACE_SILENTDATA_INTERCEPTOR, DEFAULT_DELEGATE_EXPIRES, DELEGATE_EXPIRATION_THRESHOLD_BUFFER, type DelegateConfig, type DelegateHeaders, type DelegateSignerMessage, HEADER_DELEGATE, HEADER_DELEGATE_SIGNATURE, HEADER_EIP712_DELEGATE_SIGNATURE, HEADER_EIP712_SIGNATURE, HEADER_SIGNATURE, HEADER_TIMESTAMP, NetworkName, SIGN_RPC_METHODS, SignatureType, type SilentDataProviderOptions, SilentDataRollupBase, SilentDataRollupContract, type SilentdataNetworkConfig, WHITELISTED_METHODS, defaultGetDelegate, delegateEIP721Types, eip721Domain, getAuthEIP721Types, getAuthHeaders, isSignableContractCall, prepareTypedDataPayload, signAuthHeaderRawMessage, signAuthHeaderTypedData, signRawDelegateHeader, signTypedDelegateHeader };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { Signer, JsonRpcPayload, Contract, TypedDataDomain, TypedDataField, InterfaceAbi, ContractRunner } from 'ethers';
|
|
2
|
+
|
|
3
|
+
declare const SIGN_RPC_METHODS: string[];
|
|
4
|
+
declare const eip721Domain: {
|
|
5
|
+
name: string;
|
|
6
|
+
version: string;
|
|
7
|
+
};
|
|
8
|
+
declare const delegateEIP721Types: {
|
|
9
|
+
Ticket: {
|
|
10
|
+
name: string;
|
|
11
|
+
type: string;
|
|
12
|
+
}[];
|
|
13
|
+
};
|
|
14
|
+
declare const DEBUG_NAMESPACE = "silentdata:core";
|
|
15
|
+
declare const DEBUG_NAMESPACE_SILENTDATA_INTERCEPTOR = "silentdata:interceptor";
|
|
16
|
+
declare const HEADER_SIGNATURE = "x-signature";
|
|
17
|
+
declare const HEADER_TIMESTAMP = "x-timestamp";
|
|
18
|
+
declare const HEADER_EIP712_SIGNATURE = "x-eip712-signature";
|
|
19
|
+
declare const HEADER_DELEGATE = "x-delegate";
|
|
20
|
+
declare const HEADER_DELEGATE_SIGNATURE = "x-delegate-signature";
|
|
21
|
+
declare const HEADER_EIP712_DELEGATE_SIGNATURE = "x-eip712-delegate-signature";
|
|
22
|
+
declare const DEFAULT_DELEGATE_EXPIRES: number;
|
|
23
|
+
/**
|
|
24
|
+
* A buffer time (in seconds) added to the current time when verifying the validity of a delegate.
|
|
25
|
+
* This ensures that if the current time plus the buffer exceeds the delegate's expiry date,
|
|
26
|
+
* the delegate is considered expired.
|
|
27
|
+
*/
|
|
28
|
+
declare const DELEGATE_EXPIRATION_THRESHOLD_BUFFER = 5;
|
|
29
|
+
declare const WHITELISTED_METHODS: string[];
|
|
30
|
+
|
|
31
|
+
declare enum ChainId {
|
|
32
|
+
MAINNET = 51966,
|
|
33
|
+
TESTNET = 1001
|
|
34
|
+
}
|
|
35
|
+
declare enum NetworkName {
|
|
36
|
+
MAINNET = "sdr",
|
|
37
|
+
TESTNET = "sdr-testnet"
|
|
38
|
+
}
|
|
39
|
+
declare enum SignatureType {
|
|
40
|
+
Raw = "RAW",
|
|
41
|
+
EIP191 = "EIP191",
|
|
42
|
+
EIP712 = "EIP712"
|
|
43
|
+
}
|
|
44
|
+
interface SilentDataProviderOptions {
|
|
45
|
+
authSignatureType?: SignatureType;
|
|
46
|
+
}
|
|
47
|
+
interface SilentdataNetworkConfig {
|
|
48
|
+
authSignatureType?: SignatureType;
|
|
49
|
+
}
|
|
50
|
+
type DelegateConfig = {
|
|
51
|
+
getDelegate: (provider: any) => Promise<Signer>;
|
|
52
|
+
expires: number;
|
|
53
|
+
};
|
|
54
|
+
type BaseConfig = {
|
|
55
|
+
/**
|
|
56
|
+
* Enables auth header signing by a delegate signer.
|
|
57
|
+
* Configuration for optional delegate functionality.
|
|
58
|
+
* - true: Uses default delegate configuration.
|
|
59
|
+
* - object: Allows customization of delegate behavior.
|
|
60
|
+
* - undefined/false: Disables delegate functionality.
|
|
61
|
+
*/
|
|
62
|
+
delegate?: boolean | {
|
|
63
|
+
/**
|
|
64
|
+
* Custom function to get a delegate signer.
|
|
65
|
+
* If not provided, defaults to the defaultGetDelegate function.
|
|
66
|
+
*/
|
|
67
|
+
getDelegate?: (provider: any) => Promise<Signer>;
|
|
68
|
+
/**
|
|
69
|
+
* Expiration time for the delegate in seconds.
|
|
70
|
+
* If not provided, defaults to DEFAULT_DELEGATE_EXPIRES.
|
|
71
|
+
*/
|
|
72
|
+
expires?: number;
|
|
73
|
+
};
|
|
74
|
+
authSignatureType?: SignatureType;
|
|
75
|
+
};
|
|
76
|
+
type DelegateSignerMessage = {
|
|
77
|
+
expires: string;
|
|
78
|
+
ephemeralAddress: string;
|
|
79
|
+
};
|
|
80
|
+
type AuthSignatureMessage = {
|
|
81
|
+
request: AuthSignatureMessageRequest | AuthSignatureMessageRequest[];
|
|
82
|
+
timestamp: string;
|
|
83
|
+
};
|
|
84
|
+
type AuthSignatureMessageRequest = Omit<JsonRpcPayload, 'params'> & {
|
|
85
|
+
params: string;
|
|
86
|
+
};
|
|
87
|
+
type AuthHeaders = {
|
|
88
|
+
[HEADER_TIMESTAMP]: string;
|
|
89
|
+
[HEADER_SIGNATURE]?: string;
|
|
90
|
+
[HEADER_EIP712_SIGNATURE]?: string;
|
|
91
|
+
};
|
|
92
|
+
type DelegateHeaders = {
|
|
93
|
+
[HEADER_DELEGATE]: string;
|
|
94
|
+
[HEADER_DELEGATE_SIGNATURE]?: string;
|
|
95
|
+
[HEADER_EIP712_DELEGATE_SIGNATURE]?: string;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
declare class SilentDataRollupBase {
|
|
99
|
+
config: BaseConfig;
|
|
100
|
+
private delegateConfig;
|
|
101
|
+
private currentDelegateSigner;
|
|
102
|
+
private delegateSignerExpires;
|
|
103
|
+
private cachedDelegateHeaders;
|
|
104
|
+
private cachedHeadersExpiry;
|
|
105
|
+
contract: Contract | null;
|
|
106
|
+
contractMethodsToSign: string[];
|
|
107
|
+
constructor(config: BaseConfig);
|
|
108
|
+
private resolveDelegateConfig;
|
|
109
|
+
getDelegateSigner(provider: any): Promise<Signer | null>;
|
|
110
|
+
getDelegateSignerMessage(provider: any): Promise<DelegateSignerMessage | null>;
|
|
111
|
+
/**
|
|
112
|
+
* Signs a raw delegate header message.
|
|
113
|
+
* This method can be overridden by extending classes to customize the signing process.
|
|
114
|
+
* @param provider - The provider used for signing
|
|
115
|
+
* @param message - The delegate signer message to be signed
|
|
116
|
+
* @returns A promise that resolves to the signature string
|
|
117
|
+
*/
|
|
118
|
+
protected signRawDelegateHeader(provider: any, message: DelegateSignerMessage): Promise<string>;
|
|
119
|
+
/**
|
|
120
|
+
* Signs a typed delegate header message.
|
|
121
|
+
* This method can be overridden by extending classes to customize the signing process.
|
|
122
|
+
* @param provider - The provider used for signing
|
|
123
|
+
* @param message - The delegate signer message to be signed
|
|
124
|
+
* @returns A promise that resolves to the signature string
|
|
125
|
+
*/
|
|
126
|
+
protected signTypedDelegateHeader(provider: any, message: DelegateSignerMessage): Promise<string>;
|
|
127
|
+
getDelegateHeaders(provider: any): Promise<DelegateHeaders>;
|
|
128
|
+
getAuthHeaders(provider: any, payload: JsonRpcPayload | JsonRpcPayload[]): Promise<AuthHeaders>;
|
|
129
|
+
signAuthHeaderRawMessage(provider: any, payload: JsonRpcPayload | JsonRpcPayload[], timestamp: string): Promise<string>;
|
|
130
|
+
signAuthHeaderTypedData(provider: any, payload: JsonRpcPayload | JsonRpcPayload[], timestamp: string): Promise<string>;
|
|
131
|
+
/**
|
|
132
|
+
* Signs a message using the provided signer.
|
|
133
|
+
* This method can be overridden to customize the signing process.
|
|
134
|
+
* @param signer - The signer to use
|
|
135
|
+
* @param message - The message to sign
|
|
136
|
+
* @returns A promise that resolves to the signature string
|
|
137
|
+
*/
|
|
138
|
+
protected signMessage(signer: any, message: string): Promise<string>;
|
|
139
|
+
/**
|
|
140
|
+
* Signs typed data using the provided signer.
|
|
141
|
+
* This method can be overridden to customize the signing process.
|
|
142
|
+
* @param signer - The signer to use
|
|
143
|
+
* @param domain - The EIP-712 domain
|
|
144
|
+
* @param types - The EIP-712 types
|
|
145
|
+
* @param message - The message to sign
|
|
146
|
+
* @returns A promise that resolves to the signature string
|
|
147
|
+
*/
|
|
148
|
+
protected signTypedData(signer: any, domain: TypedDataDomain, types: Record<string, Array<TypedDataField>>, message: Record<string, any>): Promise<string>;
|
|
149
|
+
setContract(contract: Contract, contractMethodsToSign: string[]): void;
|
|
150
|
+
/**
|
|
151
|
+
* Prepares the message to be signed for the x-signature header.
|
|
152
|
+
*/
|
|
153
|
+
prepareSignatureMessage(payload: JsonRpcPayload | JsonRpcPayload[], timestamp: string): string;
|
|
154
|
+
/**
|
|
155
|
+
* Prepares the message to be signed for the x-eip712-signature header.
|
|
156
|
+
*/
|
|
157
|
+
prepareSignatureTypedData(payload: JsonRpcPayload | JsonRpcPayload[], timestamp: string): AuthSignatureMessage;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
declare class SilentDataRollupContract extends Contract {
|
|
161
|
+
constructor(address: string, abi: InterfaceAbi, runner: ContractRunner, contractMethodsToSign: string[]);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
declare function getAuthEIP721Types(payload: JsonRpcPayload | JsonRpcPayload[]): {
|
|
165
|
+
Call: {
|
|
166
|
+
name: string;
|
|
167
|
+
type: string;
|
|
168
|
+
}[];
|
|
169
|
+
JsonRPCRequest: {
|
|
170
|
+
name: string;
|
|
171
|
+
type: string;
|
|
172
|
+
}[];
|
|
173
|
+
};
|
|
174
|
+
declare function signAuthHeaderTypedData(signer: any, payload: JsonRpcPayload | JsonRpcPayload[], timestamp: string): Promise<string>;
|
|
175
|
+
declare function signAuthHeaderRawMessage(signer: any, payload: JsonRpcPayload | JsonRpcPayload[], timestamp: string): Promise<string>;
|
|
176
|
+
declare function signTypedDelegateHeader(signer: any, message: DelegateSignerMessage): Promise<any>;
|
|
177
|
+
declare function signRawDelegateHeader(signer: any, message: DelegateSignerMessage): Promise<string>;
|
|
178
|
+
declare function getAuthHeaders(signer: Signer, payload: JsonRpcPayload | JsonRpcPayload[], signatureType: SignatureType): Promise<AuthHeaders>;
|
|
179
|
+
/**
|
|
180
|
+
* Determines if a given JSON-RPC payload represents a call to a contract method that requires signing.
|
|
181
|
+
*
|
|
182
|
+
* This function is crucial for identifying "private" read calls on smart contracts - methods that
|
|
183
|
+
* require authenticated `msg.sender`. It helps ensure proper authentication for accessing
|
|
184
|
+
* sensitive data or functionality on the contract side.
|
|
185
|
+
*
|
|
186
|
+
* The function performs the following checks:
|
|
187
|
+
* 1. Verifies if the payload is an `eth_call`.
|
|
188
|
+
* 2. Extracts the method signature from the call data.
|
|
189
|
+
* 3. Compares the signature against a provided list of methods requiring signing.
|
|
190
|
+
* 4. Uses the contract's ABI to match the method signature with known methods.
|
|
191
|
+
*
|
|
192
|
+
* By accurately identifying these calls, we can add appropriate authentication headers
|
|
193
|
+
* to the request, enabling the smart contract to verify the caller's identity.
|
|
194
|
+
*
|
|
195
|
+
* @param payload - The JSON-RPC payload to analyze.
|
|
196
|
+
* @param contractMethodsToSign - An array of method names that require signing.
|
|
197
|
+
* @param contract - The contract instance containing the ABI information.
|
|
198
|
+
* @returns {boolean} True if the call is to a method that requires signing, false otherwise.
|
|
199
|
+
* @throws {Error} If contractMethodsToSign or contract is not provided.
|
|
200
|
+
*/
|
|
201
|
+
declare function isSignableContractCall(payload: JsonRpcPayload, contractMethodsToSign?: string[], contract?: Contract | null): boolean;
|
|
202
|
+
declare const defaultGetDelegate: (provider: any) => Promise<Signer>;
|
|
203
|
+
declare const prepareTypedDataPayload: (p: JsonRpcPayload) => AuthSignatureMessageRequest;
|
|
204
|
+
|
|
205
|
+
export { type AuthHeaders, type AuthSignatureMessage, type AuthSignatureMessageRequest, type BaseConfig, ChainId, DEBUG_NAMESPACE, DEBUG_NAMESPACE_SILENTDATA_INTERCEPTOR, DEFAULT_DELEGATE_EXPIRES, DELEGATE_EXPIRATION_THRESHOLD_BUFFER, type DelegateConfig, type DelegateHeaders, type DelegateSignerMessage, HEADER_DELEGATE, HEADER_DELEGATE_SIGNATURE, HEADER_EIP712_DELEGATE_SIGNATURE, HEADER_EIP712_SIGNATURE, HEADER_SIGNATURE, HEADER_TIMESTAMP, NetworkName, SIGN_RPC_METHODS, SignatureType, type SilentDataProviderOptions, SilentDataRollupBase, SilentDataRollupContract, type SilentdataNetworkConfig, WHITELISTED_METHODS, defaultGetDelegate, delegateEIP721Types, eip721Domain, getAuthEIP721Types, getAuthHeaders, isSignableContractCall, prepareTypedDataPayload, signAuthHeaderRawMessage, signAuthHeaderTypedData, signRawDelegateHeader, signTypedDelegateHeader };
|