@magicnewton/newton-protocol-sdk 0.5.3 → 0.5.4

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.
@@ -1,82 +0,0 @@
1
- import { type SimulatePolicyDataParams, type SimulatePolicyDataResult, type SimulatePolicyDataWithClientParams, type SimulatePolicyDataWithClientResult, type SimulatePolicyParams, type SimulatePolicyResult, type SimulateTaskParams, type SimulateTaskResult, type SubmitEvaluationRequestParams, type SubmitIntentResult, type Task, type TaskId, type TaskResponseResult, TaskStatus } from '@core/types/task';
2
- import { type Address, type PublicClient as Client, type Hex, type WalletClient } from 'viem';
3
- export interface CreateTaskResult {
4
- task_id: Hex;
5
- task_request: unknown;
6
- status: 'Completed' | 'Failed';
7
- aggregation_response: unknown;
8
- timestamp: number;
9
- error?: unknown;
10
- }
11
- export interface PendingTaskBuilder {
12
- readonly taskId?: TaskId;
13
- waitForTaskResponded: ({ timeoutMs, }: {
14
- timeoutMs?: number;
15
- }) => Promise<TaskResponseResult>;
16
- }
17
- declare const waitForTaskResponded: (publicClient: Client, args: {
18
- taskId?: Hex;
19
- timeoutMs?: number;
20
- abortSignal?: AbortSignal;
21
- }, taskManagerAddress: Address, taskRequestedAtBlock?: bigint) => Promise<TaskResponseResult>;
22
- declare const getTaskResponseHash: (publicClient: Client, args: {
23
- taskId: TaskId;
24
- }, taskManagerAddress: Address) => Promise<Hex | null>;
25
- declare const getTaskStatus: (publicClient: Client, args: {
26
- taskId: TaskId;
27
- }, taskManagerAddress: Address, attestationValidatorAddress: Address) => Promise<TaskStatus>;
28
- declare function submitEvaluationRequest(walletClient: WalletClient, args: SubmitEvaluationRequestParams, taskManagerAddress: Address, apiKey: string, gatewayApiUrlOverride?: string): Promise<{
29
- result: {
30
- taskId: Hex;
31
- txHash: Hex;
32
- };
33
- } & PendingTaskBuilder>;
34
- /**
35
- * Evaluate intent directly without waiting for task response confirmation on source chain.
36
- * Results are to be used with `validateAttestationDirect` on NewtonPolicyClient (NewtonProverTaskManagerShared)
37
- *
38
- * @param walletClient - Wallet client
39
- * @param args - Evaluation request parameters
40
- * @param apiKey - API key
41
- * @param gatewayApiUrlOverride - Gateway API URL override
42
- * @returns Evaluation result
43
- */
44
- declare function evaluateIntentDirect(walletClient: WalletClient, args: SubmitEvaluationRequestParams, apiKey: string, gatewayApiUrlOverride?: string): Promise<{
45
- result: {
46
- evaluationResult: boolean;
47
- task: Task;
48
- taskResponse: unknown;
49
- blsSignature: unknown;
50
- };
51
- }>;
52
- /**
53
- * Submit intent and subscribe to task response on source chain (this will be slower but can be used to challenge the task evaluation)
54
- * Results are to be used with `validateAttestation` on NewtonPolicyClient (NewtonProverTaskManager)
55
- *
56
- * @param walletClient - Wallet client
57
- * @param args
58
- * @param apiKey
59
- * @param gatewayApiUrlOverride
60
- * @returns
61
- */
62
- declare function submitIntentAndSubscribe(walletClient: WalletClient, args: SubmitEvaluationRequestParams, apiKey: string, gatewayApiUrlOverride?: string): Promise<{
63
- result: SubmitIntentResult;
64
- ws: WebSocket;
65
- }>;
66
- /**
67
- * Simulates task evaluation (newt_simulateTask). Forwards to an operator and returns allow/deny without executing on-chain.
68
- */
69
- declare function simulateTask(walletClient: WalletClient, args: SimulateTaskParams, apiKey: string, gatewayApiUrlOverride?: string): Promise<SimulateTaskResult>;
70
- /**
71
- * Simulates full Rego policy evaluation (newt_simulatePolicy). Tests policy with sample intent and policy data; may require ownership if PolicyData uses stored secrets.
72
- */
73
- declare function simulatePolicy(walletClient: WalletClient, args: SimulatePolicyParams, apiKey: string, gatewayApiUrlOverride?: string): Promise<SimulatePolicyResult>;
74
- /**
75
- * Simulates PolicyData WASM execution with caller-provided secrets (newt_simulatePolicyData). No ownership verification.
76
- */
77
- declare function simulatePolicyData(walletClient: WalletClient, args: SimulatePolicyDataParams, apiKey: string, gatewayApiUrlOverride?: string): Promise<SimulatePolicyDataResult>;
78
- /**
79
- * Simulates PolicyData WASM execution with stored secrets for a policy client (newt_simulatePolicyDataWithClient). Requires ownership.
80
- */
81
- declare function simulatePolicyDataWithClient(walletClient: WalletClient, args: SimulatePolicyDataWithClientParams, apiKey: string, gatewayApiUrlOverride?: string): Promise<SimulatePolicyDataWithClientResult>;
82
- export { submitEvaluationRequest, waitForTaskResponded, getTaskResponseHash, getTaskStatus, evaluateIntentDirect, submitIntentAndSubscribe, simulateTask, simulatePolicy, simulatePolicyData, simulatePolicyDataWithClient, };
@@ -1,228 +0,0 @@
1
- import type { PolicyId, PolicyParamsJson } from '@core/types/policy';
2
- import { type Address, type PublicClient, type WalletClient } from 'viem';
3
- export declare const policyWriteFunctions: {
4
- initialize: ({ walletClient, policyContractAddress, ...args }: {
5
- walletClient: WalletClient;
6
- policyContractAddress: Address;
7
- factory: Address;
8
- entrypoint: string;
9
- policyCid: string;
10
- schemaCid: string;
11
- policyData: Address[];
12
- metadataCid: string;
13
- owner: Address;
14
- }) => Promise<`0x${string}`>;
15
- renounceOwnership: ({ walletClient, policyContractAddress, }: {
16
- walletClient: WalletClient;
17
- policyContractAddress: Address;
18
- }) => Promise<`0x${string}`>;
19
- transferOwnership: ({ walletClient, policyContractAddress, ...args }: {
20
- walletClient: WalletClient;
21
- policyContractAddress: Address;
22
- newOwner: Address;
23
- }) => Promise<`0x${string}`>;
24
- };
25
- export declare const policyReadFunctions: {
26
- getPolicyId: ({ publicClient, policyContractAddress, client, }: {
27
- publicClient: PublicClient;
28
- policyContractAddress: Address;
29
- client: Address;
30
- }) => Promise<`0x${string}`>;
31
- getPolicyConfig: ({ publicClient, policyContractAddress, policyId, }: {
32
- publicClient: PublicClient;
33
- policyContractAddress: Address;
34
- policyId: `0x${string}`;
35
- }) => Promise<{
36
- policyParams: string | object;
37
- policyParamsHex: `0x${string}`;
38
- expireAfter: number;
39
- }>;
40
- supportsInterface: ({ publicClient, policyContractAddress, interfaceId, }: {
41
- publicClient: PublicClient;
42
- policyContractAddress: Address;
43
- interfaceId: `0x${string}`;
44
- }) => Promise<boolean>;
45
- owner: ({ publicClient, policyContractAddress, }: {
46
- publicClient: PublicClient;
47
- policyContractAddress: Address;
48
- }) => Promise<Address>;
49
- factory: ({ publicClient, policyContractAddress, }: {
50
- publicClient: PublicClient;
51
- policyContractAddress: Address;
52
- }) => Promise<Address>;
53
- entrypoint: ({ publicClient, policyContractAddress, }: {
54
- publicClient: PublicClient;
55
- policyContractAddress: Address;
56
- }) => Promise<string>;
57
- clientToPolicyId: ({ publicClient, policyContractAddress, client, }: {
58
- publicClient: PublicClient;
59
- policyContractAddress: Address;
60
- client: Address;
61
- }) => Promise<`0x${string}`>;
62
- policyData: ({ publicClient, policyContractAddress, index, }: {
63
- publicClient: PublicClient;
64
- policyContractAddress: Address;
65
- index: number;
66
- }) => Promise<Address>;
67
- getEntrypoint: ({ publicClient, policyContractAddress, }: {
68
- publicClient: PublicClient;
69
- policyContractAddress: Address;
70
- }) => Promise<string>;
71
- getMetadataCid: ({ publicClient, policyContractAddress, }: {
72
- publicClient: PublicClient;
73
- policyContractAddress: Address;
74
- }) => Promise<string>;
75
- getPolicyCid: ({ publicClient, policyContractAddress, }: {
76
- publicClient: PublicClient;
77
- policyContractAddress: Address;
78
- }) => Promise<string>;
79
- getPolicyData: ({ publicClient, policyContractAddress, }: {
80
- publicClient: PublicClient;
81
- policyContractAddress: Address;
82
- }) => Promise<Address[]>;
83
- getSchemaCid: ({ publicClient, policyContractAddress, }: {
84
- publicClient: PublicClient;
85
- policyContractAddress: Address;
86
- }) => Promise<string>;
87
- isPolicyVerified: ({ publicClient, policyContractAddress, }: {
88
- publicClient: PublicClient;
89
- policyContractAddress: Address;
90
- }) => Promise<boolean>;
91
- metadataCid: ({ publicClient, policyContractAddress, }: {
92
- publicClient: PublicClient;
93
- policyContractAddress: Address;
94
- }) => Promise<string>;
95
- policyCid: ({ publicClient, policyContractAddress, }: {
96
- publicClient: PublicClient;
97
- policyContractAddress: Address;
98
- }) => Promise<string>;
99
- schemaCid: ({ publicClient, policyContractAddress, }: {
100
- publicClient: PublicClient;
101
- policyContractAddress: Address;
102
- }) => Promise<string>;
103
- precomputePolicyId: ({ publicClient, policyContractAddress, ...args }: {
104
- publicClient: PublicClient;
105
- policyContractAddress: Address;
106
- policyContract: Address;
107
- policyData: Address[];
108
- params: PolicyParamsJson;
109
- client: Address;
110
- policyUri: string;
111
- schemaUri: string;
112
- entrypoint: string;
113
- expireAfter?: number;
114
- blockTimestamp?: bigint;
115
- }) => PolicyId;
116
- };
117
- export declare const policyFunctions: {
118
- initialize: ({ walletClient, policyContractAddress, ...args }: {
119
- walletClient: WalletClient;
120
- policyContractAddress: Address;
121
- factory: Address;
122
- entrypoint: string;
123
- policyCid: string;
124
- schemaCid: string;
125
- policyData: Address[];
126
- metadataCid: string;
127
- owner: Address;
128
- }) => Promise<`0x${string}`>;
129
- renounceOwnership: ({ walletClient, policyContractAddress, }: {
130
- walletClient: WalletClient;
131
- policyContractAddress: Address;
132
- }) => Promise<`0x${string}`>;
133
- transferOwnership: ({ walletClient, policyContractAddress, ...args }: {
134
- walletClient: WalletClient;
135
- policyContractAddress: Address;
136
- newOwner: Address;
137
- }) => Promise<`0x${string}`>;
138
- getPolicyId: ({ publicClient, policyContractAddress, client, }: {
139
- publicClient: PublicClient;
140
- policyContractAddress: Address;
141
- client: Address;
142
- }) => Promise<`0x${string}`>;
143
- getPolicyConfig: ({ publicClient, policyContractAddress, policyId, }: {
144
- publicClient: PublicClient;
145
- policyContractAddress: Address;
146
- policyId: `0x${string}`;
147
- }) => Promise<{
148
- policyParams: string | object;
149
- policyParamsHex: `0x${string}`;
150
- expireAfter: number;
151
- }>;
152
- supportsInterface: ({ publicClient, policyContractAddress, interfaceId, }: {
153
- publicClient: PublicClient;
154
- policyContractAddress: Address;
155
- interfaceId: `0x${string}`;
156
- }) => Promise<boolean>;
157
- owner: ({ publicClient, policyContractAddress, }: {
158
- publicClient: PublicClient;
159
- policyContractAddress: Address;
160
- }) => Promise<Address>;
161
- factory: ({ publicClient, policyContractAddress, }: {
162
- publicClient: PublicClient;
163
- policyContractAddress: Address;
164
- }) => Promise<Address>;
165
- entrypoint: ({ publicClient, policyContractAddress, }: {
166
- publicClient: PublicClient;
167
- policyContractAddress: Address;
168
- }) => Promise<string>;
169
- clientToPolicyId: ({ publicClient, policyContractAddress, client, }: {
170
- publicClient: PublicClient;
171
- policyContractAddress: Address;
172
- client: Address;
173
- }) => Promise<`0x${string}`>;
174
- policyData: ({ publicClient, policyContractAddress, index, }: {
175
- publicClient: PublicClient;
176
- policyContractAddress: Address;
177
- index: number;
178
- }) => Promise<Address>;
179
- getEntrypoint: ({ publicClient, policyContractAddress, }: {
180
- publicClient: PublicClient;
181
- policyContractAddress: Address;
182
- }) => Promise<string>;
183
- getMetadataCid: ({ publicClient, policyContractAddress, }: {
184
- publicClient: PublicClient;
185
- policyContractAddress: Address;
186
- }) => Promise<string>;
187
- getPolicyCid: ({ publicClient, policyContractAddress, }: {
188
- publicClient: PublicClient;
189
- policyContractAddress: Address;
190
- }) => Promise<string>;
191
- getPolicyData: ({ publicClient, policyContractAddress, }: {
192
- publicClient: PublicClient;
193
- policyContractAddress: Address;
194
- }) => Promise<Address[]>;
195
- getSchemaCid: ({ publicClient, policyContractAddress, }: {
196
- publicClient: PublicClient;
197
- policyContractAddress: Address;
198
- }) => Promise<string>;
199
- isPolicyVerified: ({ publicClient, policyContractAddress, }: {
200
- publicClient: PublicClient;
201
- policyContractAddress: Address;
202
- }) => Promise<boolean>;
203
- metadataCid: ({ publicClient, policyContractAddress, }: {
204
- publicClient: PublicClient;
205
- policyContractAddress: Address;
206
- }) => Promise<string>;
207
- policyCid: ({ publicClient, policyContractAddress, }: {
208
- publicClient: PublicClient;
209
- policyContractAddress: Address;
210
- }) => Promise<string>;
211
- schemaCid: ({ publicClient, policyContractAddress, }: {
212
- publicClient: PublicClient;
213
- policyContractAddress: Address;
214
- }) => Promise<string>;
215
- precomputePolicyId: ({ publicClient, policyContractAddress, ...args }: {
216
- publicClient: PublicClient;
217
- policyContractAddress: Address;
218
- policyContract: Address;
219
- policyData: Address[];
220
- params: PolicyParamsJson;
221
- client: Address;
222
- policyUri: string;
223
- schemaUri: string;
224
- entrypoint: string;
225
- expireAfter?: number;
226
- blockTimestamp?: bigint;
227
- }) => PolicyId;
228
- };
@@ -1,77 +0,0 @@
1
- /**
2
- * Newton Privacy Module — Client-side HPKE encryption for privacy-preserving policy evaluation.
3
- *
4
- * Encryption suite: X25519 KEM + HKDF-SHA256 + ChaCha20-Poly1305 (RFC 9180, Base mode).
5
- * Compatible with the Rust gateway's `crates/core/src/crypto/hpke.rs`.
6
- *
7
- * Key design constraints:
8
- * - Zero network calls during encrypt/createSecureEnvelope
9
- * - Offline capable once the gateway public key is known
10
- * - Ephemeral keys zeroed after encryption
11
- */
12
- import type { CreateSecureEnvelopeParams, Ed25519KeyPair, PrivacyAuthorizationResult, PrivacyPublicKeyResponse, SecureEnvelopeResult, SignPrivacyAuthorizationParams, StoreEncryptedSecretsParams, StoreEncryptedSecretsResponse, UploadEncryptedDataParams, UploadEncryptedDataResponse, UploadSecureEnvelopeParams } from '@core/types/privacy';
13
- /**
14
- * Create a SecureEnvelope by encrypting plaintext with HPKE.
15
- *
16
- * This is a pure, offline function — zero network calls.
17
- * The ephemeral HPKE key is generated internally and zeroed after use.
18
- *
19
- * The caller owns the signingKey buffer lifecycle. This function creates an
20
- * internal copy for signing and zeroes it immediately after use, but the
21
- * caller is responsible for zeroing the original Uint8Array when done.
22
- *
23
- * @param params - Encryption parameters
24
- * @param signingKey - Ed25519 private key seed (32 bytes as Uint8Array)
25
- * @returns Envelope + Ed25519 signature over the serialized envelope
26
- */
27
- export declare function createSecureEnvelope(params: CreateSecureEnvelopeParams, signingKey: Uint8Array): Promise<SecureEnvelopeResult>;
28
- /**
29
- * Fetch the gateway's X25519 HPKE public key.
30
- *
31
- * Clients call this once to discover which key to encrypt SecureEnvelopes to.
32
- * The result can be cached — the key only changes on gateway restart or key rotation.
33
- */
34
- export declare function getPrivacyPublicKey(chainId: number, apiKey: string, gatewayApiUrlOverride?: string): Promise<PrivacyPublicKeyResponse>;
35
- /**
36
- * Encrypt data and upload to the gateway in a single call.
37
- *
38
- * Combines createSecureEnvelope + RPC upload. If recipientPublicKey is not
39
- * provided, it is fetched from the gateway first via newt_getPrivacyPublicKey.
40
- */
41
- export declare function uploadEncryptedData(chainId: number, apiKey: string, params: UploadEncryptedDataParams, gatewayApiUrlOverride?: string): Promise<UploadEncryptedDataResponse>;
42
- /**
43
- * Upload a pre-built SecureEnvelope to the gateway.
44
- *
45
- * Use this when you've already created an envelope via createSecureEnvelope
46
- * and want to control the upload separately — e.g., offline-first apps that
47
- * encrypt now and upload later, or batching multiple envelopes.
48
- */
49
- export declare function uploadSecureEnvelope(chainId: number, apiKey: string, params: UploadSecureEnvelopeParams, gatewayApiUrlOverride?: string): Promise<UploadEncryptedDataResponse>;
50
- /**
51
- * Generate a random Ed25519 key pair for signing envelopes and privacy authorization.
52
- *
53
- * This is a pure offline function. The private key is generated from 32 bytes of
54
- * cryptographically secure randomness via `crypto.getRandomValues`.
55
- */
56
- export declare function generateSigningKeyPair(): Ed25519KeyPair;
57
- /**
58
- * Upload KMS-encrypted secrets for a policy client's PolicyData.
59
- *
60
- * The gateway decrypts via AWS KMS, validates against the PolicyData schema,
61
- * and stores the secrets for use during policy evaluation.
62
- */
63
- export declare function storeEncryptedSecrets(chainId: number, apiKey: string, params: StoreEncryptedSecretsParams, gatewayApiUrlOverride?: string): Promise<StoreEncryptedSecretsResponse>;
64
- /**
65
- * Compute dual Ed25519 signatures for privacy-enabled task creation.
66
- *
67
- * The gateway validates these signatures when `encrypted_data_refs` are present
68
- * in a `newt_createTask` request. This prevents unauthorized use of encrypted
69
- * data references across policy contexts.
70
- *
71
- * Signature scheme (must match `crates/gateway/src/processor/privacy_auth.rs`):
72
- * - User signs: keccak256(abi.encodePacked(policy_client, intent_hash, ref_id_1, ref_id_2, ...))
73
- * - App signs: keccak256(abi.encodePacked(policy_client, intent_hash, user_signature))
74
- *
75
- * This is a pure offline function — zero network calls.
76
- */
77
- export declare function signPrivacyAuthorization(params: SignPrivacyAuthorizationParams): PrivacyAuthorizationResult;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magicnewton/newton-protocol-sdk",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "Official SDK for the Newton Protocol.",
5
5
  "author": "Newton Protocol <https://x.com/newton_xyz> (https://newton.xyz)",
6
6
  "private": false,