@textrp/briij-js-sdk 43.2.1 → 44.1.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 +24 -1
- package/README.md +66 -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 +5 -0
- package/lib/briij.d.ts.map +1 -1
- package/lib/briij.js +5 -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/xrpl/clientSignedBinding.d.ts +21 -0
- package/lib/xrpl/clientSignedBinding.d.ts.map +1 -0
- package/lib/xrpl/clientSignedBinding.js +112 -0
- package/lib/xrpl/clientSignedBinding.js.map +1 -0
- 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 +13 -0
- package/src/client.ts +187 -0
- package/src/components/LoginStepper.tsx +50 -0
- package/src/xrpl/clientSignedBinding.ts +136 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface XrplClientSignedWalletAdapter {
|
|
2
|
+
getAddress(): Promise<string>;
|
|
3
|
+
signAndSubmit(tx: Record<string, unknown>): Promise<{
|
|
4
|
+
hash: string;
|
|
5
|
+
txBlob?: string;
|
|
6
|
+
signedTxBlob?: string;
|
|
7
|
+
}>;
|
|
8
|
+
}
|
|
9
|
+
export interface XrplClientSignedBindingConfig {
|
|
10
|
+
homeserverBaseUrl: string;
|
|
11
|
+
accessToken: string;
|
|
12
|
+
wallet: XrplClientSignedWalletAdapter;
|
|
13
|
+
network?: "xrpl" | "xahau";
|
|
14
|
+
}
|
|
15
|
+
export interface XrplClientSignedBindingResult {
|
|
16
|
+
did: Record<string, unknown>;
|
|
17
|
+
credential: Record<string, unknown>;
|
|
18
|
+
}
|
|
19
|
+
export declare function configureXrplClientSignedBinding(config: Partial<XrplClientSignedBindingConfig>): void;
|
|
20
|
+
export declare function runClientSignedDidCredentialBinding(e2eePubkeyCommitment: string): Promise<XrplClientSignedBindingResult>;
|
|
21
|
+
//# sourceMappingURL=clientSignedBinding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clientSignedBinding.d.ts","sourceRoot":"","sources":["../../src/xrpl/clientSignedBinding.ts"],"names":[],"mappings":"AAkBA,MAAM,WAAW,6BAA6B;IAC1C,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAC9B,aAAa,CAAC,EAAE,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC;QAChD,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,YAAY,CAAC,EAAE,MAAM,CAAC;KACzB,CAAC,CAAC;CACN;AAED,MAAM,WAAW,6BAA6B;IAC1C,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,6BAA6B,CAAC;IACtC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CAC9B;AAED,MAAM,WAAW,6BAA6B;IAC1C,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACvC;AAID,wBAAgB,gCAAgC,CAAC,MAAM,EAAE,OAAO,CAAC,6BAA6B,CAAC,GAAG,IAAI,CAKrG;AAED,wBAAsB,mCAAmC,CACrD,oBAAoB,EAAE,MAAM,GAC7B,OAAO,CAAC,6BAA6B,CAAC,CAwDxC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
|
+
/*
|
|
6
|
+
Copyright 2026 The Matrix.org Foundation C.I.C.
|
|
7
|
+
|
|
8
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
you may not use this file except in compliance with the License.
|
|
10
|
+
You may obtain a copy of the License at
|
|
11
|
+
|
|
12
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
|
|
14
|
+
Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
See the License for the specific language governing permissions and
|
|
18
|
+
limitations under the License.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { logger } from "../logger.js";
|
|
22
|
+
var bindingConfig = {};
|
|
23
|
+
export function configureXrplClientSignedBinding(config) {
|
|
24
|
+
bindingConfig = _objectSpread(_objectSpread({}, bindingConfig), config);
|
|
25
|
+
}
|
|
26
|
+
export function runClientSignedDidCredentialBinding(_x) {
|
|
27
|
+
return _runClientSignedDidCredentialBinding.apply(this, arguments);
|
|
28
|
+
}
|
|
29
|
+
function _runClientSignedDidCredentialBinding() {
|
|
30
|
+
_runClientSignedDidCredentialBinding = _asyncToGenerator(function* (e2eePubkeyCommitment) {
|
|
31
|
+
var _bindingConfig$networ, _didSignResult$txBlob, _credentialSignResult;
|
|
32
|
+
var {
|
|
33
|
+
homeserverBaseUrl,
|
|
34
|
+
accessToken,
|
|
35
|
+
wallet
|
|
36
|
+
} = bindingConfig;
|
|
37
|
+
var network = (_bindingConfig$networ = bindingConfig.network) !== null && _bindingConfig$networ !== void 0 ? _bindingConfig$networ : "xrpl";
|
|
38
|
+
if (!homeserverBaseUrl || !accessToken || !wallet) {
|
|
39
|
+
throw new Error("XRPL client-signed binding is not configured");
|
|
40
|
+
}
|
|
41
|
+
var xrplAddress = yield wallet.getAddress();
|
|
42
|
+
var didPrepare = yield postJson(homeserverBaseUrl, accessToken, "/_matrix/client/v3/did/prepare", {
|
|
43
|
+
xrpl_address: xrplAddress,
|
|
44
|
+
network,
|
|
45
|
+
e2ee_pubkey_commitment: e2eePubkeyCommitment
|
|
46
|
+
});
|
|
47
|
+
var didSignResult = yield wallet.signAndSubmit(asObject(didPrepare.unsigned_tx, "did unsigned_tx"));
|
|
48
|
+
var didTxBlob = (_didSignResult$txBlob = didSignResult.txBlob) !== null && _didSignResult$txBlob !== void 0 ? _didSignResult$txBlob : didSignResult.signedTxBlob;
|
|
49
|
+
if (!didTxBlob) {
|
|
50
|
+
throw new Error("Wallet adapter must return txBlob/signedTxBlob for DID finalize");
|
|
51
|
+
}
|
|
52
|
+
var didFinalize = yield postJson(homeserverBaseUrl, accessToken, "/_matrix/client/v3/did/finalize", {
|
|
53
|
+
xrpl_address: xrplAddress,
|
|
54
|
+
network,
|
|
55
|
+
session: didPrepare.session,
|
|
56
|
+
tx_blob: didTxBlob,
|
|
57
|
+
tx_hash: didSignResult.hash
|
|
58
|
+
});
|
|
59
|
+
var credentialPrepare = yield postJson(homeserverBaseUrl, accessToken, "/_matrix/client/v3/credential/prepare", {
|
|
60
|
+
xrpl_address: xrplAddress,
|
|
61
|
+
network,
|
|
62
|
+
e2ee_pubkey_commitment: e2eePubkeyCommitment
|
|
63
|
+
});
|
|
64
|
+
var credentialSignResult = yield wallet.signAndSubmit(asObject(credentialPrepare.unsigned_tx, "credential unsigned_tx"));
|
|
65
|
+
var credentialTxBlob = (_credentialSignResult = credentialSignResult.txBlob) !== null && _credentialSignResult !== void 0 ? _credentialSignResult : credentialSignResult.signedTxBlob;
|
|
66
|
+
if (!credentialTxBlob) {
|
|
67
|
+
throw new Error("Wallet adapter must return txBlob/signedTxBlob for credential finalize");
|
|
68
|
+
}
|
|
69
|
+
var credentialFinalize = yield postJson(homeserverBaseUrl, accessToken, "/_matrix/client/v3/credential/finalize", {
|
|
70
|
+
xrpl_address: xrplAddress,
|
|
71
|
+
network,
|
|
72
|
+
session: credentialPrepare.session,
|
|
73
|
+
tx_blob: credentialTxBlob,
|
|
74
|
+
tx_hash: credentialSignResult.hash
|
|
75
|
+
});
|
|
76
|
+
logger.info("Completed client-signed DID/Credential binding for %s", xrplAddress);
|
|
77
|
+
return {
|
|
78
|
+
did: didFinalize,
|
|
79
|
+
credential: credentialFinalize
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
return _runClientSignedDidCredentialBinding.apply(this, arguments);
|
|
83
|
+
}
|
|
84
|
+
function asObject(value, name) {
|
|
85
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
86
|
+
throw new Error("Invalid ".concat(name, " payload from homeserver"));
|
|
87
|
+
}
|
|
88
|
+
return value;
|
|
89
|
+
}
|
|
90
|
+
function postJson(_x2, _x3, _x4, _x5) {
|
|
91
|
+
return _postJson.apply(this, arguments);
|
|
92
|
+
}
|
|
93
|
+
function _postJson() {
|
|
94
|
+
_postJson = _asyncToGenerator(function* (homeserverBaseUrl, accessToken, path, body) {
|
|
95
|
+
var response = yield fetch("".concat(homeserverBaseUrl.replace(/\/+$/, "")).concat(path), {
|
|
96
|
+
method: "POST",
|
|
97
|
+
headers: {
|
|
98
|
+
Authorization: "Bearer ".concat(accessToken),
|
|
99
|
+
"Content-Type": "application/json"
|
|
100
|
+
},
|
|
101
|
+
body: JSON.stringify(body)
|
|
102
|
+
});
|
|
103
|
+
var payload = yield response.json().catch(() => ({}));
|
|
104
|
+
if (!response.ok) {
|
|
105
|
+
var message = typeof payload.error === "string" ? payload.error : "HTTP ".concat(response.status);
|
|
106
|
+
throw new Error("XRPL client-signed request failed (".concat(path, "): ").concat(message));
|
|
107
|
+
}
|
|
108
|
+
return payload;
|
|
109
|
+
});
|
|
110
|
+
return _postJson.apply(this, arguments);
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=clientSignedBinding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clientSignedBinding.js","names":["logger","bindingConfig","configureXrplClientSignedBinding","config","_objectSpread","runClientSignedDidCredentialBinding","_x","_runClientSignedDidCredentialBinding","apply","arguments","_asyncToGenerator","e2eePubkeyCommitment","_bindingConfig$networ","_didSignResult$txBlob","_credentialSignResult","homeserverBaseUrl","accessToken","wallet","network","Error","xrplAddress","getAddress","didPrepare","postJson","xrpl_address","e2ee_pubkey_commitment","didSignResult","signAndSubmit","asObject","unsigned_tx","didTxBlob","txBlob","signedTxBlob","didFinalize","session","tx_blob","tx_hash","hash","credentialPrepare","credentialSignResult","credentialTxBlob","credentialFinalize","info","did","credential","value","name","Array","isArray","concat","_x2","_x3","_x4","_x5","_postJson","path","body","response","fetch","replace","method","headers","Authorization","JSON","stringify","payload","json","catch","ok","message","error","status"],"sources":["../../src/xrpl/clientSignedBinding.ts"],"sourcesContent":["/*\nCopyright 2026 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 { logger } from \"../logger.ts\";\n\nexport interface XrplClientSignedWalletAdapter {\n getAddress(): Promise<string>;\n signAndSubmit(tx: Record<string, unknown>): Promise<{\n hash: string;\n txBlob?: string;\n signedTxBlob?: string;\n }>;\n}\n\nexport interface XrplClientSignedBindingConfig {\n homeserverBaseUrl: string;\n accessToken: string;\n wallet: XrplClientSignedWalletAdapter;\n network?: \"xrpl\" | \"xahau\";\n}\n\nexport interface XrplClientSignedBindingResult {\n did: Record<string, unknown>;\n credential: Record<string, unknown>;\n}\n\nlet bindingConfig: Partial<XrplClientSignedBindingConfig> = {};\n\nexport function configureXrplClientSignedBinding(config: Partial<XrplClientSignedBindingConfig>): void {\n bindingConfig = {\n ...bindingConfig,\n ...config,\n };\n}\n\nexport async function runClientSignedDidCredentialBinding(\n e2eePubkeyCommitment: string,\n): Promise<XrplClientSignedBindingResult> {\n const { homeserverBaseUrl, accessToken, wallet } = bindingConfig;\n const network = bindingConfig.network ?? \"xrpl\";\n if (!homeserverBaseUrl || !accessToken || !wallet) {\n throw new Error(\"XRPL client-signed binding is not configured\");\n }\n\n const xrplAddress = await wallet.getAddress();\n const didPrepare = await postJson(homeserverBaseUrl, accessToken, \"/_matrix/client/v3/did/prepare\", {\n xrpl_address: xrplAddress,\n network,\n e2ee_pubkey_commitment: e2eePubkeyCommitment,\n });\n const didSignResult = await wallet.signAndSubmit(asObject(didPrepare.unsigned_tx, \"did unsigned_tx\"));\n const didTxBlob = didSignResult.txBlob ?? didSignResult.signedTxBlob;\n if (!didTxBlob) {\n throw new Error(\"Wallet adapter must return txBlob/signedTxBlob for DID finalize\");\n }\n const didFinalize = await postJson(homeserverBaseUrl, accessToken, \"/_matrix/client/v3/did/finalize\", {\n xrpl_address: xrplAddress,\n network,\n session: didPrepare.session,\n tx_blob: didTxBlob,\n tx_hash: didSignResult.hash,\n });\n\n const credentialPrepare = await postJson(homeserverBaseUrl, accessToken, \"/_matrix/client/v3/credential/prepare\", {\n xrpl_address: xrplAddress,\n network,\n e2ee_pubkey_commitment: e2eePubkeyCommitment,\n });\n const credentialSignResult = await wallet.signAndSubmit(\n asObject(credentialPrepare.unsigned_tx, \"credential unsigned_tx\"),\n );\n const credentialTxBlob = credentialSignResult.txBlob ?? credentialSignResult.signedTxBlob;\n if (!credentialTxBlob) {\n throw new Error(\"Wallet adapter must return txBlob/signedTxBlob for credential finalize\");\n }\n const credentialFinalize = await postJson(\n homeserverBaseUrl,\n accessToken,\n \"/_matrix/client/v3/credential/finalize\",\n {\n xrpl_address: xrplAddress,\n network,\n session: credentialPrepare.session,\n tx_blob: credentialTxBlob,\n tx_hash: credentialSignResult.hash,\n },\n );\n\n logger.info(\"Completed client-signed DID/Credential binding for %s\", xrplAddress);\n return {\n did: didFinalize,\n credential: credentialFinalize,\n };\n}\n\nfunction asObject(value: unknown, name: string): Record<string, unknown> {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) {\n throw new Error(`Invalid ${name} payload from homeserver`);\n }\n return value as Record<string, unknown>;\n}\n\nasync function postJson(\n homeserverBaseUrl: string,\n accessToken: string,\n path: string,\n body: Record<string, unknown>,\n): Promise<Record<string, unknown>> {\n const response = await fetch(`${homeserverBaseUrl.replace(/\\/+$/, \"\")}${path}`, {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${accessToken}`,\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(body),\n });\n const payload = (await response.json().catch(() => ({}))) as Record<string, unknown>;\n if (!response.ok) {\n const message = typeof payload.error === \"string\" ? payload.error : `HTTP ${response.status}`;\n throw new Error(`XRPL client-signed request failed (${path}): ${message}`);\n }\n return payload;\n}\n"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,MAAM,QAAQ,cAAc;AAuBrC,IAAIC,aAAqD,GAAG,CAAC,CAAC;AAE9D,OAAO,SAASC,gCAAgCA,CAACC,MAA8C,EAAQ;EACnGF,aAAa,GAAAG,aAAA,CAAAA,aAAA,KACNH,aAAa,GACbE,MAAM,CACZ;AACL;AAEA,gBAAsBE,mCAAmCA,CAAAC,EAAA;EAAA,OAAAC,oCAAA,CAAAC,KAAA,OAAAC,SAAA;AAAA;AA0DxD,SAAAF,qCAAA;EAAAA,oCAAA,GAAAG,iBAAA,CA1DM,WACHC,oBAA4B,EACU;IAAA,IAAAC,qBAAA,EAAAC,qBAAA,EAAAC,qBAAA;IACtC,IAAM;MAAEC,iBAAiB;MAAEC,WAAW;MAAEC;IAAO,CAAC,GAAGhB,aAAa;IAChE,IAAMiB,OAAO,IAAAN,qBAAA,GAAGX,aAAa,CAACiB,OAAO,cAAAN,qBAAA,cAAAA,qBAAA,GAAI,MAAM;IAC/C,IAAI,CAACG,iBAAiB,IAAI,CAACC,WAAW,IAAI,CAACC,MAAM,EAAE;MAC/C,MAAM,IAAIE,KAAK,CAAC,8CAA8C,CAAC;IACnE;IAEA,IAAMC,WAAW,SAASH,MAAM,CAACI,UAAU,CAAC,CAAC;IAC7C,IAAMC,UAAU,SAASC,QAAQ,CAACR,iBAAiB,EA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AQ,CAACS,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAA6B;IACpF,IAAI,CAACV,QAAQ,CAACW,EAAE,EAAE;MACd,IAAMC,OAAO,GAAG,OAAOJ,OAAO,CAACK,KAAK,KAAK,QAAQ,GAAGL,OAAO,CAACK,KAAK,WAAArB,MAAA,CAAWQ,QAAQ,CAACc,MAAM,CAAE;MAC7F,MAAM,IAAIpD,KAAK,uCAAA8B,MAAA,CAAuCM,IAAI,SAAAN,MAAA,CAAMoB,OAAO,CAAE,CAAC;IAC9E;IACA,OAAOJ,OAAO;EAClB,CAAC;EAAA,OAAAX,SAAA,CAAA9C,KAAA,OAAAC,SAAA;AAAA","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@textrp/briij-js-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "44.1.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,7 +49,20 @@ 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";
|
|
65
|
+
export * from "./xrpl/clientSignedBinding.ts";
|
|
53
66
|
export * from "./xrpl/trust.ts";
|
|
54
67
|
export * from "./xrpl/verification.ts";
|
|
55
68
|
export * from "./wallet-recovery.ts";
|