@celo/buy-identity 0.3.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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,19 @@
1
+ import type { SoftKycRequirements, VerificationRequest } from './types.js';
2
+ /**
3
+ * Build a Self verification request and return the universal link the mobile
4
+ * app understands. The link is what gets rendered as a QR code in the terminal.
5
+ *
6
+ * ASYNC, and importing `@selfxyz/qrcode` LAZILY, because that module prints
7
+ * `[WebSocket] Initializing websocket module.` to STDOUT the moment it is
8
+ * loaded. At the top of this file that banner landed on every single `buy`
9
+ * invocation — `main.ts` imports all commands eagerly, so merely having a
10
+ * `verify` command polluted `buy fetch`'s stdout, which is the response body.
11
+ * `buy fetch … | jq` was parsing that line as the first thing in the payload.
12
+ *
13
+ * Nothing in this package can stop a dependency writing to stdout, so the only
14
+ * fix is not to load it until it is genuinely needed — i.e. inside the one
15
+ * function that builds a QR link.
16
+ */
17
+ export declare function buildVerificationLink(request: VerificationRequest): Promise<string>;
18
+ /** Exposed for tests — pure function, no Self SDK calls. */
19
+ export declare function _disclosuresFor(req: SoftKycRequirements): Record<string, unknown>;
package/dist/config.js ADDED
@@ -0,0 +1,51 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,4 @@
1
+ export * from './types.js';
2
+ export * from './config.js';
3
+ export * from './verify.js';
4
+ export { renderQrToTerminal } from './qr.js';
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export * from './types.js';
2
+ export * from './config.js';
3
+ export * from './verify.js';
4
+ export { renderQrToTerminal } from './qr.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC"}
package/dist/qr.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ export type QrRenderOptions = {
2
+ small?: boolean;
3
+ };
4
+ /**
5
+ * Render the Self universal link as an ASCII QR code suitable for a 80-col
6
+ * terminal. `small` halves the size at the cost of legibility on noisy
7
+ * displays.
8
+ */
9
+ export declare function renderQrToTerminal(link: string, opts?: QrRenderOptions): Promise<string>;
package/dist/qr.js ADDED
@@ -0,0 +1,12 @@
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 ADDED
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,63 @@
1
+ import type { VerificationAttributes } from '@celo/buy-keystore';
2
+ /**
3
+ * Self.xyz `endpointType` from the SelfAppBuilder config.
4
+ *
5
+ * - `https` / `staging_https` → off-chain backend verifier; `endpoint` is the HTTPS URL
6
+ * - `celo` / `staging_celo` → on-chain hub verifier; `endpoint` is the contract address
7
+ *
8
+ * Mismatching these causes the Self mobile app to reject with "Invalid 'to' address".
9
+ */
10
+ export type SelfEndpointType = 'https' | 'staging_https' | 'celo' | 'staging_celo';
11
+ /** @deprecated Renamed to `SelfEndpointType`. Kept temporarily for back-compat. */
12
+ export type SelfNetwork = SelfEndpointType;
13
+ /**
14
+ * High-level KYC requirements requested from the user. Maps 1:1 onto Self.xyz
15
+ * `disclosures` + the SelfBackendVerifier config. Kept tiny on purpose — we
16
+ * surface only the attributes the bug-bounty / x402 challenge space needs.
17
+ */
18
+ export type SoftKycRequirements = {
19
+ minimumAge?: number;
20
+ excludedCountries?: string[];
21
+ /** Require non-OFAC. */
22
+ notOfac?: boolean;
23
+ /** Request the prover disclose their nationality (ISO-3 code). */
24
+ discloseNationality?: boolean;
25
+ /** Request the prover disclose their gender. */
26
+ discloseGender?: boolean;
27
+ };
28
+ export type VerificationRequest = {
29
+ /** Stable scope ID — usually a fixed string per app, e.g. "buy" or "buy-demo". */
30
+ scope: string;
31
+ /** Public callback URL that Self mobile app POSTs the proof to. */
32
+ endpoint: string;
33
+ /** Whether to accept the mock-passport flow (staging only). */
34
+ mockPassport: boolean;
35
+ /** EVM address (hex) the proof is bound to. */
36
+ userId: string;
37
+ /** Requested disclosures + thresholds. */
38
+ requirements: SoftKycRequirements;
39
+ /** Free-form context echoed back in the proof (logged for debugging only). */
40
+ userDefinedData?: string;
41
+ /**
42
+ * Self.xyz endpointType — picks staging/production AND on-chain/off-chain.
43
+ * For buy's HTTPS proof receiver this is `staging_https` or `https`.
44
+ */
45
+ endpointType: SelfEndpointType;
46
+ /** Human-readable app name shown in the Self mobile app. */
47
+ appName: string;
48
+ };
49
+ /** Result returned from a successful proof verification. */
50
+ export type VerificationResult = {
51
+ ok: true;
52
+ attributes: VerificationAttributes;
53
+ proofHash: string;
54
+ /** Address the proof was bound to (Self's `userData.userIdentifier`). */
55
+ userIdentifier?: string;
56
+ /** Per-user per-scope unique value from the proof. */
57
+ nullifier?: string;
58
+ };
59
+ export type VerificationFailure = {
60
+ ok: false;
61
+ reason: string;
62
+ };
63
+ export type { VerificationAttributes } from '@celo/buy-keystore';
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,23 @@
1
+ import type { VerificationFailure, VerificationRequest, VerificationResult } from './types.js';
2
+ export type ProofPayload = {
3
+ attestationId: number;
4
+ proof: unknown;
5
+ publicSignals: unknown;
6
+ userContextData: unknown;
7
+ };
8
+ /**
9
+ * Verify a Self proof against the requested requirements. Wraps Self's
10
+ * `SelfBackendVerifier` and translates its result into a compact attestation
11
+ * we can persist to accounts.json.
12
+ *
13
+ * NOTE: SelfBackendVerifier hits an on-chain hub for some checks. We don't
14
+ * currently expose a custom hub address — the SDK defaults to mainnet /
15
+ * staging based on the network choice baked into the proof itself.
16
+ */
17
+ export declare function verifyProof(request: VerificationRequest, payload: ProofPayload): Promise<VerificationResult | VerificationFailure>;
18
+ /**
19
+ * Build a mock attestation result with no Self SDK calls. Used by `buy
20
+ * verify mock` for demos and CI smoke tests where running the mobile-app
21
+ * flow isn't practical.
22
+ */
23
+ export declare function buildMockResult(request: VerificationRequest): VerificationResult;
package/dist/verify.js ADDED
@@ -0,0 +1,88 @@
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
@@ -0,0 +1 @@
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,KAAmB;IACpC,MAAM,GAAG,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC7E,OAAO,KAAK,GAAG,EAAE,CAAC;AACpB,CAAC;AAED,SAAS,oBAAoB,CAAC,KAAc;IAC1C,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IA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,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;IACjF,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,OAA4B;IAC1D,OAAO;QACL,EAAE,EAAE,IAAI;QACR,UAAU,EAAE,yBAAyB,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC;QAC/D,SAAS,EAAE,SAAS,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;KACjE,CAAC;AACJ,CAAC"}
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@celo/buy-identity",
3
+ "version": "0.3.0",
4
+ "description": "buy identity — Self.xyz soft-KYC integration (off-chain proof verification + attestation cache)",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": "./dist/index.js"
11
+ },
12
+ "files": [
13
+ "dist",
14
+ "LICENSE"
15
+ ],
16
+ "dependencies": {
17
+ "@selfxyz/core": "^1.1.0-beta.1",
18
+ "@selfxyz/qrcode": "^1.0.0",
19
+ "qrcode-terminal": "^0.12.0",
20
+ "@celo/buy-keystore": "0.3.0"
21
+ },
22
+ "devDependencies": {
23
+ "@types/node": "^22.10.0",
24
+ "@types/qrcode-terminal": "^0.12.2"
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/celo-org/cpay.git",
29
+ "directory": "packages/identity"
30
+ },
31
+ "homepage": "https://github.com/celo-org/cpay/tree/main/packages/identity#readme",
32
+ "bugs": {
33
+ "url": "https://github.com/celo-org/cpay/issues"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public",
37
+ "registry": "https://registry.npmjs.org"
38
+ },
39
+ "scripts": {
40
+ "build": "tsc -p tsconfig.json",
41
+ "test": "vitest run"
42
+ }
43
+ }