@celo/buy-identity 0.3.0 → 0.3.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/THIRD_PARTY_NOTICES.md +118 -0
- package/dist/config.d.ts +2 -10
- package/dist/index.js +48758 -5
- package/dist/index.js.map +7 -1
- 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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celo/buy-identity",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.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",
|
|
@@ -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.3.
|
|
21
|
+
"@celo/buy-keystore": "0.3.1"
|
|
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;QAA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
-
/**
|
|
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.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