@celo/buy-identity 0.3.0 → 0.4.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/THIRD_PARTY_NOTICES.md +118 -0
- package/dist/config.d.ts +2 -10
- package/dist/hosted.d.ts +90 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +49083 -5
- package/dist/index.js.map +7 -1
- package/dist/receiver.d.ts +113 -0
- package/dist/types.d.ts +25 -1
- package/dist/verify.d.ts +12 -0
- package/package.json +12 -8
- package/dist/config.js +0 -51
- package/dist/config.js.map +0 -1
- package/dist/qr.js +0 -12
- package/dist/qr.js.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/verify.js +0 -88
- package/dist/verify.js.map +0 -1
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The HTTP endpoint the Self.xyz mobile app posts a proof to.
|
|
3
|
+
*
|
|
4
|
+
* This lived in the CLI, where it served exactly one caller: `buy verify serve`
|
|
5
|
+
* spins up a tunnel, holds ONE pending `VerificationRequest`, and waits for ONE
|
|
6
|
+
* proof to arrive. That shape is why the client needs `cloudflared` at all — the
|
|
7
|
+
* party that wants the attestation is made to run a public web server.
|
|
8
|
+
*
|
|
9
|
+
* Moving it here is what lets a GATEWAY host the same endpoint instead, and the
|
|
10
|
+
* move forces two changes the single-session version did not need:
|
|
11
|
+
*
|
|
12
|
+
* - `request` is resolved PER REQUEST rather than read from one variable. A
|
|
13
|
+
* server fields proofs from many callers it has never heard of, and has to
|
|
14
|
+
* decide what each one should be checked against.
|
|
15
|
+
* - persistence is a callback rather than a keystore write. The CLI stores an
|
|
16
|
+
* attestation for its own account; a server stores it for whoever proved it,
|
|
17
|
+
* somewhere durable and shared.
|
|
18
|
+
*
|
|
19
|
+
* It lives in `@celo/buy-identity` and not in `@celo/buy` because `@celo/buy`
|
|
20
|
+
* publishes a `bin` and no `main` or `exports` — nothing can import from it.
|
|
21
|
+
*/
|
|
22
|
+
import type { IncomingMessage, RequestListener } from 'node:http';
|
|
23
|
+
import type { Verification } from '@celo/buy-keystore';
|
|
24
|
+
import type { VerificationRequest } from './types.js';
|
|
25
|
+
import { type ProofPayload } from './verify.js';
|
|
26
|
+
/** Self proof JSON is normally far smaller; 256 KiB leaves ample protocol headroom. */
|
|
27
|
+
export declare const MAX_VERIFY_BODY_BYTES: number;
|
|
28
|
+
/** Default route, and the path Self posts to. Must match the pinned endpoint. */
|
|
29
|
+
export declare const DEFAULT_VERIFY_PATH = "/api/verify";
|
|
30
|
+
export declare class VerifyBodyTooLargeError extends Error {
|
|
31
|
+
constructor();
|
|
32
|
+
}
|
|
33
|
+
export declare function readVerifyBody(req: IncomingMessage): Promise<string>;
|
|
34
|
+
/**
|
|
35
|
+
* What the proof itself asserted, beside the attestation built from it.
|
|
36
|
+
*
|
|
37
|
+
* `userDefinedData` is the field that makes a hosted receiver possible. It is a
|
|
38
|
+
* slice of `userContextData`, whose hash the circuit commits to, so a value the
|
|
39
|
+
* verifier puts in there comes back bound to the proof and cannot be swapped
|
|
40
|
+
* for another. A server can therefore mint a session id, carry it through the
|
|
41
|
+
* QR, and know which of its many pending callers a proof belongs to — something
|
|
42
|
+
* a single-session receiver never had to ask.
|
|
43
|
+
*
|
|
44
|
+
* It comes in two forms because the SDK returns it hex-encoded. Match on
|
|
45
|
+
* `userDefinedDataHex` when the value identifies a session: it is the exact
|
|
46
|
+
* bytes the circuit committed to, and needs no decode anyone can disagree
|
|
47
|
+
* about. `userDefinedData` is the decoded convenience form.
|
|
48
|
+
*/
|
|
49
|
+
export type ProofContext = {
|
|
50
|
+
readonly userIdentifier: string | undefined;
|
|
51
|
+
readonly nullifier: string | undefined;
|
|
52
|
+
/** Decoded, or undefined when absent or not valid UTF-8. */
|
|
53
|
+
readonly userDefinedData: string | undefined;
|
|
54
|
+
/** The raw hex the verifier returned. Compare this for identity. */
|
|
55
|
+
readonly userDefinedDataHex: string | undefined;
|
|
56
|
+
readonly payload: ProofPayload;
|
|
57
|
+
};
|
|
58
|
+
export type ProofReceiverOptions = {
|
|
59
|
+
/**
|
|
60
|
+
* The request this proof must satisfy, resolved per incoming request.
|
|
61
|
+
*
|
|
62
|
+
* Returning `undefined` answers 503 — the CLI uses that for the window
|
|
63
|
+
* between binding the port and knowing its own tunnel URL.
|
|
64
|
+
*/
|
|
65
|
+
readonly request: (req: IncomingMessage) => VerificationRequest | undefined | Promise<VerificationRequest | undefined>;
|
|
66
|
+
/**
|
|
67
|
+
* Store the verified attestation. THROWING REJECTS THE PROOF: a server that
|
|
68
|
+
* cannot tie the proof to a pending session should throw here, and the caller
|
|
69
|
+
* is told the proof was refused rather than being told it succeeded.
|
|
70
|
+
*
|
|
71
|
+
* Runs BEFORE the response, so it must not tear anything down — see
|
|
72
|
+
* `onStored` for work that has to wait until the phone has its answer.
|
|
73
|
+
*/
|
|
74
|
+
readonly persist: (verification: Verification, context: ProofContext) => void | Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Fired once the success response has actually left, via the `finish` event.
|
|
77
|
+
*
|
|
78
|
+
* This exists because the CLI's caller reacts by shutting the server down:
|
|
79
|
+
* `verify serve` resolves, prints, and its `finally` calls
|
|
80
|
+
* `closeAllConnections()`. Driving that from `persist` — which runs before
|
|
81
|
+
* the 200 is written — destroys the socket mid-reply, so the phone sees
|
|
82
|
+
* `socket hang up` for a proof that was stored perfectly well.
|
|
83
|
+
*
|
|
84
|
+
* Registered before the write rather than after it, so a response that
|
|
85
|
+
* finishes synchronously cannot slip between the two.
|
|
86
|
+
*/
|
|
87
|
+
readonly onStored?: (verification: Verification, context: ProofContext) => void;
|
|
88
|
+
/** Route to accept proofs on. Must equal the endpoint pinned in the QR. */
|
|
89
|
+
readonly path?: string;
|
|
90
|
+
/** Liveness route, or null to serve none (a gateway has its own). */
|
|
91
|
+
readonly healthPath?: string | null;
|
|
92
|
+
readonly onProofRejected?: (reason: string) => void;
|
|
93
|
+
readonly onHandlerError?: (reason: string) => void;
|
|
94
|
+
/**
|
|
95
|
+
* Rewrite a refusal reason before it reaches the caller.
|
|
96
|
+
*
|
|
97
|
+
* The CLI wants the raw text — it is the operator's own machine and the
|
|
98
|
+
* detail is the point. A gateway does not: this endpoint is open to the
|
|
99
|
+
* internet, and `verifyProof` surfaces whatever the Self SDK threw, so an
|
|
100
|
+
* anonymous POST of `{}` comes back carrying an internal stack message.
|
|
101
|
+
* Defaults to passing the reason through unchanged.
|
|
102
|
+
*/
|
|
103
|
+
readonly reasonForClient?: (reason: string) => string;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* A `RequestListener` that verifies Self proofs and hands them to `persist`.
|
|
107
|
+
*
|
|
108
|
+
* Mountable as a whole server (the CLI does) or delegated to from one route of
|
|
109
|
+
* a larger server (a gateway does). Rejections answer 200 with
|
|
110
|
+
* `{status:'error'}` rather than a 4xx, because that is the shape the Self app
|
|
111
|
+
* expects back.
|
|
112
|
+
*/
|
|
113
|
+
export declare function createProofReceiver(options: ProofReceiverOptions): RequestListener;
|
package/dist/types.d.ts
CHANGED
|
@@ -36,7 +36,15 @@ export type VerificationRequest = {
|
|
|
36
36
|
userId: string;
|
|
37
37
|
/** Requested disclosures + thresholds. */
|
|
38
38
|
requirements: SoftKycRequirements;
|
|
39
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* Free-form context echoed back in the proof.
|
|
41
|
+
*
|
|
42
|
+
* NOT merely diagnostic, despite how it reads: it is a slice of
|
|
43
|
+
* `userContextData`, and the circuit commits to that value's sha256 as a
|
|
44
|
+
* public signal. Whatever the verifier puts here comes back provably
|
|
45
|
+
* unaltered, which is what lets a receiver serving many unknown callers bind
|
|
46
|
+
* a proof to the session that asked for it.
|
|
47
|
+
*/
|
|
40
48
|
userDefinedData?: string;
|
|
41
49
|
/**
|
|
42
50
|
* Self.xyz endpointType — picks staging/production AND on-chain/off-chain.
|
|
@@ -55,6 +63,22 @@ export type VerificationResult = {
|
|
|
55
63
|
userIdentifier?: string;
|
|
56
64
|
/** Per-user per-scope unique value from the proof. */
|
|
57
65
|
nullifier?: string;
|
|
66
|
+
/**
|
|
67
|
+
* The request's `userDefinedData`, decoded back to the string that was sent.
|
|
68
|
+
*
|
|
69
|
+
* Undefined when absent or not valid UTF-8 — never a lossy approximation, so
|
|
70
|
+
* two different proofs can never decode onto one value. Bound to the proof
|
|
71
|
+
* via the committed `userContextData` hash; see the note on
|
|
72
|
+
* `VerificationRequest.userDefinedData`.
|
|
73
|
+
*/
|
|
74
|
+
userDefinedData?: string;
|
|
75
|
+
/**
|
|
76
|
+
* The same value exactly as the verifier returned it: the hex tail of
|
|
77
|
+
* `userContextData`, undecoded. Compare THIS when the value identifies
|
|
78
|
+
* something — it is the bytes the circuit committed to, with no decode step
|
|
79
|
+
* to disagree about.
|
|
80
|
+
*/
|
|
81
|
+
userDefinedDataHex?: string;
|
|
58
82
|
};
|
|
59
83
|
export type VerificationFailure = {
|
|
60
84
|
ok: false;
|
package/dist/verify.d.ts
CHANGED
|
@@ -14,6 +14,18 @@ export type ProofPayload = {
|
|
|
14
14
|
* currently expose a custom hub address — the SDK defaults to mainnet /
|
|
15
15
|
* staging based on the network choice baked into the proof itself.
|
|
16
16
|
*/
|
|
17
|
+
/**
|
|
18
|
+
* Decode the hex `userDefinedData` tail back to the string that was sent.
|
|
19
|
+
*
|
|
20
|
+
* STRICT, and deliberately so. `Buffer.from(hex, 'hex').toString('utf8')`
|
|
21
|
+
* silently maps every invalid byte sequence to U+FFFD, so a caller comparing
|
|
22
|
+
* decoded values would see distinct proofs collapse onto one key — which, for
|
|
23
|
+
* anything using this to identify a session, is a collision an attacker picks.
|
|
24
|
+
* `TextDecoder` in fatal mode refuses instead, and `undefined` means "no usable
|
|
25
|
+
* value" rather than a lossy guess. Anything needing exactness compares
|
|
26
|
+
* `userDefinedDataHex`.
|
|
27
|
+
*/
|
|
28
|
+
export declare function decodeUserDefinedData(hex: string | undefined): string | undefined;
|
|
17
29
|
export declare function verifyProof(request: VerificationRequest, payload: ProofPayload): Promise<VerificationResult | VerificationFailure>;
|
|
18
30
|
/**
|
|
19
31
|
* Build a mock attestation result with no Self SDK calls. Used by `buy
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celo/buy-identity",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "buy identity — Self.xyz soft-KYC integration (off-chain proof verification + attestation cache)",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -10,18 +10,22 @@
|
|
|
10
10
|
".": "./dist/index.js"
|
|
11
11
|
},
|
|
12
12
|
"files": [
|
|
13
|
-
"dist",
|
|
14
|
-
"
|
|
13
|
+
"dist/*.d.ts",
|
|
14
|
+
"dist/index.js",
|
|
15
|
+
"dist/index.js.map",
|
|
16
|
+
"LICENSE",
|
|
17
|
+
"THIRD_PARTY_NOTICES.md"
|
|
15
18
|
],
|
|
16
19
|
"dependencies": {
|
|
17
|
-
"@selfxyz/core": "^1.1.0-beta.1",
|
|
18
|
-
"@selfxyz/qrcode": "^1.0.0",
|
|
19
20
|
"qrcode-terminal": "^0.12.0",
|
|
20
|
-
"@celo/buy-keystore": "0.
|
|
21
|
+
"@celo/buy-keystore": "0.4.0"
|
|
21
22
|
},
|
|
22
23
|
"devDependencies": {
|
|
24
|
+
"@selfxyz/core": "1.1.0-beta.7",
|
|
25
|
+
"@selfxyz/sdk-common": "^1.0.1",
|
|
23
26
|
"@types/node": "^22.10.0",
|
|
24
|
-
"@types/qrcode-terminal": "^0.12.2"
|
|
27
|
+
"@types/qrcode-terminal": "^0.12.2",
|
|
28
|
+
"esbuild": "0.28.1"
|
|
25
29
|
},
|
|
26
30
|
"repository": {
|
|
27
31
|
"type": "git",
|
|
@@ -37,7 +41,7 @@
|
|
|
37
41
|
"registry": "https://registry.npmjs.org"
|
|
38
42
|
},
|
|
39
43
|
"scripts": {
|
|
40
|
-
"build": "tsc -p tsconfig.json",
|
|
44
|
+
"build": "tsc -p tsconfig.json && esbuild src/index.ts --bundle --platform=node --format=esm --target=node20 --sourcemap --legal-comments=eof --banner:js=\"import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);\" --outfile=dist/index.js --external:qrcode-terminal --external:'@celo/*'",
|
|
41
45
|
"test": "vitest run"
|
|
42
46
|
}
|
|
43
47
|
}
|
package/dist/config.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/** Translates our compact requirements shape into the Self disclosures schema. */
|
|
2
|
-
function toDisclosures(req) {
|
|
3
|
-
const disclosures = {};
|
|
4
|
-
if (req.minimumAge !== undefined)
|
|
5
|
-
disclosures.minimumAge = req.minimumAge;
|
|
6
|
-
if (req.excludedCountries?.length)
|
|
7
|
-
disclosures.excludedCountries = req.excludedCountries;
|
|
8
|
-
if (req.notOfac !== undefined)
|
|
9
|
-
disclosures.ofac = req.notOfac;
|
|
10
|
-
if (req.discloseNationality)
|
|
11
|
-
disclosures.nationality = true;
|
|
12
|
-
if (req.discloseGender)
|
|
13
|
-
disclosures.gender = true;
|
|
14
|
-
return disclosures;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Build a Self verification request and return the universal link the mobile
|
|
18
|
-
* app understands. The link is what gets rendered as a QR code in the terminal.
|
|
19
|
-
*
|
|
20
|
-
* ASYNC, and importing `@selfxyz/qrcode` LAZILY, because that module prints
|
|
21
|
-
* `[WebSocket] Initializing websocket module.` to STDOUT the moment it is
|
|
22
|
-
* loaded. At the top of this file that banner landed on every single `buy`
|
|
23
|
-
* invocation — `main.ts` imports all commands eagerly, so merely having a
|
|
24
|
-
* `verify` command polluted `buy fetch`'s stdout, which is the response body.
|
|
25
|
-
* `buy fetch … | jq` was parsing that line as the first thing in the payload.
|
|
26
|
-
*
|
|
27
|
-
* Nothing in this package can stop a dependency writing to stdout, so the only
|
|
28
|
-
* fix is not to load it until it is genuinely needed — i.e. inside the one
|
|
29
|
-
* function that builds a QR link.
|
|
30
|
-
*/
|
|
31
|
-
export async function buildVerificationLink(request) {
|
|
32
|
-
const { SelfAppBuilder } = await import('@selfxyz/qrcode');
|
|
33
|
-
const { getUniversalLink } = await import('@selfxyz/core');
|
|
34
|
-
const app = new SelfAppBuilder({
|
|
35
|
-
version: 2,
|
|
36
|
-
appName: request.appName,
|
|
37
|
-
scope: request.scope,
|
|
38
|
-
endpoint: request.endpoint,
|
|
39
|
-
endpointType: request.endpointType,
|
|
40
|
-
userId: request.userId,
|
|
41
|
-
userIdType: 'hex',
|
|
42
|
-
userDefinedData: request.userDefinedData ?? '',
|
|
43
|
-
disclosures: toDisclosures(request.requirements),
|
|
44
|
-
}).build();
|
|
45
|
-
return getUniversalLink(app);
|
|
46
|
-
}
|
|
47
|
-
/** Exposed for tests — pure function, no Self SDK calls. */
|
|
48
|
-
export function _disclosuresFor(req) {
|
|
49
|
-
return toDisclosures(req);
|
|
50
|
-
}
|
|
51
|
-
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAEA,kFAAkF;AAClF,SAAS,aAAa,CAAC,GAAwB;IAC7C,MAAM,WAAW,GAA4B,EAAE,CAAC;IAChD,IAAI,GAAG,CAAC,UAAU,KAAK,SAAS;QAAE,WAAW,CAAC,UAAU,GAAG,GAAG,CAAC,UAAU,CAAC;IAC1E,IAAI,GAAG,CAAC,iBAAiB,EAAE,MAAM;QAAE,WAAW,CAAC,iBAAiB,GAAG,GAAG,CAAC,iBAAiB,CAAC;IACzF,IAAI,GAAG,CAAC,OAAO,KAAK,SAAS;QAAE,WAAW,CAAC,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC;IAC9D,IAAI,GAAG,CAAC,mBAAmB;QAAE,WAAW,CAAC,WAAW,GAAG,IAAI,CAAC;IAC5D,IAAI,GAAG,CAAC,cAAc;QAAE,WAAW,CAAC,MAAM,GAAG,IAAI,CAAC;IAClD,OAAO,WAAW,CAAC;AACrB,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,OAA4B;IACtE,MAAM,EAAE,cAAc,EAAE,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC,CAAC;IAC3D,MAAM,EAAE,gBAAgB,EAAE,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC,CAAC;IAC3D,MAAM,GAAG,GAAG,IAAI,cAAc,CAAC;QAC7B,OAAO,EAAE,CAAC;QACV,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,YAAY,EAAE,OAAO,CAAC,YAAY;QAClC,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,UAAU,EAAE,KAAK;QACjB,eAAe,EAAE,OAAO,CAAC,eAAe,IAAI,EAAE;QAC9C,WAAW,EAAE,aAAa,CAAC,OAAO,CAAC,YAAY,CAAC;KACjD,CAAC,CAAC,KAAK,EAAE,CAAC;IACX,OAAO,gBAAgB,CAAC,GAAG,CAAC,CAAC;AAC/B,CAAC;AAED,4DAA4D;AAC5D,MAAM,UAAU,eAAe,CAAC,GAAwB;IACtD,OAAO,aAAa,CAAC,GAAG,CAAC,CAAC;AAC5B,CAAC"}
|
package/dist/qr.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import qrcode from 'qrcode-terminal';
|
|
2
|
-
/**
|
|
3
|
-
* Render the Self universal link as an ASCII QR code suitable for a 80-col
|
|
4
|
-
* terminal. `small` halves the size at the cost of legibility on noisy
|
|
5
|
-
* displays.
|
|
6
|
-
*/
|
|
7
|
-
export function renderQrToTerminal(link, opts = {}) {
|
|
8
|
-
return new Promise((resolve) => {
|
|
9
|
-
qrcode.generate(link, { small: opts.small ?? true }, (out) => resolve(out));
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=qr.js.map
|
package/dist/qr.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"qr.js","sourceRoot":"","sources":["../src/qr.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAMrC;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAY,EAAE,OAAwB,EAAE;IACzE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,IAAI,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;IAC9E,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/types.js
DELETED
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/dist/verify.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto';
|
|
2
|
-
import { AllIds, DefaultConfigStore, SelfBackendVerifier } from '@selfxyz/core';
|
|
3
|
-
function hashProof(proof) {
|
|
4
|
-
const hex = createHash('sha256').update(JSON.stringify(proof)).digest('hex');
|
|
5
|
-
return `0x${hex}`;
|
|
6
|
-
}
|
|
7
|
-
function cleanDisclosedString(value) {
|
|
8
|
-
if (typeof value !== 'string')
|
|
9
|
-
return undefined;
|
|
10
|
-
// biome-ignore lint/suspicious/noControlCharactersInRegex: intentionally strips null-byte padding that Self.xyz SDK returns for undisclosed fields
|
|
11
|
-
const trimmed = value.replace(/\u0000+/g, '').trim();
|
|
12
|
-
return trimmed.length > 0 ? trimmed : undefined;
|
|
13
|
-
}
|
|
14
|
-
function attributesFromDisclosures(req, disclosed) {
|
|
15
|
-
const attrs = {};
|
|
16
|
-
if (req.minimumAge !== undefined)
|
|
17
|
-
attrs.minimumAge = req.minimumAge;
|
|
18
|
-
if (req.notOfac)
|
|
19
|
-
attrs.notOfac = true;
|
|
20
|
-
if (req.excludedCountries?.length)
|
|
21
|
-
attrs.excludedCountries = req.excludedCountries;
|
|
22
|
-
if (req.discloseNationality) {
|
|
23
|
-
const nationality = cleanDisclosedString(disclosed.nationality);
|
|
24
|
-
if (nationality !== undefined)
|
|
25
|
-
attrs.nationality = nationality;
|
|
26
|
-
}
|
|
27
|
-
if (req.discloseGender) {
|
|
28
|
-
const gender = cleanDisclosedString(disclosed.gender);
|
|
29
|
-
if (gender !== undefined)
|
|
30
|
-
attrs.gender = gender;
|
|
31
|
-
}
|
|
32
|
-
return attrs;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Verify a Self proof against the requested requirements. Wraps Self's
|
|
36
|
-
* `SelfBackendVerifier` and translates its result into a compact attestation
|
|
37
|
-
* we can persist to accounts.json.
|
|
38
|
-
*
|
|
39
|
-
* NOTE: SelfBackendVerifier hits an on-chain hub for some checks. We don't
|
|
40
|
-
* currently expose a custom hub address — the SDK defaults to mainnet /
|
|
41
|
-
* staging based on the network choice baked into the proof itself.
|
|
42
|
-
*/
|
|
43
|
-
export async function verifyProof(request, payload) {
|
|
44
|
-
// SDK enforces a narrow Country3LetterCode union — we accept any string at
|
|
45
|
-
// our surface (so callers can pass ISO-3 codes directly) and cast here.
|
|
46
|
-
const configStore = new DefaultConfigStore({
|
|
47
|
-
minimumAge: request.requirements.minimumAge,
|
|
48
|
-
excludedCountries: request.requirements.excludedCountries,
|
|
49
|
-
ofac: request.requirements.notOfac ?? false,
|
|
50
|
-
});
|
|
51
|
-
const verifier = new SelfBackendVerifier(request.scope, request.endpoint, request.mockPassport, AllIds, configStore, 'hex');
|
|
52
|
-
try {
|
|
53
|
-
const result = (await verifier.verify(
|
|
54
|
-
// SDK types attestationId as a literal union (1 | 2 | 3). Self mobile
|
|
55
|
-
// sends a number — we trust whatever the proof carried.
|
|
56
|
-
payload.attestationId, payload.proof, payload.publicSignals, payload.userContextData));
|
|
57
|
-
const ok = result.isValidDetails?.isValid === true;
|
|
58
|
-
if (!ok) {
|
|
59
|
-
return { ok: false, reason: 'Self verifier returned isValid=false' };
|
|
60
|
-
}
|
|
61
|
-
const disclosed = result.discloseOutput ?? {};
|
|
62
|
-
const nullifier = result.nullifier ??
|
|
63
|
-
(typeof disclosed.nullifier === 'string' ? disclosed.nullifier : undefined);
|
|
64
|
-
return {
|
|
65
|
-
ok: true,
|
|
66
|
-
attributes: attributesFromDisclosures(request.requirements, disclosed),
|
|
67
|
-
proofHash: hashProof(payload),
|
|
68
|
-
userIdentifier: result.userData?.userIdentifier,
|
|
69
|
-
nullifier,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
catch (err) {
|
|
73
|
-
return { ok: false, reason: err instanceof Error ? err.message : String(err) };
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Build a mock attestation result with no Self SDK calls. Used by `buy
|
|
78
|
-
* verify mock` for demos and CI smoke tests where running the mobile-app
|
|
79
|
-
* flow isn't practical.
|
|
80
|
-
*/
|
|
81
|
-
export function buildMockResult(request) {
|
|
82
|
-
return {
|
|
83
|
-
ok: true,
|
|
84
|
-
attributes: attributesFromDisclosures(request.requirements, {}),
|
|
85
|
-
proofHash: `0xmock${Buffer.from(request.scope).toString('hex')}`,
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
//# sourceMappingURL=verify.js.map
|
package/dist/verify.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"verify.js","sourceRoot":"","sources":["../src/verify.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAehF,SAAS,SAAS,CAAC,KAA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