@textrp/briij-js-sdk 43.1.1 → 44.0.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/CHANGELOG.md +11 -1
- package/README.md +18 -0
- package/lib/@types/auth.d.ts +38 -0
- package/lib/@types/auth.d.ts.map +1 -1
- package/lib/@types/auth.js.map +1 -1
- package/lib/@types/snarkjs.d.js +0 -0
- package/lib/@types/snarkjs.d.js.map +1 -0
- package/lib/auth/credential.d.ts +25 -0
- package/lib/auth/credential.d.ts.map +1 -0
- package/lib/auth/credential.js +48 -0
- package/lib/auth/credential.js.map +1 -0
- package/lib/auth/did.d.ts +22 -0
- package/lib/auth/did.d.ts.map +1 -0
- package/lib/auth/did.js +66 -0
- package/lib/auth/did.js.map +1 -0
- package/lib/auth/wallet.d.ts +22 -0
- package/lib/auth/wallet.d.ts.map +1 -0
- package/lib/auth/wallet.js +27 -0
- package/lib/auth/wallet.js.map +1 -0
- package/lib/auth/zkpE2EE.d.ts +22 -0
- package/lib/auth/zkpE2EE.d.ts.map +1 -0
- package/lib/auth/zkpE2EE.js +69 -0
- package/lib/auth/zkpE2EE.js.map +1 -0
- package/lib/briij.d.ts +4 -0
- package/lib/briij.d.ts.map +1 -1
- package/lib/briij.js +4 -0
- package/lib/briij.js.map +1 -1
- package/lib/client.d.ts +40 -1
- package/lib/client.d.ts.map +1 -1
- package/lib/client.js +259 -113
- package/lib/client.js.map +1 -1
- package/lib/credits.d.ts +24 -0
- package/lib/credits.d.ts.map +1 -0
- package/lib/credits.js +53 -0
- package/lib/credits.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/package.json +3 -1
- package/src/@types/auth.ts +44 -0
- package/src/@types/snarkjs.d.ts +17 -0
- package/src/auth/credential.ts +63 -0
- package/src/auth/did.ts +89 -0
- package/src/auth/wallet.ts +50 -0
- package/src/auth/zkpE2EE.ts +88 -0
- package/src/briij.ts +12 -0
- package/src/client.ts +187 -0
- package/src/components/LoginStepper.tsx +50 -0
- package/src/credits.ts +60 -0
- package/src/index.ts +2 -0
package/lib/credits.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { BriijClient } from "./client.ts";
|
|
2
|
+
export interface McreditPackage {
|
|
3
|
+
id: number;
|
|
4
|
+
name: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
credits_amount: number;
|
|
7
|
+
price_usd_cents: number;
|
|
8
|
+
sort_order?: number;
|
|
9
|
+
is_active?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare class CreditsClient {
|
|
12
|
+
private matrixClient;
|
|
13
|
+
constructor(matrixClient: BriijClient);
|
|
14
|
+
/**
|
|
15
|
+
* Public endpoint: Get packages available for purchase
|
|
16
|
+
*/
|
|
17
|
+
getPackages(): Promise<McreditPackage[]>;
|
|
18
|
+
/**
|
|
19
|
+
* Admin only: Get all packages (including inactive) for admin UI
|
|
20
|
+
* Uses the current Matrix access token for authentication
|
|
21
|
+
*/
|
|
22
|
+
getAdminPackages(): Promise<McreditPackage[]>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=credits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credits.d.ts","sourceRoot":"","sources":["../src/credits.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,qBAAa,aAAa;IACZ,OAAO,CAAC,YAAY;gBAAZ,YAAY,EAAE,WAAW;IAE7C;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IAgB9C;;;OAGG;IACG,gBAAgB,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;CAqBpD"}
|
package/lib/credits.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
export class CreditsClient {
|
|
3
|
+
constructor(matrixClient) {
|
|
4
|
+
this.matrixClient = matrixClient;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Public endpoint: Get packages available for purchase
|
|
9
|
+
*/
|
|
10
|
+
getPackages() {
|
|
11
|
+
var _this = this;
|
|
12
|
+
return _asyncToGenerator(function* () {
|
|
13
|
+
var baseUrl = _this.matrixClient.getHomeserverUrl();
|
|
14
|
+
var response = yield fetch("".concat(baseUrl, "/_briij/credits"), {
|
|
15
|
+
method: "GET",
|
|
16
|
+
headers: {
|
|
17
|
+
"Content-Type": "application/json"
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
if (!response.ok) {
|
|
21
|
+
throw new Error("Failed to fetch mCredits packages: ".concat(response.status));
|
|
22
|
+
}
|
|
23
|
+
return response.json();
|
|
24
|
+
})();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Admin only: Get all packages (including inactive) for admin UI
|
|
29
|
+
* Uses the current Matrix access token for authentication
|
|
30
|
+
*/
|
|
31
|
+
getAdminPackages() {
|
|
32
|
+
var _this2 = this;
|
|
33
|
+
return _asyncToGenerator(function* () {
|
|
34
|
+
var baseUrl = _this2.matrixClient.getHomeserverUrl();
|
|
35
|
+
var accessToken = _this2.matrixClient.getAccessToken();
|
|
36
|
+
var response = yield fetch("".concat(baseUrl, "/_briij/admin/credits/packages"), {
|
|
37
|
+
method: "GET",
|
|
38
|
+
headers: {
|
|
39
|
+
"Content-Type": "application/json",
|
|
40
|
+
Authorization: "Bearer ".concat(accessToken)
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
if (response.status === 403) {
|
|
45
|
+
throw new Error("Admin access required");
|
|
46
|
+
}
|
|
47
|
+
throw new Error("Failed to fetch admin packages: ".concat(response.status));
|
|
48
|
+
}
|
|
49
|
+
return response.json();
|
|
50
|
+
})();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=credits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credits.js","names":["CreditsClient","constructor","matrixClient","getPackages","_this","_asyncToGenerator","baseUrl","getHomeserverUrl","response","fetch","concat","method","headers","ok","Error","status","json","getAdminPackages","_this2","accessToken","getAccessToken","Authorization"],"sources":["../src/credits.ts"],"sourcesContent":["import type { BriijClient } from \"./client.ts\";\n\nexport interface McreditPackage {\n id: number;\n name: string;\n description?: string;\n credits_amount: number;\n price_usd_cents: number;\n sort_order?: number;\n is_active?: boolean;\n}\n\nexport class CreditsClient {\n constructor(private matrixClient: BriijClient) {}\n\n /**\n * Public endpoint: Get packages available for purchase\n */\n async getPackages(): Promise<McreditPackage[]> {\n const baseUrl = this.matrixClient.getHomeserverUrl();\n const response = await fetch(`${baseUrl}/_briij/credits`, {\n method: \"GET\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n });\n\n if (!response.ok) {\n throw new Error(`Failed to fetch mCredits packages: ${response.status}`);\n }\n\n return response.json();\n }\n\n /**\n * Admin only: Get all packages (including inactive) for admin UI\n * Uses the current Matrix access token for authentication\n */\n async getAdminPackages(): Promise<McreditPackage[]> {\n const baseUrl = this.matrixClient.getHomeserverUrl();\n const accessToken = this.matrixClient.getAccessToken();\n\n const response = await fetch(`${baseUrl}/_briij/admin/credits/packages`, {\n method: \"GET\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${accessToken}`,\n },\n });\n\n if (!response.ok) {\n if (response.status === 403) {\n throw new Error(\"Admin access required\");\n }\n throw new Error(`Failed to fetch admin packages: ${response.status}`);\n }\n\n return response.json();\n }\n}\n"],"mappings":";AAYA,OAAO,MAAMA,aAAa,CAAC;EACzBC,WAAWA,CAASC,YAAyB,EAAE;IAAA,KAA3BA,YAAyB,GAAzBA,YAAyB;EAAG;;EAEhD;AACF;AACA;EACQC,WAAWA,CAAA,EAA8B;IAAA,IAAAC,KAAA;IAAA,OAAAC,iBAAA;MAC7C,IAAMC,OAAO,GAAGF,KAAI,CAACF,YAAY,CAACK,gBAAgB,CAAC,CAAC;MACpD,IAAMC,QAAQ,SAASC,KAAK,IAAAC,MAAA,CAAIJ,OAAO,sBAAmB;QACxDK,MAAM,EAAE,KAAK;QACbC,OAAO,EAAE;UACP,cAAc,EAAE;QAClB;MACF,CAAC,CAAC;MAEF,IAAI,CAACJ,QAAQ,CAACK,EAAE,EAAE;QAChB,MAAM,IAAIC,KAAK,uCAAAJ,MAAA,CAAuCF,QAAQ,CAACO,MAAM,CAAE,CAAC;MAC1E;MAEA,OAAOP,QAAQ,CAACQ,IAAI,CAAC,CAAC;IAAC;EACzB;;EAEA;AACF;AACA;AACA;EACQC,gBAAgBA,CAAA,EAA8B;IAAA,IAAAC,MAAA;IAAA,OAAAb,iBAAA;MAClD,IAAMC,OAAO,GAAGY,MAAI,CAAChB,YAAY,CAACK,gBAAgB,CAAC,CAAC;MACpD,IAAMY,WAAW,GAAGD,MAAI,CAAChB,YAAY,CAACkB,cAAc,CAAC,CAAC;MAEtD,IAAMZ,QAAQ,SAASC,KAAK,IAAAC,MAAA,CAAIJ,OAAO,qCAAkC;QACvEK,MAAM,EAAE,KAAK;QACbC,OAAO,EAAE;UACP,cAAc,EAAE,kBAAkB;UAClCS,aAAa,YAAAX,MAAA,CAAYS,WAAW;QACtC;MACF,CAAC,CAAC;MAEF,IAAI,CAACX,QAAQ,CAACK,EAAE,EAAE;QAChB,IAAIL,QAAQ,CAACO,MAAM,KAAK,GAAG,EAAE;UAC3B,MAAM,IAAID,KAAK,CAAC,uBAAuB,CAAC;QAC1C;QACA,MAAM,IAAIA,KAAK,oCAAAJ,MAAA,CAAoCF,QAAQ,CAACO,MAAM,CAAE,CAAC;MACvE;MAEA,OAAOP,QAAQ,CAACQ,IAAI,CAAC,CAAC;IAAC;EACzB;AACF","ignoreList":[]}
|
package/lib/index.d.ts
CHANGED
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AAOpC,cAAc,YAAY,CAAC;AAC3B,eAAe,KAAK,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AAOpC,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,eAAe,KAAK,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -20,5 +20,7 @@ if (globalThis.__briij_js_sdk_entrypoint) {
|
|
|
20
20
|
}
|
|
21
21
|
globalThis.__briij_js_sdk_entrypoint = true;
|
|
22
22
|
export * from "./briij.js";
|
|
23
|
+
export * from "./credits";
|
|
24
|
+
export { CreditsClient } from "./credits";
|
|
23
25
|
export default briij;
|
|
24
26
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["briij","globalThis","__briij_js_sdk_entrypoint","Error"],"sources":["../src/index.ts"],"sourcesContent":["/*\nCopyright 2019 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport * as briij from \"./briij.ts\";\n\nif (globalThis.__briij_js_sdk_entrypoint) {\n throw new Error(\"Multiple briij-js-sdk entrypoints detected!\");\n}\nglobalThis.__briij_js_sdk_entrypoint = true;\n\nexport * from \"./briij.ts\";\nexport default briij;\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,KAAKA,KAAK,MAAM,YAAY;AAEnC,IAAIC,UAAU,CAACC,yBAAyB,EAAE;EACtC,MAAM,IAAIC,KAAK,CAAC,6CAA6C,CAAC;AAClE;AACAF,UAAU,CAACC,yBAAyB,GAAG,IAAI;AAE3C,cAAc,YAAY;AAC1B,
|
|
1
|
+
{"version":3,"file":"index.js","names":["briij","globalThis","__briij_js_sdk_entrypoint","Error","CreditsClient"],"sources":["../src/index.ts"],"sourcesContent":["/*\nCopyright 2019 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport * as briij from \"./briij.ts\";\n\nif (globalThis.__briij_js_sdk_entrypoint) {\n throw new Error(\"Multiple briij-js-sdk entrypoints detected!\");\n}\nglobalThis.__briij_js_sdk_entrypoint = true;\n\nexport * from \"./briij.ts\";\nexport * from \"./credits\";\nexport { CreditsClient } from \"./credits\";\nexport default briij;\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,KAAKA,KAAK,MAAM,YAAY;AAEnC,IAAIC,UAAU,CAACC,yBAAyB,EAAE;EACtC,MAAM,IAAIC,KAAK,CAAC,6CAA6C,CAAC;AAClE;AACAF,UAAU,CAACC,yBAAyB,GAAG,IAAI;AAE3C,cAAc,YAAY;AAC1B,cAAc,WAAW;AACzB,SAASE,aAAa,QAAQ,WAAW;AACzC,eAAeJ,KAAK","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@textrp/briij-js-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "44.0.0",
|
|
4
4
|
"description": "Briij Client-Server SDK for JavaScript and TypeScript",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22.0.0"
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"another-json": "^0.2.0",
|
|
40
40
|
"bs58": "^6.0.0",
|
|
41
41
|
"content-type": "^1.0.4",
|
|
42
|
+
"did-resolver": "^4.1.0",
|
|
42
43
|
"jwt-decode": "^4.0.0",
|
|
43
44
|
"loglevel": "^1.9.2",
|
|
44
45
|
"matrix-events-sdk": "0.0.1",
|
|
@@ -46,6 +47,7 @@
|
|
|
46
47
|
"oidc-client-ts": "^3.0.1",
|
|
47
48
|
"p-retry": "7",
|
|
48
49
|
"sdp-transform": "^3.0.0",
|
|
50
|
+
"snarkjs": "^0.7.6",
|
|
49
51
|
"unhomoglyph": "^1.0.6",
|
|
50
52
|
"uuid": "13",
|
|
51
53
|
"xrpl": "^4.6.0"
|
package/src/@types/auth.ts
CHANGED
|
@@ -270,6 +270,50 @@ export interface WalletIdentityAccountData {
|
|
|
270
270
|
public_key?: string | null;
|
|
271
271
|
network?: string | null;
|
|
272
272
|
key_type?: string | null;
|
|
273
|
+
did_uri?: string | null;
|
|
274
|
+
credential_id?: string | null;
|
|
275
|
+
e2ee_pubkey_commitment?: string | null;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
interface DidVerificationMethod {
|
|
279
|
+
id: string;
|
|
280
|
+
type: string;
|
|
281
|
+
controller: string;
|
|
282
|
+
publicKeyMultibase?: string;
|
|
283
|
+
blockchainAccountId?: string;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
export interface DidResolutionResult {
|
|
287
|
+
did_uri: string;
|
|
288
|
+
resolution_type?: string;
|
|
289
|
+
did_document: {
|
|
290
|
+
id: string;
|
|
291
|
+
verificationMethod: DidVerificationMethod[];
|
|
292
|
+
authentication: string[];
|
|
293
|
+
service?: Array<Record<string, string>>;
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export interface CredentialCreateResult {
|
|
298
|
+
credential_id: string;
|
|
299
|
+
status: string;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export interface CredentialVerifyResult {
|
|
303
|
+
credential_id: string;
|
|
304
|
+
valid: boolean;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export interface ZkpVerifyResult {
|
|
308
|
+
valid: boolean;
|
|
309
|
+
verified_at?: number;
|
|
310
|
+
reason?: string;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
export interface DidCredentialMetadata {
|
|
314
|
+
didUri: string;
|
|
315
|
+
credentialId: string;
|
|
316
|
+
issuedAt: number;
|
|
273
317
|
}
|
|
274
318
|
|
|
275
319
|
export interface XrplWalletLoginRequest extends Omit<LoginRequest, "type"> {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare module "snarkjs" {
|
|
2
|
+
export const groth16: {
|
|
3
|
+
fullProve: (
|
|
4
|
+
input: Record<string, string>,
|
|
5
|
+
wasmPath: string,
|
|
6
|
+
zkeyPath: string,
|
|
7
|
+
) => Promise<{
|
|
8
|
+
proof: Record<string, unknown>;
|
|
9
|
+
publicSignals: string[] | Record<string, string>;
|
|
10
|
+
}>;
|
|
11
|
+
verify: (
|
|
12
|
+
verificationKey: Record<string, unknown>,
|
|
13
|
+
publicSignals: string[] | Record<string, string>,
|
|
14
|
+
proof: Record<string, unknown>,
|
|
15
|
+
) => Promise<boolean>;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2026 Xurge Digital Lab
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export interface CredentialCreateRequest {
|
|
12
|
+
did_uri: string;
|
|
13
|
+
subject: string;
|
|
14
|
+
e2ee_pubkey_commitment: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface CredentialCreateResponse {
|
|
18
|
+
credential_id: string;
|
|
19
|
+
status: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface CredentialVerifyResponse {
|
|
23
|
+
credential_id: string;
|
|
24
|
+
valid: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface DidCredentialMetadata {
|
|
28
|
+
didUri: string;
|
|
29
|
+
credentialId: string;
|
|
30
|
+
issuedAt: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const METADATA_KEY = "briij.did_credential_metadata";
|
|
34
|
+
const memoryMetadata = new Map<string, DidCredentialMetadata>();
|
|
35
|
+
|
|
36
|
+
export async function requestCredentialCreate(
|
|
37
|
+
requester: (path: string, method: "POST", body: CredentialCreateRequest) => Promise<CredentialCreateResponse>,
|
|
38
|
+
payload: CredentialCreateRequest,
|
|
39
|
+
): Promise<CredentialCreateResponse> {
|
|
40
|
+
return requester("/credential/create", "POST", payload);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function verifyCredential(
|
|
44
|
+
requester: (path: string, method: "POST", body: { credential_id: string }) => Promise<CredentialVerifyResponse>,
|
|
45
|
+
credentialId: string,
|
|
46
|
+
): Promise<CredentialVerifyResponse> {
|
|
47
|
+
return requester("/credential/verify", "POST", { credential_id: credentialId });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function storeDidCredentialMetadata(userId: string, metadata: DidCredentialMetadata): void {
|
|
51
|
+
memoryMetadata.set(userId, metadata);
|
|
52
|
+
if (globalThis.localStorage) {
|
|
53
|
+
globalThis.localStorage.setItem(`${METADATA_KEY}:${userId}`, JSON.stringify(metadata));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function loadDidCredentialMetadata(userId: string): DidCredentialMetadata | null {
|
|
58
|
+
const fromMemory = memoryMetadata.get(userId);
|
|
59
|
+
if (fromMemory) return fromMemory;
|
|
60
|
+
const raw = globalThis.localStorage?.getItem(`${METADATA_KEY}:${userId}`);
|
|
61
|
+
if (!raw) return null;
|
|
62
|
+
return JSON.parse(raw) as DidCredentialMetadata;
|
|
63
|
+
}
|
package/src/auth/did.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2026 Xurge Digital Lab
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { Resolver } from "did-resolver";
|
|
12
|
+
|
|
13
|
+
export interface DidVerificationMethod {
|
|
14
|
+
id: string;
|
|
15
|
+
type: string;
|
|
16
|
+
controller: string;
|
|
17
|
+
publicKeyMultibase?: string;
|
|
18
|
+
blockchainAccountId?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface DidDocumentShape {
|
|
22
|
+
id: string;
|
|
23
|
+
verificationMethod: DidVerificationMethod[];
|
|
24
|
+
authentication: string[];
|
|
25
|
+
service?: Array<Record<string, string>>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface DidResolutionResponse {
|
|
29
|
+
did_uri: string;
|
|
30
|
+
resolution_type?: string;
|
|
31
|
+
did_document: DidDocumentShape;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const fallbackResolver = new Resolver({});
|
|
35
|
+
|
|
36
|
+
export function deriveXrplDid(address: string, network: "testnet" | "mainnet" = "testnet"): string {
|
|
37
|
+
if (!address || !address.startsWith("r")) {
|
|
38
|
+
throw new Error("Invalid XRPL address");
|
|
39
|
+
}
|
|
40
|
+
return `did:xrpl:${network}:${address}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function createMinimalDidDocument(didUri: string, e2eePubkeyCommitment: string): DidDocumentShape {
|
|
44
|
+
return {
|
|
45
|
+
id: didUri,
|
|
46
|
+
verificationMethod: [
|
|
47
|
+
{
|
|
48
|
+
id: `${didUri}#owner`,
|
|
49
|
+
type: "EcdsaSecp256k1RecoveryMethod2020",
|
|
50
|
+
controller: didUri,
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
id: `${didUri}#e2ee`,
|
|
54
|
+
type: "E2EEPublicKeyCommitment",
|
|
55
|
+
controller: didUri,
|
|
56
|
+
publicKeyMultibase: e2eePubkeyCommitment,
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
authentication: [`${didUri}#owner`],
|
|
60
|
+
service: [
|
|
61
|
+
{
|
|
62
|
+
id: `${didUri}#did-resolution`,
|
|
63
|
+
type: "BriijDidResolution",
|
|
64
|
+
serviceEndpoint: "/_matrix/client/v3/did/resolve",
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function resolveDidViaHomeserver(
|
|
71
|
+
requester: (path: string, method: "GET") => Promise<DidResolutionResponse>,
|
|
72
|
+
account: string,
|
|
73
|
+
): Promise<DidResolutionResponse> {
|
|
74
|
+
const direct = await requester(`/did/resolve?account=${encodeURIComponent(account)}`, "GET");
|
|
75
|
+
if (direct?.did_document?.id) {
|
|
76
|
+
return direct;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Keep a resolver instance available for future DID-method plugins.
|
|
80
|
+
const fallback = await fallbackResolver.resolve(`did:xrpl:testnet:${account}`);
|
|
81
|
+
if (fallback.didDocument) {
|
|
82
|
+
return {
|
|
83
|
+
did_uri: fallback.didDocument.id,
|
|
84
|
+
did_document: fallback.didDocument as DidDocumentShape,
|
|
85
|
+
resolution_type: "resolver-fallback",
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
throw new Error("Failed to resolve DID document");
|
|
89
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2026 Xurge Digital Lab
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { XRPL_WALLET_LOGIN_TYPE } from "../@types/auth.ts";
|
|
12
|
+
|
|
13
|
+
export interface WalletProofResult {
|
|
14
|
+
address: string;
|
|
15
|
+
signature: string;
|
|
16
|
+
publicKey?: string;
|
|
17
|
+
network?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface WalletLoginSubmission {
|
|
21
|
+
type: typeof XRPL_WALLET_LOGIN_TYPE;
|
|
22
|
+
address: string;
|
|
23
|
+
signature: string;
|
|
24
|
+
public_key?: string;
|
|
25
|
+
network: string;
|
|
26
|
+
session: string;
|
|
27
|
+
username?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type WalletProofProvider = (challenge: string, network: string) => Promise<WalletProofResult>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Normalizes wallet proof payload to the login body used by the homeserver.
|
|
34
|
+
*/
|
|
35
|
+
export function buildWalletLoginSubmission(
|
|
36
|
+
proof: WalletProofResult,
|
|
37
|
+
session: string,
|
|
38
|
+
network: string,
|
|
39
|
+
username?: string,
|
|
40
|
+
): WalletLoginSubmission {
|
|
41
|
+
return {
|
|
42
|
+
type: XRPL_WALLET_LOGIN_TYPE,
|
|
43
|
+
session,
|
|
44
|
+
address: proof.address,
|
|
45
|
+
signature: proof.signature,
|
|
46
|
+
public_key: proof.publicKey,
|
|
47
|
+
network: proof.network ?? network,
|
|
48
|
+
username,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2026 Xurge Digital Lab
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export interface E2eeZkInput {
|
|
12
|
+
didUri: string;
|
|
13
|
+
xrplAddress: string;
|
|
14
|
+
e2eePrivateKey: string;
|
|
15
|
+
credentialId: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface E2eeZkProofPayload {
|
|
19
|
+
proof: Record<string, unknown>;
|
|
20
|
+
publicSignals: string[] | Record<string, string>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface E2eeZkGenerateOptions {
|
|
24
|
+
wasmPath: string;
|
|
25
|
+
zkeyPath: string;
|
|
26
|
+
fullProve?: (
|
|
27
|
+
input: Record<string, string>,
|
|
28
|
+
wasmPath: string,
|
|
29
|
+
zkeyPath: string,
|
|
30
|
+
) => Promise<E2eeZkProofPayload>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface E2eeZkVerifyOptions {
|
|
34
|
+
verificationKey: Record<string, unknown>;
|
|
35
|
+
verify?: (
|
|
36
|
+
verificationKey: Record<string, unknown>,
|
|
37
|
+
publicSignals: E2eeZkProofPayload["publicSignals"],
|
|
38
|
+
proof: E2eeZkProofPayload["proof"],
|
|
39
|
+
) => Promise<boolean>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function sha256Hex(input: string): Promise<string> {
|
|
43
|
+
if (!globalThis.crypto?.subtle) {
|
|
44
|
+
return input;
|
|
45
|
+
}
|
|
46
|
+
const digest = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(input));
|
|
47
|
+
return Array.from(new Uint8Array(digest))
|
|
48
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
49
|
+
.join("");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export async function generateE2eeZkProof(
|
|
53
|
+
input: E2eeZkInput,
|
|
54
|
+
options: E2eeZkGenerateOptions,
|
|
55
|
+
): Promise<E2eeZkProofPayload> {
|
|
56
|
+
const fullProve =
|
|
57
|
+
options.fullProve ??
|
|
58
|
+
(async (signals, wasmPath, zkeyPath) => {
|
|
59
|
+
const snarkjs = await import("snarkjs");
|
|
60
|
+
return snarkjs.groth16.fullProve(signals, wasmPath, zkeyPath);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const e2eePrivateKeyHash = await sha256Hex(input.e2eePrivateKey);
|
|
64
|
+
return fullProve(
|
|
65
|
+
{
|
|
66
|
+
did_uri: input.didUri,
|
|
67
|
+
xrpl_address: input.xrplAddress,
|
|
68
|
+
credential_id: input.credentialId,
|
|
69
|
+
e2ee_privkey_hash: e2eePrivateKeyHash,
|
|
70
|
+
},
|
|
71
|
+
options.wasmPath,
|
|
72
|
+
options.zkeyPath,
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export async function verifyE2eeZkProof(
|
|
77
|
+
payload: E2eeZkProofPayload,
|
|
78
|
+
options: E2eeZkVerifyOptions,
|
|
79
|
+
): Promise<boolean> {
|
|
80
|
+
const verifier =
|
|
81
|
+
options.verify ??
|
|
82
|
+
(async (verificationKey, publicSignals, proof) => {
|
|
83
|
+
const snarkjs = await import("snarkjs");
|
|
84
|
+
return snarkjs.groth16.verify(verificationKey, publicSignals, proof);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
return verifier(options.verificationKey, payload.publicSignals, payload.proof);
|
|
88
|
+
}
|
package/src/briij.ts
CHANGED
|
@@ -49,6 +49,18 @@ export * from "./scheduler.ts";
|
|
|
49
49
|
export * from "./filter.ts";
|
|
50
50
|
export * from "./timeline-window.ts";
|
|
51
51
|
export * from "./interactive-auth.ts";
|
|
52
|
+
export * from "./auth/did.ts";
|
|
53
|
+
export {
|
|
54
|
+
type CredentialCreateRequest,
|
|
55
|
+
type CredentialCreateResponse,
|
|
56
|
+
type CredentialVerifyResponse,
|
|
57
|
+
loadDidCredentialMetadata,
|
|
58
|
+
requestCredentialCreate,
|
|
59
|
+
storeDidCredentialMetadata,
|
|
60
|
+
verifyCredential,
|
|
61
|
+
} from "./auth/credential.ts";
|
|
62
|
+
export * from "./auth/wallet.ts";
|
|
63
|
+
export * from "./auth/zkpE2EE.ts";
|
|
52
64
|
export * from "./xrpl/identity.ts";
|
|
53
65
|
export * from "./xrpl/trust.ts";
|
|
54
66
|
export * from "./xrpl/verification.ts";
|