@celo/buy-identity 0.3.1 → 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/dist/hosted.d.ts +90 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +347 -22
- package/dist/index.js.map +4 -4
- package/dist/receiver.d.ts +113 -0
- package/dist/types.d.ts +25 -1
- package/dist/verify.d.ts +12 -0
- package/package.json +2 -2
|
@@ -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",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"qrcode-terminal": "^0.12.0",
|
|
21
|
-
"@celo/buy-keystore": "0.
|
|
21
|
+
"@celo/buy-keystore": "0.4.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@selfxyz/core": "1.1.0-beta.7",
|