Skip to content

Commit fe6e34c

Browse files
0xalexbelzmalatrax
andauthored
chore: fix rety-after issue + improvements (#375)
* chore: fix bug retry-after * chore: exclude test-dom from tsconfig * 0.4.0-alpha.1 * chore: fix doc * chore: v0.4.0-alpha.1 * chore: prettier * chore: add file autogenerated message in _version.ts * Update src/relayer-provider/v2/RelayerV2Provider_input-proof.test.ts Co-authored-by: malatrax <71888134+zmalatrax@users.noreply.github.com> * chore: prettier fix * chore: unify use of FheTypeId and add extra asserts * chore: add mainnet config * chore: add comments * chore: fix gen version script * chore: typo * chore: fix ci linkinspector when checking npmjs * chore: fix2 ci linkinspector when checking npmjs * chore: fix3 ci linkinspector when checking npmjs --------- Co-authored-by: malatrax <71888134+zmalatrax@users.noreply.github.com>
1 parent 465eb26 commit fe6e34c

71 files changed

Lines changed: 1838 additions & 1328 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/linkchecker.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
uses: umbrelladocs/action-linkspector@652f85bc57bb1e7d4327260decc10aa68f7694c3 # v1.4.0
3434
with:
3535
filter_mode: nofilter
36-
config_file: .linkspector.yml
36+
config_file: .github/config/.linkspector.yml
3737
github_token: ${{ secrets.github_token }}
3838
reporter: github-pr-review
3939
fail_level: any

bundle.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ export {
1111
FhevmInstanceConfig,
1212
createInstance,
1313
EncryptionBits,
14-
ENCRYPTION_TYPES,
1514
UserDecryptResults,
1615
PublicDecryptResults,
1716
ClearValueType,
1817
ClearValues,
1918
initSDK,
2019
SepoliaConfig,
20+
MainnetConfig,
2121
Auth,
2222
BearerToken,
2323
ApiKeyCookie,

docs/webapp.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Include this line at the top of your project.
3636

3737
```html
3838
<script
39-
src="https://cdn.zama.org/relayer-sdk-js/0.3.0-5/relayer-sdk-js.umd.cjs"
39+
src="https://cdn.zama.org/relayer-sdk-js/0.3.0-7/relayer-sdk-js.umd.cjs"
4040
type="text/javascript"
4141
></script>
4242
```
@@ -61,7 +61,7 @@ If you prefer You can also use the `@zama-fhe/relayer-sdk` as a ES module:
6161
initSDK,
6262
createInstance,
6363
SepoliaConfig,
64-
} from 'https://cdn.zama.org/relayer-sdk-js/0.3.0-5/relayer-sdk-js.umd.cjs';
64+
} from 'https://cdn.zama.org/relayer-sdk-js/0.3.0-7/relayer-sdk-js.umd.cjs';
6565
6666
await initSDK();
6767
const config = { ...SepoliaConfig, network: window.ethereum };

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@zama-fhe/relayer-sdk",
3-
"version": "0.4.0-alpha.0",
3+
"version": "0.4.0-alpha.1",
44
"description": "fhevm Relayer SDK",
55
"main": "lib/node.js",
66
"types": "lib/node.d.ts",
@@ -45,8 +45,11 @@
4545
"clean": "rm -rf dist.tmp lib bundle coverage",
4646
"clean:dts": "rm -rf dist.tmp",
4747
"tsc:dts": "tsc --project config/tsconfig.dts.json",
48+
"tsc:ts": "tsc --project ./tsconfig.json --noEmit",
49+
"tsc:ts:test": "tsc --project ./tsconfig.test.json --noEmit",
4850
"flatten:dts": "api-extractor run --local --config config/api-extractor.node.json && api-extractor run --local --config config/api-extractor.web.json",
49-
"build:dts": "npm run clean:dts && npm run tsc:dts && npm run flatten:dts && npm run clean:dts"
51+
"build:dts": "npm run clean:dts && npm run tsc:dts && npm run flatten:dts && npm run clean:dts",
52+
"version": "cd ./scripts && node ./generate-version.cjs"
5053
},
5154
"repository": {
5255
"type": "git",

scripts/generate-version.cjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const pkgPath = path.resolve(__dirname, '../package.json');
5+
6+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
7+
const version = pkg.version;
8+
9+
const out = `// This file is auto-generated
10+
export const version: string = "${version}";
11+
export const sdkName: string = "${pkg.name}";\n`;
12+
13+
const outputPath = path.resolve(__dirname, '../src/_version.ts');
14+
15+
fs.writeFileSync(outputPath, out);
16+
17+
console.log(`✅ Generated ${outputPath} (version: ${version})`);

src/_version.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// This file is auto-generated
2+
export const version: string = '0.4.0-alpha.1';
3+
export const sdkName: string = '@zama-fhe/relayer-sdk';

src/auth.ts

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,4 @@
1-
/**
2-
* Bearer Token Authentication
3-
*/
4-
export type BearerToken = {
5-
__type: 'BearerToken';
6-
/**
7-
* The Bearer token.
8-
*/
9-
token: string;
10-
};
11-
12-
/**
13-
* Custom header authentication
14-
*/
15-
export type ApiKeyHeader = {
16-
__type: 'ApiKeyHeader';
17-
/**
18-
* The header name. The default value is `x-api-key`.
19-
*/
20-
header?: string;
21-
/**
22-
* The API key.
23-
*/
24-
value: string;
25-
};
26-
27-
/**
28-
* Custom cookie authentication
29-
*/
30-
export type ApiKeyCookie = {
31-
__type: 'ApiKeyCookie';
32-
/**
33-
* The cookie name. The default value is `x-api-key`.
34-
*/
35-
cookie?: string;
36-
/**
37-
* The API key.
38-
*/
39-
value: string;
40-
};
1+
import type { Auth } from './types/relayer';
412

423
/**
434
* Set the authentication method for the request. The default is no authentication.
@@ -46,7 +7,6 @@ export type ApiKeyCookie = {
467
* - Custom header
478
* - Custom cookie
489
*/
49-
export type Auth = BearerToken | ApiKeyHeader | ApiKeyCookie;
5010
export function setAuth(init: RequestInit, auth?: Auth): RequestInit {
5111
if (auth) {
5212
switch (auth.__type) {

src/config.ts

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@ import {
55
JsonRpcProvider,
66
Provider,
77
} from 'ethers';
8-
import { PublicParams } from './sdk/encrypt';
8+
import type { PublicParams } from './sdk/encrypt';
99
import { getKeysFromRelayer } from './relayer/network';
1010
import {
1111
SERIALIZED_SIZE_LIMIT_PK,
1212
SERIALIZED_SIZE_LIMIT_CRS,
1313
} from './constants';
1414
import type { TFHEType } from './tfheType';
15-
import { Auth } from './auth';
16-
import { Prettify } from './utils/types';
1715
import { removeSuffix } from './utils/string';
16+
import type { FhevmInstanceConfig } from './types/relayer';
1817

1918
const abiKmsVerifier = [
2019
'function getKmsSigners() view returns (address[])',
@@ -26,29 +25,6 @@ const abiInputVerifier = [
2625
'function getThreshold() view returns (uint256)',
2726
];
2827

29-
export type FhevmInstanceOptions = {
30-
auth?: Auth;
31-
};
32-
33-
export type FhevmInstanceConfig = Prettify<
34-
{
35-
verifyingContractAddressDecryption: string;
36-
verifyingContractAddressInputVerification: string;
37-
kmsContractAddress: string;
38-
inputVerifierContractAddress: string;
39-
aclContractAddress: string;
40-
gatewayChainId: number;
41-
chainId?: number;
42-
relayerUrl?: string;
43-
network?: Eip1193Provider | string;
44-
publicParams?: PublicParams<Uint8Array> | null;
45-
publicKey?: {
46-
data: Uint8Array | null;
47-
id: string | null;
48-
};
49-
} & FhevmInstanceOptions
50-
>;
51-
5228
export const getProvider = (network: string | Eip1193Provider | undefined) => {
5329
if (typeof network === 'string') {
5430
return new JsonRpcProvider(network);

src/errors/ACLError.ts

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { Prettify } from '../utils/types';
22
import { Bytes32Hex, ChecksummedAddress } from '../types/primitives';
3-
import { RelayerErrorBase, RelayerErrorBaseParams } from './RelayerErrorBase';
3+
import {
4+
ContractErrorBase,
5+
ContractErrorBaseParams,
6+
} from './ContractErrorBase';
47

58
////////////////////////////////////////////////////////////////////////////////
69
// ACLErrorBase
@@ -11,28 +14,22 @@ export type ACLErrorBaseType = ACLErrorBase & {
1114
};
1215

1316
export type ACLErrorBaseParams = Prettify<
14-
RelayerErrorBaseParams & {
15-
aclAddress: ChecksummedAddress;
17+
ContractErrorBaseParams & {
1618
handle: Bytes32Hex;
1719
}
1820
>;
1921

20-
export abstract class ACLErrorBase extends RelayerErrorBase {
21-
private readonly _aclAddress: ChecksummedAddress;
22+
export abstract class ACLErrorBase extends ContractErrorBase {
2223
private readonly _handle: Bytes32Hex;
2324

2425
constructor(params: ACLErrorBaseParams) {
2526
super({
2627
...params,
2728
name: params.name ?? 'ACLErrorBase',
2829
});
29-
this._aclAddress = params.aclAddress;
3030
this._handle = params.handle;
3131
}
3232

33-
public get aclAddress() {
34-
return this._aclAddress;
35-
}
3633
public get handle() {
3734
return this._handle;
3835
}
@@ -46,19 +43,55 @@ export type ACLPublicDecryptionErrorType = ACLPublicDecryptionError & {
4643
name: 'ACLPublicDecryptionError';
4744
};
4845

49-
export class ACLPublicDecryptionError extends ACLErrorBase {
46+
export class ACLPublicDecryptionError extends ContractErrorBase {
47+
private readonly _handles: Bytes32Hex[];
48+
5049
constructor({
51-
aclAddress,
52-
handle,
50+
contractAddress,
51+
handles,
5352
}: {
54-
aclAddress: ChecksummedAddress;
55-
handle: Bytes32Hex;
53+
contractAddress: ChecksummedAddress;
54+
handles: Bytes32Hex[];
5655
}) {
56+
const handleList = handles.join(', ');
5757
super({
58-
message: `Handle ${handle} is not allowed for public decryption!`,
58+
message:
59+
handles.length === 1
60+
? `Handle ${handles[0]} is not allowed for public decryption`
61+
: `${handles.length} handles are not allowed for public decryption: ${handleList}`,
5962
name: 'ACLPublicDecryptionError',
60-
aclAddress,
61-
handle,
63+
contractAddress,
64+
contractName: 'ACL',
65+
});
66+
this._handles = handles;
67+
}
68+
69+
public get handles(): Bytes32Hex[] {
70+
return this._handles;
71+
}
72+
}
73+
74+
////////////////////////////////////////////////////////////////////////////////
75+
// ACLUserDecryptionError
76+
////////////////////////////////////////////////////////////////////////////////
77+
78+
export type ACLUserDecryptionErrorType = ACLUserDecryptionError & {
79+
name: 'ACLUserDecryptionError';
80+
};
81+
82+
export class ACLUserDecryptionError extends ContractErrorBase {
83+
constructor({
84+
contractAddress,
85+
message,
86+
}: {
87+
contractAddress: ChecksummedAddress;
88+
message: string;
89+
}) {
90+
super({
91+
message,
92+
name: 'ACLUserDecryptionError',
93+
contractAddress,
94+
contractName: 'ACL',
6295
});
6396
}
6497
}

0 commit comments

Comments
 (0)