@vlayer/sdk 0.1.0-nightly-20241122-7018b34 → 0.1.0-nightly-20241125-736efe7
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/api/email/dnsResolver.js +8 -1
- package/dist/api/email/dnsResolver.test.js +5 -0
- package/dist/api/lib/client.js +33 -2
- package/dist/api/lib/types/viem.d.ts +1 -1
- package/dist/api/lib/types/vlayer.d.ts +16 -0
- package/dist/api/lib/types/webProofProvider.d.ts +4 -3
- package/dist/api/prover.d.ts +1 -1
- package/dist/api/prover.js +2 -1
- package/dist/api/webProof/createWebProofRequest.d.ts +2 -0
- package/dist/api/webProof/createWebProofRequest.js +9 -0
- package/dist/api/webProof/index.d.ts +1 -1
- package/dist/api/webProof/index.js +1 -1
- package/dist/api/webProof/providers/extension.js +21 -10
- package/package.json +1 -1
- package/dist/api/webProof/createWebProof.d.ts +0 -2
- package/dist/api/webProof/createWebProof.js +0 -7
@@ -2,5 +2,12 @@ import DnsResolver from "dns-over-http-resolver";
|
|
2
2
|
export async function resolveDkimDns(domain, selector) {
|
3
3
|
const resolver = new DnsResolver();
|
4
4
|
const address = await resolver.resolveTxt(`${selector}._domainkey.${domain}`);
|
5
|
-
|
5
|
+
let record = address.flat().at(-1);
|
6
|
+
if (!record) {
|
7
|
+
throw new Error("No DKIM DNS record found");
|
8
|
+
}
|
9
|
+
if (record?.startsWith("p=")) {
|
10
|
+
record = ["v=DKIM1", "k=rsa", record].join("; ");
|
11
|
+
}
|
12
|
+
return record;
|
6
13
|
}
|
@@ -6,6 +6,11 @@ describe("resolveDkimDns Integration", () => {
|
|
6
6
|
const expected = "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3gWcOhCm99qzN+h7/2+LeP3CLsJkQQ4EP/2mrceXle5pKq8uZmBl1U4d2Vxn4w+pWFANDLmcHolLboESLFqEL5N6ae7u9b236dW4zn9AFkXAGenTzQEeif9VUFtLAZ0Qh2eV7OQgz/vPj5IaNqJ7h9hpM9gO031fe4v+J0DLCE8Rgo7hXbNgJavctc0983DaCDQaznHZ44LZ6TtZv9TBs+QFvsy4+UCTfsuOtHzoEqOOuXsVXZKLP6B882XbEnBpXEF8QzV4J26HiAJFUbO3mAqZL2UeKC0hhzoIZqZXNG0BfuzOF0VLpDa18GYMUiu+LhEJPJO9D8zhzvQIHNrpGwIDAQAB";
|
7
7
|
expect(resolved).toBe(expected);
|
8
8
|
});
|
9
|
+
test("resolves delegated dns", async () => {
|
10
|
+
const resolved = await resolveDkimDns("bolt.eu", "el7njvpsjxbr7wk7l7dss5ejzvijzoeu");
|
11
|
+
const expected = "v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDQxwOEYMZS2rPORBB94iL47Ute8zb1SUNl7K0zCQMk+M83AJHcwKjnJVhA4F0rLbSxY7cxJgl57lN4Vp5k10HHOil00oIn1S0ChBKHiFCQAMHCNonwDOdJa6mXwe2VwEM7hnVpRc/Eo0F0acpNMeYJxyLcTcOuZBNzcPm6t+4uTwIDAQAB";
|
12
|
+
expect(resolved).toBe(expected);
|
13
|
+
});
|
9
14
|
test("throws error if dns not found", async () => {
|
10
15
|
await expect(resolveDkimDns("not-a-domain.com", "abcd")).rejects.toThrow();
|
11
16
|
});
|
package/dist/api/lib/client.js
CHANGED
@@ -18,9 +18,9 @@ export const createVlayerClient = ({ url = "http://127.0.0.1:3000", webProofProv
|
|
18
18
|
}) => {
|
19
19
|
const resultHashMap = new Map();
|
20
20
|
return {
|
21
|
-
prove: async ({ address, functionName, chainId, proverAbi, args }) => {
|
21
|
+
prove: async ({ address, functionName, chainId, gasLimit, proverAbi, args, }) => {
|
22
22
|
webProofProvider.notifyZkProvingStatus(ZkProvingStatus.Proving);
|
23
|
-
const response = prove(address, proverAbi, functionName, args, chainId, url)
|
23
|
+
const response = prove(address, proverAbi, functionName, args, chainId, gasLimit, url)
|
24
24
|
.catch((error) => {
|
25
25
|
webProofProvider.notifyZkProvingStatus(ZkProvingStatus.Error);
|
26
26
|
throw error;
|
@@ -51,5 +51,36 @@ export const createVlayerClient = ({ url = "http://127.0.0.1:3000", webProofProv
|
|
51
51
|
}));
|
52
52
|
return [proof, ...result];
|
53
53
|
},
|
54
|
+
proveWeb: async function ({ address, proverAbi, functionName, chainId, args, }) {
|
55
|
+
const webProofPlaceholder = args[0];
|
56
|
+
const commitmentArgs = args.slice(1);
|
57
|
+
const webProof = await webProofProvider.getWebProof({
|
58
|
+
proverCallCommitment: {
|
59
|
+
address,
|
60
|
+
proverAbi,
|
61
|
+
functionName,
|
62
|
+
commitmentArgs,
|
63
|
+
chainId,
|
64
|
+
},
|
65
|
+
logoUrl: webProofPlaceholder.logoUrl,
|
66
|
+
steps: webProofPlaceholder.steps,
|
67
|
+
});
|
68
|
+
const hash = await this.prove({
|
69
|
+
address,
|
70
|
+
functionName,
|
71
|
+
chainId,
|
72
|
+
proverAbi,
|
73
|
+
args: [
|
74
|
+
{
|
75
|
+
webProofJson: JSON.stringify({
|
76
|
+
tls_proof: webProof,
|
77
|
+
notary_pub_key: webProofPlaceholder.notaryPubKey,
|
78
|
+
}),
|
79
|
+
},
|
80
|
+
...commitmentArgs,
|
81
|
+
],
|
82
|
+
});
|
83
|
+
return hash;
|
84
|
+
},
|
54
85
|
};
|
55
86
|
};
|
@@ -4,5 +4,5 @@ type Without<T extends readonly unknown[], P> = T extends readonly [
|
|
4
4
|
infer F,
|
5
5
|
...infer R
|
6
6
|
] ? F extends P ? Without<R, P> : readonly [F, ...Without<R, P>] : [];
|
7
|
-
export type ContractFunctionArgsWithout<abi extends Abi, functionName extends ContractFunctionName<abi>, without> = AbiParametersToPrimitiveTypes<Without<ExtractAbiFunction<abi extends Abi ? abi : Abi, functionName>["inputs"], without>, "inputs"
|
7
|
+
export type ContractFunctionArgsWithout<abi extends Abi, functionName extends ContractFunctionName<abi>, without> = AbiParametersToPrimitiveTypes<Without<ExtractAbiFunction<abi extends Abi ? abi : Abi, functionName>["inputs"], without>, "inputs">;
|
8
8
|
export {};
|
@@ -1,5 +1,7 @@
|
|
1
1
|
import { Branded } from "../../../web-proof-commons/utils.js";
|
2
2
|
import { Abi, AbiStateMutability, Address, ContractFunctionArgs, ContractFunctionName, ContractFunctionReturnType, Hex } from "viem";
|
3
|
+
import { WebProofRequest } from "./webProofProvider.js";
|
4
|
+
import { ContractFunctionArgsWithout } from "./viem.js";
|
3
5
|
type Calldata = string;
|
4
6
|
export type CallParams = {
|
5
7
|
to: Address;
|
@@ -7,6 +9,7 @@ export type CallParams = {
|
|
7
9
|
};
|
8
10
|
export type CallContext = {
|
9
11
|
chain_id: number;
|
12
|
+
gas_limit: number;
|
10
13
|
};
|
11
14
|
export type BrandedHash<T, F> = Branded<{
|
12
15
|
hash: string;
|
@@ -42,8 +45,21 @@ export type VlayerClient = {
|
|
42
45
|
proverAbi: T;
|
43
46
|
functionName: F;
|
44
47
|
chainId?: number;
|
48
|
+
gasLimit?: number;
|
45
49
|
args: ContractFunctionArgs<T, AbiStateMutability, F>;
|
46
50
|
}) => Promise<BrandedHash<T, F>>;
|
47
51
|
waitForProvingResult: <T extends Abi, F extends ContractFunctionName<T>>(hash: BrandedHash<T, F>) => Promise<ContractFunctionReturnType<T, AbiStateMutability, F>>;
|
52
|
+
proveWeb: <T extends Abi, F extends ContractFunctionName<T>>(args: {
|
53
|
+
address: Hex;
|
54
|
+
proverAbi: T;
|
55
|
+
functionName: F;
|
56
|
+
chainId: number;
|
57
|
+
args: [
|
58
|
+
WebProofRequest,
|
59
|
+
...ContractFunctionArgsWithout<T, F, {
|
60
|
+
name: "webProof";
|
61
|
+
}>
|
62
|
+
];
|
63
|
+
}) => Promise<BrandedHash<T, F>>;
|
48
64
|
};
|
49
65
|
export {};
|
@@ -1,11 +1,12 @@
|
|
1
1
|
import { Hex, Abi, ContractFunctionName } from "viem";
|
2
2
|
import type { ContractFunctionArgsWithout } from "./viem.js";
|
3
3
|
import { Branded, ExtensionMessageType, ExtensionMessage, WebProof, WebProofStep, ZkProvingStatus } from "../../../web-proof-commons/index.js";
|
4
|
-
export type
|
4
|
+
export type WebProofRequestInput = {
|
5
5
|
logoUrl: string;
|
6
6
|
steps: WebProofStep[];
|
7
|
+
notaryPubKey?: string;
|
7
8
|
};
|
8
|
-
export type
|
9
|
+
export type WebProofRequest = Branded<WebProofRequestInput & {
|
9
10
|
isWebProof: true;
|
10
11
|
}, "webProof">;
|
11
12
|
export type ProverCallCommitment<T extends Abi, F extends ContractFunctionName<T>> = {
|
@@ -19,7 +20,7 @@ export type ProverCallCommitment<T extends Abi, F extends ContractFunctionName<T
|
|
19
20
|
};
|
20
21
|
export type GetWebProofArgs<T extends Abi, F extends ContractFunctionName<T>> = {
|
21
22
|
proverCallCommitment: ProverCallCommitment<T, F>;
|
22
|
-
} &
|
23
|
+
} & WebProofRequestInput;
|
23
24
|
export type WebProofProvider = {
|
24
25
|
getWebProof: <T extends Abi, F extends ContractFunctionName<T>>(args: GetWebProofArgs<T, F>) => Promise<WebProof>;
|
25
26
|
requestWebProof: <T extends Abi, F extends ContractFunctionName<T>>(args: GetWebProofArgs<T, F>) => void;
|
package/dist/api/prover.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
import { type Abi, AbiStateMutability, type Address, ContractFunctionArgs, ContractFunctionName } from "viem";
|
2
|
-
export declare function prove<T extends Abi, F extends ContractFunctionName<T>>(prover: Address, abi: T, functionName: F, args: ContractFunctionArgs<T, AbiStateMutability, F>, chainId?: number, url?: string): Promise<import("./lib/types/vlayer.js").VCallResponse>;
|
2
|
+
export declare function prove<T extends Abi, F extends ContractFunctionName<T>>(prover: Address, abi: T, functionName: F, args: ContractFunctionArgs<T, AbiStateMutability, F>, chainId?: number, gasLimit?: number, url?: string): Promise<import("./lib/types/vlayer.js").VCallResponse>;
|
package/dist/api/prover.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { encodeFunctionData, } from "viem";
|
2
2
|
import { v_call } from "./v_call.js";
|
3
3
|
import { foundry } from "viem/chains";
|
4
|
-
export async function prove(prover, abi, functionName, args, chainId = foundry.id, url = "http://127.0.0.1:3000") {
|
4
|
+
export async function prove(prover, abi, functionName, args, chainId = foundry.id, gasLimit = 1_000_000, url = "http://127.0.0.1:3000") {
|
5
5
|
const calldata = encodeFunctionData({
|
6
6
|
abi: abi,
|
7
7
|
functionName: functionName,
|
@@ -10,6 +10,7 @@ export async function prove(prover, abi, functionName, args, chainId = foundry.i
|
|
10
10
|
const call = { to: prover, data: calldata };
|
11
11
|
const context = {
|
12
12
|
chain_id: chainId,
|
13
|
+
gas_limit: gasLimit,
|
13
14
|
};
|
14
15
|
return v_call(call, context, url);
|
15
16
|
}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
const NOTARY_PUB_KEY = "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAExpX/4R4z40gI6C/j9zAM39u58LJu\n3Cx5tXTuqhhu/tirnBi5GniMmspOTEsps4ANnPLpMmMSfhJ+IFHbc3qVOA==\n-----END PUBLIC KEY-----\n";
|
2
|
+
export const createWebProofRequest = ({ logoUrl, steps, notaryPubKey = NOTARY_PUB_KEY, }) => {
|
3
|
+
return {
|
4
|
+
logoUrl,
|
5
|
+
steps,
|
6
|
+
notaryPubKey,
|
7
|
+
isWebProof: true,
|
8
|
+
};
|
9
|
+
};
|
@@ -11,10 +11,21 @@ class ExtensionWebProofProvider {
|
|
11
11
|
}
|
12
12
|
notifyZkProvingStatus(status) {
|
13
13
|
if (typeof chrome !== "undefined") {
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
// Chrome does not provide reliable api to check if given extension is installed
|
15
|
+
// what we could do is to use management api but
|
16
|
+
// 1) this will need to provided extra permission
|
17
|
+
// 2) still is not reliable because this api becomes defined when first extension that uses it is installed
|
18
|
+
// so still will need to try catch
|
19
|
+
try {
|
20
|
+
chrome.runtime.sendMessage(EXTENSION_ID, {
|
21
|
+
action: "NotifyZkProvingStatus" /* ExtensionAction.NotifyZkProvingStatus */,
|
22
|
+
payload: { status },
|
23
|
+
});
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
25
|
+
}
|
26
|
+
catch (e) {
|
27
|
+
console.log("Cant send message", "look that extension is not installed ");
|
28
|
+
}
|
18
29
|
}
|
19
30
|
}
|
20
31
|
connectToExtension() {
|
@@ -42,26 +53,26 @@ class ExtensionWebProofProvider {
|
|
42
53
|
}
|
43
54
|
this.listeners[messageType].push(listener);
|
44
55
|
}
|
45
|
-
requestWebProof(
|
56
|
+
requestWebProof(webProofRequest) {
|
46
57
|
this.connectToExtension().postMessage({
|
47
58
|
action: "RequestWebProof" /* ExtensionAction.RequestWebProof */,
|
48
59
|
payload: {
|
49
60
|
notaryUrl: this.notaryUrl,
|
50
61
|
wsProxyUrl: this.wsProxyUrl,
|
51
|
-
logoUrl:
|
52
|
-
steps:
|
62
|
+
logoUrl: webProofRequest.logoUrl,
|
63
|
+
steps: webProofRequest.steps,
|
53
64
|
},
|
54
65
|
});
|
55
66
|
}
|
56
|
-
async getWebProof(
|
67
|
+
async getWebProof(webProofRequest) {
|
57
68
|
return new Promise((resolve, reject) => {
|
58
69
|
chrome.runtime.sendMessage(EXTENSION_ID, {
|
59
70
|
action: "RequestWebProof" /* ExtensionAction.RequestWebProof */,
|
60
71
|
payload: {
|
61
72
|
notaryUrl: this.notaryUrl,
|
62
73
|
wsProxyUrl: this.wsProxyUrl,
|
63
|
-
logoUrl:
|
64
|
-
steps:
|
74
|
+
logoUrl: webProofRequest.logoUrl,
|
75
|
+
steps: webProofRequest.steps,
|
65
76
|
},
|
66
77
|
});
|
67
78
|
this.connectToExtension().onMessage.addListener((message) => {
|
package/package.json
CHANGED