@celo/buy-identity 0.3.1 → 0.4.1
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 +3 -1
- package/dist/index.js +379 -23
- package/dist/index.js.map +4 -4
- package/dist/qr.d.ts +12 -0
- package/dist/receiver.d.ts +105 -0
- package/dist/types.d.ts +44 -2
- package/dist/verify.d.ts +33 -0
- package/package.json +2 -2
package/dist/qr.d.ts
CHANGED
|
@@ -7,3 +7,15 @@ export type QrRenderOptions = {
|
|
|
7
7
|
* displays.
|
|
8
8
|
*/
|
|
9
9
|
export declare function renderQrToTerminal(link: string, opts?: QrRenderOptions): Promise<string>;
|
|
10
|
+
/**
|
|
11
|
+
* A note to print beside a QR that will not fit the terminal.
|
|
12
|
+
*
|
|
13
|
+
* A Self verification QR is ~47 rows even at `small: true` — the link it
|
|
14
|
+
* encodes is ~660 characters — so a default 24-row terminal scrolls the top
|
|
15
|
+
* half away and leaves something that cannot be scanned. Nothing about the
|
|
16
|
+
* output says so: it simply does not work, and the reader has no idea why.
|
|
17
|
+
*
|
|
18
|
+
* Returns undefined when it fits, or when the height is unknown (not a TTY, so
|
|
19
|
+
* nobody is looking at it anyway).
|
|
20
|
+
*/
|
|
21
|
+
export declare function qrFitWarning(qr: string, rows?: number | undefined): string | undefined;
|
|
@@ -0,0 +1,105 @@
|
|
|
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
|
+
export declare function createProofReceiver(options: ProofReceiverOptions): RequestListener;
|
package/dist/types.d.ts
CHANGED
|
@@ -31,12 +31,28 @@ export type VerificationRequest = {
|
|
|
31
31
|
/** Public callback URL that Self mobile app POSTs the proof to. */
|
|
32
32
|
endpoint: string;
|
|
33
33
|
/** Whether to accept the mock-passport flow (staging only). */
|
|
34
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Which Self hub to verify against: false = mainnet (real passports),
|
|
36
|
+
* true = staging (mock passports), `'either'` = try both.
|
|
37
|
+
*
|
|
38
|
+
* `'either'` exists so one deployment can serve hackathon participants using
|
|
39
|
+
* mock passports alongside real users, which a single verifier cannot do —
|
|
40
|
+
* see `verifyProof`.
|
|
41
|
+
*/
|
|
42
|
+
mockPassport: boolean | 'either';
|
|
35
43
|
/** EVM address (hex) the proof is bound to. */
|
|
36
44
|
userId: string;
|
|
37
45
|
/** Requested disclosures + thresholds. */
|
|
38
46
|
requirements: SoftKycRequirements;
|
|
39
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* Free-form context echoed back in the proof.
|
|
49
|
+
*
|
|
50
|
+
* NOT merely diagnostic, despite how it reads: it is a slice of
|
|
51
|
+
* `userContextData`, and the circuit commits to that value's sha256 as a
|
|
52
|
+
* public signal. Whatever the verifier puts here comes back provably
|
|
53
|
+
* unaltered, which is what lets a receiver serving many unknown callers bind
|
|
54
|
+
* a proof to the session that asked for it.
|
|
55
|
+
*/
|
|
40
56
|
userDefinedData?: string;
|
|
41
57
|
/**
|
|
42
58
|
* Self.xyz endpointType — picks staging/production AND on-chain/off-chain.
|
|
@@ -55,6 +71,32 @@ export type VerificationResult = {
|
|
|
55
71
|
userIdentifier?: string;
|
|
56
72
|
/** Per-user per-scope unique value from the proof. */
|
|
57
73
|
nullifier?: string;
|
|
74
|
+
/**
|
|
75
|
+
* The request's `userDefinedData`, decoded back to the string that was sent.
|
|
76
|
+
*
|
|
77
|
+
* Undefined when absent or not valid UTF-8 — never a lossy approximation, so
|
|
78
|
+
* two different proofs can never decode onto one value. Bound to the proof
|
|
79
|
+
* via the committed `userContextData` hash; see the note on
|
|
80
|
+
* `VerificationRequest.userDefinedData`.
|
|
81
|
+
*/
|
|
82
|
+
userDefinedData?: string;
|
|
83
|
+
/**
|
|
84
|
+
* The same value exactly as the verifier returned it: the hex tail of
|
|
85
|
+
* `userContextData`, undecoded. Compare THIS when the value identifies
|
|
86
|
+
* something — it is the bytes the circuit committed to, with no decode step
|
|
87
|
+
* to disagree about.
|
|
88
|
+
*/
|
|
89
|
+
userDefinedDataHex?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Which Self hub validated this proof: true = staging (mock passports),
|
|
92
|
+
* false = mainnet (real ones).
|
|
93
|
+
*
|
|
94
|
+
* Only interesting when the request said `'either'`, but always set, because
|
|
95
|
+
* the attestation must record the matching `endpointType` — re-verification
|
|
96
|
+
* picks its hub from that, and a mismatch fails with `InvalidRoot` on a proof
|
|
97
|
+
* that is perfectly valid.
|
|
98
|
+
*/
|
|
99
|
+
usedMockPassport?: boolean;
|
|
58
100
|
};
|
|
59
101
|
export type VerificationFailure = {
|
|
60
102
|
ok: false;
|
package/dist/verify.d.ts
CHANGED
|
@@ -14,6 +14,39 @@ 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;
|
|
29
|
+
/**
|
|
30
|
+
* Verify against BOTH Self hubs when the caller will accept either.
|
|
31
|
+
*
|
|
32
|
+
* A `SelfBackendVerifier` is bound to one hub: `mockPassport` picks the RPC and
|
|
33
|
+
* the IdentityVerificationHub address, staging or mainnet. A mock passport
|
|
34
|
+
* registers its identity root on staging and a real one on mainnet, so a single
|
|
35
|
+
* verifier can only ever validate one of them — the other fails with
|
|
36
|
+
* `InvalidRoot: Onchain root does not exist`, an error about WHERE the root was
|
|
37
|
+
* looked for, not about the proof being bad.
|
|
38
|
+
*
|
|
39
|
+
* Trying both is what lets one deployment serve hackathon participants with
|
|
40
|
+
* mock passports and real users at the same time. It costs an extra hub read
|
|
41
|
+
* only on the miss, and it is safe because the two cannot be confused: the
|
|
42
|
+
* scope commitment is `hashEndpointWithScope(endpoint, scope)` — endpointType
|
|
43
|
+
* is NOT in it — so a proof that validates against a hub validates for this
|
|
44
|
+
* exact endpoint and scope regardless of which hub held its root.
|
|
45
|
+
*
|
|
46
|
+
* The hub that succeeded comes back as `usedMockPassport`, because the
|
|
47
|
+
* attestation has to record the matching `endpointType` or re-verification
|
|
48
|
+
* later would look in the wrong place.
|
|
49
|
+
*/
|
|
17
50
|
export declare function verifyProof(request: VerificationRequest, payload: ProofPayload): Promise<VerificationResult | VerificationFailure>;
|
|
18
51
|
/**
|
|
19
52
|
* 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.1",
|
|
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.1"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@selfxyz/core": "1.1.0-beta.7",
|