@reyaxyz/sdk 0.106.61 → 0.106.63
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/README.md +1 -1
- package/package.json +3 -5
- package/dist/services/auth/authenticate.js +0 -73
- package/dist/services/auth/authenticate.js.map +0 -1
- package/dist/services/auth/checkSupport.js +0 -5
- package/dist/services/auth/checkSupport.js.map +0 -1
- package/dist/services/auth/embeddedWalletHelpers.js +0 -101
- package/dist/services/auth/embeddedWalletHelpers.js.map +0 -1
- package/dist/services/auth/index.js +0 -2
- package/dist/services/auth/index.js.map +0 -1
- package/dist/services/auth/register.js +0 -94
- package/dist/services/auth/register.js.map +0 -1
- package/dist/types/services/auth/authenticate.d.ts +0 -2
- package/dist/types/services/auth/authenticate.d.ts.map +0 -1
- package/dist/types/services/auth/checkSupport.d.ts +0 -1
- package/dist/types/services/auth/checkSupport.d.ts.map +0 -1
- package/dist/types/services/auth/embeddedWalletHelpers.d.ts +0 -7
- package/dist/types/services/auth/embeddedWalletHelpers.d.ts.map +0 -1
- package/dist/types/services/auth/index.d.ts +0 -1
- package/dist/types/services/auth/index.d.ts.map +0 -1
- package/dist/types/services/auth/register.d.ts +0 -4
- package/dist/types/services/auth/register.d.ts.map +0 -1
- package/src/services/auth/authenticate.ts +0 -22
- package/src/services/auth/checkSupport.ts +0 -3
- package/src/services/auth/embeddedWalletHelpers.ts +0 -70
- package/src/services/auth/index.ts +0 -0
- package/src/services/auth/register.ts +0 -51
package/README.md
CHANGED
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
|
|
7
7
|
| Statements | Branches | Functions | Lines |
|
|
8
8
|
| --------------------------- | ----------------------- | ------------------------- | ----------------- |
|
|
9
|
-
|  |  |  |  |
|
|
10
10
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/sdk",
|
|
3
|
-
"version": "0.106.
|
|
3
|
+
"version": "0.106.63",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -29,13 +29,11 @@
|
|
|
29
29
|
"generate:coverage-badges": "npx istanbul-badges-readme --silent"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@reyaxyz/common": "0.
|
|
33
|
-
"@simplewebauthn/browser": "^10.0.0",
|
|
34
|
-
"@simplewebauthn/types": "^10.0.0",
|
|
32
|
+
"@reyaxyz/common": "0.185.0",
|
|
35
33
|
"axios": "^1.6.2",
|
|
36
34
|
"bignumber.js": "^9.1.2",
|
|
37
35
|
"ethers": "6.9.0"
|
|
38
36
|
},
|
|
39
37
|
"packageManager": "pnpm@8.3.1",
|
|
40
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "ea6c0ba19b703139df94f8420746771c3968f183"
|
|
41
39
|
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.authenticate = void 0;
|
|
43
|
-
var axios_1 = __importDefault(require("axios"));
|
|
44
|
-
var browser_1 = require("@simplewebauthn/browser");
|
|
45
|
-
var authenticate = function (baseUrl) { return __awaiter(void 0, void 0, void 0, function () {
|
|
46
|
-
var authenticationOptions, attestationResponse, error_1, verificationResponse;
|
|
47
|
-
return __generator(this, function (_a) {
|
|
48
|
-
switch (_a.label) {
|
|
49
|
-
case 0: return [4 /*yield*/, axios_1.default.get("".concat(baseUrl, "/api/auth/generate-authentication-options"))];
|
|
50
|
-
case 1:
|
|
51
|
-
authenticationOptions = _a.sent();
|
|
52
|
-
_a.label = 2;
|
|
53
|
-
case 2:
|
|
54
|
-
_a.trys.push([2, 4, , 5]);
|
|
55
|
-
return [4 /*yield*/, (0, browser_1.startAuthentication)(authenticationOptions.data)];
|
|
56
|
-
case 3:
|
|
57
|
-
// Pass the options to the authenticator and wait for a response
|
|
58
|
-
attestationResponse = _a.sent();
|
|
59
|
-
return [3 /*break*/, 5];
|
|
60
|
-
case 4:
|
|
61
|
-
error_1 = _a.sent();
|
|
62
|
-
console.error(error_1);
|
|
63
|
-
throw new Error('Failed to authenticate');
|
|
64
|
-
case 5: return [4 /*yield*/, axios_1.default.post("".concat(baseUrl, "/api/auth/verify-authentication"), JSON.stringify(attestationResponse))];
|
|
65
|
-
case 6:
|
|
66
|
-
verificationResponse = _a.sent();
|
|
67
|
-
return [4 /*yield*/, verificationResponse.data];
|
|
68
|
-
case 7: return [2 /*return*/, _a.sent()];
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}); };
|
|
72
|
-
exports.authenticate = authenticate;
|
|
73
|
-
//# sourceMappingURL=authenticate.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authenticate.js","sourceRoot":"/","sources":["services/auth/authenticate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAA0B;AAC1B,mDAA8D;AAEvD,IAAM,YAAY,GAAG,UAAO,OAAe;;;;oBAClB,qBAAM,eAAK,CAAC,GAAG,CAC3C,UAAG,OAAO,8CAA2C,CACtD,EAAA;;gBAFK,qBAAqB,GAAG,SAE7B;;;;gBAIuB,qBAAM,IAAA,6BAAmB,EAAC,qBAAqB,CAAC,IAAI,CAAC,EAAA;;gBAD3E,gEAAgE;gBAChE,mBAAmB,GAAG,SAAqD,CAAC;;;;gBAE5E,OAAO,CAAC,KAAK,CAAC,OAAK,CAAC,CAAC;gBACrB,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;oBAGf,qBAAM,eAAK,CAAC,IAAI,CAC3C,UAAG,OAAO,oCAAiC,EAC3C,IAAI,CAAC,SAAS,CAAC,mBAAmB,CAAC,CACpC,EAAA;;gBAHK,oBAAoB,GAAG,SAG5B;gBACM,qBAAM,oBAAoB,CAAC,IAAI,EAAA;oBAAtC,sBAAO,SAA+B,EAAC;;;KACxC,CAAC;AAlBW,QAAA,YAAY,gBAkBvB","sourcesContent":["import axios from 'axios';\nimport { startAuthentication } from '@simplewebauthn/browser';\n\nexport const authenticate = async (baseUrl: string) => {\n const authenticationOptions = await axios.get(\n `${baseUrl}/api/auth/generate-authentication-options`,\n );\n let attestationResponse;\n try {\n // Pass the options to the authenticator and wait for a response\n attestationResponse = await startAuthentication(authenticationOptions.data);\n } catch (error) {\n console.error(error);\n throw new Error('Failed to authenticate');\n }\n\n const verificationResponse = await axios.post(\n `${baseUrl}/api/auth/verify-authentication`,\n JSON.stringify(attestationResponse),\n );\n return await verificationResponse.data;\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"checkSupport.js","sourceRoot":"/","sources":["services/auth/checkSupport.ts"],"names":[],"mappings":";AAAA,sCAAsC;AACtC,8CAA8C;AAC9C,+CAA+C","sourcesContent":["// todo: p2: browserSupportsWebAuthn()\n// todo: p2: browserSupportsWebAuthnAutofill()\n// todo: p2: platformAuthenticatorIsAvailable()\n"]}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.generateEmbeddedWallet = void 0;
|
|
40
|
-
var ethers_1 = require("ethers");
|
|
41
|
-
var crypto_1 = require("crypto");
|
|
42
|
-
var generateEmbeddedWallet = function (attestationResponse) { return __awaiter(void 0, void 0, void 0, function () {
|
|
43
|
-
var embeddedWallet, encryptionKey, _a, ciphertext, iv;
|
|
44
|
-
return __generator(this, function (_b) {
|
|
45
|
-
switch (_b.label) {
|
|
46
|
-
case 0:
|
|
47
|
-
embeddedWallet = ethers_1.ethers.Wallet.createRandom();
|
|
48
|
-
return [4 /*yield*/, deriveEncryptionKey(attestationResponse)];
|
|
49
|
-
case 1:
|
|
50
|
-
encryptionKey = _b.sent();
|
|
51
|
-
return [4 /*yield*/, encryptPrivateKey(embeddedWallet.privateKey, encryptionKey)];
|
|
52
|
-
case 2:
|
|
53
|
-
_a = _b.sent(), ciphertext = _a.ciphertext, iv = _a.iv;
|
|
54
|
-
return [2 /*return*/, {
|
|
55
|
-
embeddedWalletAddress: embeddedWallet.address,
|
|
56
|
-
ciphertext: ciphertext,
|
|
57
|
-
iv: iv,
|
|
58
|
-
}];
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
}); };
|
|
62
|
-
exports.generateEmbeddedWallet = generateEmbeddedWallet;
|
|
63
|
-
var deriveEncryptionKey = function (publicKeyCredential) { return __awaiter(void 0, void 0, void 0, function () {
|
|
64
|
-
var rawIdBuffer, keyMaterial;
|
|
65
|
-
return __generator(this, function (_a) {
|
|
66
|
-
switch (_a.label) {
|
|
67
|
-
case 0:
|
|
68
|
-
rawIdBuffer = new TextEncoder().encode(publicKeyCredential.rawId);
|
|
69
|
-
return [4 /*yield*/, crypto_1.subtle.importKey('raw', rawIdBuffer, { name: 'HKDF' }, false, ['deriveKey'])];
|
|
70
|
-
case 1:
|
|
71
|
-
keyMaterial = _a.sent();
|
|
72
|
-
return [4 /*yield*/, crypto_1.subtle.deriveKey({
|
|
73
|
-
name: 'HKDF',
|
|
74
|
-
hash: 'SHA-256',
|
|
75
|
-
salt: new Uint8Array(16), // Use a consistent salt
|
|
76
|
-
info: new TextEncoder().encode('encryption key'),
|
|
77
|
-
}, keyMaterial, { name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt'])];
|
|
78
|
-
case 2: return [2 /*return*/, _a.sent()];
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}); };
|
|
82
|
-
var encryptPrivateKey = function (embeddedWalletPrivateKey, encryptionKey) { return __awaiter(void 0, void 0, void 0, function () {
|
|
83
|
-
var iv, encrypted;
|
|
84
|
-
return __generator(this, function (_a) {
|
|
85
|
-
switch (_a.label) {
|
|
86
|
-
case 0:
|
|
87
|
-
iv = crypto.getRandomValues(new Uint8Array(12));
|
|
88
|
-
return [4 /*yield*/, crypto_1.subtle.encrypt({
|
|
89
|
-
name: 'AES-GCM',
|
|
90
|
-
iv: iv,
|
|
91
|
-
}, encryptionKey, new TextEncoder().encode(embeddedWalletPrivateKey))];
|
|
92
|
-
case 1:
|
|
93
|
-
encrypted = _a.sent();
|
|
94
|
-
return [2 /*return*/, {
|
|
95
|
-
ciphertext: encrypted,
|
|
96
|
-
iv: iv,
|
|
97
|
-
}];
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
}); };
|
|
101
|
-
//# sourceMappingURL=embeddedWalletHelpers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"embeddedWalletHelpers.js","sourceRoot":"/","sources":["services/auth/embeddedWalletHelpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAAgC;AAChC,iCAAgC;AAGzB,IAAM,sBAAsB,GAAG,UACpC,mBAA6C;;;;;gBAEvC,cAAc,GAAG,eAAM,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;gBAE9B,qBAAM,mBAAmB,CAAC,mBAAmB,CAAC,EAAA;;gBAA9D,aAAa,GAAG,SAA8C;gBAEzC,qBAAM,iBAAiB,CAChD,cAAc,CAAC,UAAU,EACzB,aAAa,CACd,EAAA;;gBAHK,KAAqB,SAG1B,EAHO,UAAU,gBAAA,EAAE,EAAE,QAAA;gBAKtB,sBAAO;wBACL,qBAAqB,EAAE,cAAc,CAAC,OAAO;wBAC7C,UAAU,EAAE,UAAU;wBACtB,EAAE,EAAE,EAAE;qBACP,EAAC;;;KACH,CAAC;AAjBW,QAAA,sBAAsB,0BAiBjC;AAEF,IAAM,mBAAmB,GAAG,UAC1B,mBAA6C;;;;;gBAGvC,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC;gBAEpD,qBAAM,eAAM,CAAC,SAAS,CACxC,KAAK,EACL,WAAW,EACX,EAAE,IAAI,EAAE,MAAM,EAAE,EAChB,KAAK,EACL,CAAC,WAAW,CAAC,CACd,EAAA;;gBANK,WAAW,GAAG,SAMnB;gBAEM,qBAAM,eAAM,CAAC,SAAS,CAC3B;wBACE,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,SAAS;wBACf,IAAI,EAAE,IAAI,UAAU,CAAC,EAAE,CAAC,EAAE,wBAAwB;wBAClD,IAAI,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC;qBACjD,EACD,WAAW,EACX,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,EAChC,KAAK,EACL,CAAC,SAAS,EAAE,SAAS,CAAC,CACvB,EAAA;oBAXD,sBAAO,SAWN,EAAC;;;KACH,CAAC;AAEF,IAAM,iBAAiB,GAAG,UACxB,wBAAgC,EAChC,aAAwB;;;;;gBAElB,EAAE,GAAG,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;gBACpC,qBAAM,eAAM,CAAC,OAAO,CACpC;wBACE,IAAI,EAAE,SAAS;wBACf,EAAE,EAAE,EAAE;qBACP,EACD,aAAa,EACb,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,wBAAwB,CAAC,CACnD,EAAA;;gBAPK,SAAS,GAAG,SAOjB;gBAED,sBAAO;wBACL,UAAU,EAAE,SAAS;wBACrB,EAAE,EAAE,EAAE;qBACP,EAAC;;;KACH,CAAC","sourcesContent":["import { ethers } from 'ethers';\nimport { subtle } from 'crypto';\nimport type { RegistrationResponseJSON } from '@simplewebauthn/types';\n\nexport const generateEmbeddedWallet = async (\n attestationResponse: RegistrationResponseJSON,\n) => {\n const embeddedWallet = ethers.Wallet.createRandom();\n\n const encryptionKey = await deriveEncryptionKey(attestationResponse);\n\n const { ciphertext, iv } = await encryptPrivateKey(\n embeddedWallet.privateKey,\n encryptionKey,\n );\n\n return {\n embeddedWalletAddress: embeddedWallet.address,\n ciphertext: ciphertext,\n iv: iv,\n };\n};\n\nconst deriveEncryptionKey = async (\n publicKeyCredential: RegistrationResponseJSON,\n) => {\n // Convert rawId to Uint8Array if it is not already\n const rawIdBuffer = new TextEncoder().encode(publicKeyCredential.rawId);\n\n const keyMaterial = await subtle.importKey(\n 'raw',\n rawIdBuffer,\n { name: 'HKDF' },\n false,\n ['deriveKey'],\n );\n\n return await subtle.deriveKey(\n {\n name: 'HKDF',\n hash: 'SHA-256',\n salt: new Uint8Array(16), // Use a consistent salt\n info: new TextEncoder().encode('encryption key'),\n },\n keyMaterial,\n { name: 'AES-GCM', length: 256 },\n false,\n ['encrypt', 'decrypt'],\n );\n};\n\nconst encryptPrivateKey = async (\n embeddedWalletPrivateKey: string,\n encryptionKey: CryptoKey,\n) => {\n const iv = crypto.getRandomValues(new Uint8Array(12)); // 12 bytes IV for AES-GCM\n const encrypted = await subtle.encrypt(\n {\n name: 'AES-GCM',\n iv: iv,\n },\n encryptionKey,\n new TextEncoder().encode(embeddedWalletPrivateKey),\n );\n\n return {\n ciphertext: encrypted,\n iv: iv,\n };\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["services/auth/index.ts"],"names":[],"mappings":"","sourcesContent":[""]}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
-
};
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.register = void 0;
|
|
43
|
-
var browser_1 = require("@simplewebauthn/browser");
|
|
44
|
-
var embeddedWalletHelpers_1 = require("./embeddedWalletHelpers");
|
|
45
|
-
var axios_1 = __importDefault(require("axios"));
|
|
46
|
-
var common_1 = require("@reyaxyz/common");
|
|
47
|
-
// todo: p2: clean up function inputs (e.g. baseUrl) / introduce types
|
|
48
|
-
var register = function (baseUrl, signer, reyaChainId, accountId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
49
|
-
var registrationOptions, attestationResponse, error_1, _a, embeddedWalletAddress, ciphertext, iv, signerAddress, signature, verificationResponse;
|
|
50
|
-
return __generator(this, function (_b) {
|
|
51
|
-
switch (_b.label) {
|
|
52
|
-
case 0: return [4 /*yield*/, axios_1.default.get("".concat(baseUrl, "/api/auth/generate-registration-options"))];
|
|
53
|
-
case 1:
|
|
54
|
-
registrationOptions = _b.sent();
|
|
55
|
-
_b.label = 2;
|
|
56
|
-
case 2:
|
|
57
|
-
_b.trys.push([2, 4, , 5]);
|
|
58
|
-
return [4 /*yield*/, (0, browser_1.startRegistration)(registrationOptions.data)];
|
|
59
|
-
case 3:
|
|
60
|
-
// Pass the options to the authenticator and wait for a response
|
|
61
|
-
attestationResponse = _b.sent();
|
|
62
|
-
return [3 /*break*/, 5];
|
|
63
|
-
case 4:
|
|
64
|
-
error_1 = _b.sent();
|
|
65
|
-
// if InvalidStateError -> Authenticator was probably already registered by user
|
|
66
|
-
console.error(error_1);
|
|
67
|
-
throw new Error('Failed to register');
|
|
68
|
-
case 5: return [4 /*yield*/, (0, embeddedWalletHelpers_1.generateEmbeddedWallet)(attestationResponse)];
|
|
69
|
-
case 6:
|
|
70
|
-
_a = _b.sent(), embeddedWalletAddress = _a.embeddedWalletAddress, ciphertext = _a.ciphertext, iv = _a.iv;
|
|
71
|
-
return [4 /*yield*/, signer.getAddress()];
|
|
72
|
-
case 7:
|
|
73
|
-
signerAddress = _b.sent();
|
|
74
|
-
return [4 /*yield*/, (0, common_1.signRegisterEmbeddedWallet)(signer, embeddedWalletAddress)];
|
|
75
|
-
case 8:
|
|
76
|
-
signature = _b.sent();
|
|
77
|
-
return [4 /*yield*/, axios_1.default.post("".concat(baseUrl, "/api/auth/verify-registration"), {
|
|
78
|
-
registrationResponse: JSON.stringify(attestationResponse),
|
|
79
|
-
accountId: accountId,
|
|
80
|
-
signature: signature,
|
|
81
|
-
embeddedWalletAddress: embeddedWalletAddress,
|
|
82
|
-
embeddedWalletPrivateKeyCypherText: ciphertext,
|
|
83
|
-
embeddedWalletPrivateKeyIv: iv,
|
|
84
|
-
mainWalletAddress: signerAddress,
|
|
85
|
-
})];
|
|
86
|
-
case 9:
|
|
87
|
-
verificationResponse = _b.sent();
|
|
88
|
-
return [4 /*yield*/, verificationResponse.data];
|
|
89
|
-
case 10: return [2 /*return*/, _b.sent()];
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
}); };
|
|
93
|
-
exports.register = register;
|
|
94
|
-
//# sourceMappingURL=register.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"register.js","sourceRoot":"/","sources":["services/auth/register.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAA4D;AAC5D,iEAAiE;AACjE,gDAA0B;AAG1B,0CAA6D;AAE7D,sEAAsE;AAC/D,IAAM,QAAQ,GAAG,UACtB,OAAe,EACf,MAA8B,EAC9B,WAAwB,EACxB,SAAiB;;;;oBAIW,qBAAM,eAAK,CAAC,GAAG,CACzC,UAAG,OAAO,4CAAyC,CACpD,EAAA;;gBAFK,mBAAmB,GAAG,SAE3B;;;;gBAIuB,qBAAM,IAAA,2BAAiB,EAAC,mBAAmB,CAAC,IAAI,CAAC,EAAA;;gBADvE,gEAAgE;gBAChE,mBAAmB,GAAG,SAAiD,CAAC;;;;gBAExE,gFAAgF;gBAChF,OAAO,CAAC,KAAK,CAAC,OAAK,CAAC,CAAC;gBACrB,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;oBAItC,qBAAM,IAAA,8CAAsB,EAAC,mBAAmB,CAAC,EAAA;;gBAD7C,KACJ,SAAiD,EAD3C,qBAAqB,2BAAA,EAAE,UAAU,gBAAA,EAAE,EAAE,QAAA;gBAEvB,qBAAM,MAAM,CAAC,UAAU,EAAE,EAAA;;gBAAzC,aAAa,GAAG,SAAyB;gBAC7B,qBAAM,IAAA,mCAA0B,EAChD,MAAM,EACN,qBAAqB,CACtB,EAAA;;gBAHK,SAAS,GAAG,SAGjB;gBAE4B,qBAAM,eAAK,CAAC,IAAI,CAC3C,UAAG,OAAO,kCAA+B,EACzC;wBACE,oBAAoB,EAAE,IAAI,CAAC,SAAS,CAAC,mBAAmB,CAAC;wBACzD,SAAS,EAAE,SAAS;wBACpB,SAAS,EAAE,SAAS;wBACpB,qBAAqB,EAAE,qBAAqB;wBAC5C,kCAAkC,EAAE,UAAU;wBAC9C,0BAA0B,EAAE,EAAE;wBAC9B,iBAAiB,EAAE,aAAa;qBACjC,CACF,EAAA;;gBAXK,oBAAoB,GAAG,SAW5B;gBACM,qBAAM,oBAAoB,CAAC,IAAI,EAAA;qBAAtC,sBAAO,SAA+B,EAAC;;;KACxC,CAAC;AA1CW,QAAA,QAAQ,YA0CnB","sourcesContent":["import { startRegistration } from '@simplewebauthn/browser';\nimport { generateEmbeddedWallet } from './embeddedWalletHelpers';\nimport axios from 'axios';\nimport { JsonRpcSigner, Signer } from 'ethers';\nimport { ReyaChainId } from '@reyaxyz/common';\nimport { signRegisterEmbeddedWallet } from '@reyaxyz/common';\n\n// todo: p2: clean up function inputs (e.g. baseUrl) / introduce types\nexport const register = async (\n baseUrl: string,\n signer: Signer | JsonRpcSigner,\n reyaChainId: ReyaChainId,\n accountId: number,\n) => {\n // GET registration options from the endpoint that calls\n // @simplewebauthn/server -> generateRegistrationOptions()\n const registrationOptions = await axios.get(\n `${baseUrl}/api/auth/generate-registration-options`,\n );\n let attestationResponse;\n try {\n // Pass the options to the authenticator and wait for a response\n attestationResponse = await startRegistration(registrationOptions.data);\n } catch (error) {\n // if InvalidStateError -> Authenticator was probably already registered by user\n console.error(error);\n throw new Error('Failed to register');\n }\n\n const { embeddedWalletAddress, ciphertext, iv } =\n await generateEmbeddedWallet(attestationResponse);\n const signerAddress = await signer.getAddress();\n const signature = await signRegisterEmbeddedWallet(\n signer,\n embeddedWalletAddress,\n );\n\n const verificationResponse = await axios.post(\n `${baseUrl}/api/auth/verify-registration`,\n {\n registrationResponse: JSON.stringify(attestationResponse),\n accountId: accountId,\n signature: signature,\n embeddedWalletAddress: embeddedWalletAddress,\n embeddedWalletPrivateKeyCypherText: ciphertext,\n embeddedWalletPrivateKeyIv: iv,\n mainWalletAddress: signerAddress,\n },\n );\n return await verificationResponse.data;\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authenticate.d.ts","sourceRoot":"/","sources":["services/auth/authenticate.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY,YAAmB,MAAM,iBAkBjD,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=checkSupport.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"checkSupport.d.ts","sourceRoot":"/","sources":["services/auth/checkSupport.ts"],"names":[],"mappings":""}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { RegistrationResponseJSON } from '@simplewebauthn/types';
|
|
2
|
-
export declare const generateEmbeddedWallet: (attestationResponse: RegistrationResponseJSON) => Promise<{
|
|
3
|
-
embeddedWalletAddress: string;
|
|
4
|
-
ciphertext: ArrayBuffer;
|
|
5
|
-
iv: Uint8Array;
|
|
6
|
-
}>;
|
|
7
|
-
//# sourceMappingURL=embeddedWalletHelpers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"embeddedWalletHelpers.d.ts","sourceRoot":"/","sources":["services/auth/embeddedWalletHelpers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEtE,eAAO,MAAM,sBAAsB,wBACZ,wBAAwB;;;;EAgB9C,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["services/auth/index.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { JsonRpcSigner, Signer } from 'ethers';
|
|
2
|
-
import { ReyaChainId } from '@reyaxyz/common';
|
|
3
|
-
export declare const register: (baseUrl: string, signer: Signer | JsonRpcSigner, reyaChainId: ReyaChainId, accountId: number) => Promise<any>;
|
|
4
|
-
//# sourceMappingURL=register.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"register.d.ts","sourceRoot":"/","sources":["services/auth/register.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAI9C,eAAO,MAAM,QAAQ,YACV,MAAM,UACP,MAAM,GAAG,aAAa,eACjB,WAAW,aACb,MAAM,iBAsClB,CAAC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import { startAuthentication } from '@simplewebauthn/browser';
|
|
3
|
-
|
|
4
|
-
export const authenticate = async (baseUrl: string) => {
|
|
5
|
-
const authenticationOptions = await axios.get(
|
|
6
|
-
`${baseUrl}/api/auth/generate-authentication-options`,
|
|
7
|
-
);
|
|
8
|
-
let attestationResponse;
|
|
9
|
-
try {
|
|
10
|
-
// Pass the options to the authenticator and wait for a response
|
|
11
|
-
attestationResponse = await startAuthentication(authenticationOptions.data);
|
|
12
|
-
} catch (error) {
|
|
13
|
-
console.error(error);
|
|
14
|
-
throw new Error('Failed to authenticate');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const verificationResponse = await axios.post(
|
|
18
|
-
`${baseUrl}/api/auth/verify-authentication`,
|
|
19
|
-
JSON.stringify(attestationResponse),
|
|
20
|
-
);
|
|
21
|
-
return await verificationResponse.data;
|
|
22
|
-
};
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { ethers } from 'ethers';
|
|
2
|
-
import { subtle } from 'crypto';
|
|
3
|
-
import type { RegistrationResponseJSON } from '@simplewebauthn/types';
|
|
4
|
-
|
|
5
|
-
export const generateEmbeddedWallet = async (
|
|
6
|
-
attestationResponse: RegistrationResponseJSON,
|
|
7
|
-
) => {
|
|
8
|
-
const embeddedWallet = ethers.Wallet.createRandom();
|
|
9
|
-
|
|
10
|
-
const encryptionKey = await deriveEncryptionKey(attestationResponse);
|
|
11
|
-
|
|
12
|
-
const { ciphertext, iv } = await encryptPrivateKey(
|
|
13
|
-
embeddedWallet.privateKey,
|
|
14
|
-
encryptionKey,
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
return {
|
|
18
|
-
embeddedWalletAddress: embeddedWallet.address,
|
|
19
|
-
ciphertext: ciphertext,
|
|
20
|
-
iv: iv,
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const deriveEncryptionKey = async (
|
|
25
|
-
publicKeyCredential: RegistrationResponseJSON,
|
|
26
|
-
) => {
|
|
27
|
-
// Convert rawId to Uint8Array if it is not already
|
|
28
|
-
const rawIdBuffer = new TextEncoder().encode(publicKeyCredential.rawId);
|
|
29
|
-
|
|
30
|
-
const keyMaterial = await subtle.importKey(
|
|
31
|
-
'raw',
|
|
32
|
-
rawIdBuffer,
|
|
33
|
-
{ name: 'HKDF' },
|
|
34
|
-
false,
|
|
35
|
-
['deriveKey'],
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
return await subtle.deriveKey(
|
|
39
|
-
{
|
|
40
|
-
name: 'HKDF',
|
|
41
|
-
hash: 'SHA-256',
|
|
42
|
-
salt: new Uint8Array(16), // Use a consistent salt
|
|
43
|
-
info: new TextEncoder().encode('encryption key'),
|
|
44
|
-
},
|
|
45
|
-
keyMaterial,
|
|
46
|
-
{ name: 'AES-GCM', length: 256 },
|
|
47
|
-
false,
|
|
48
|
-
['encrypt', 'decrypt'],
|
|
49
|
-
);
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const encryptPrivateKey = async (
|
|
53
|
-
embeddedWalletPrivateKey: string,
|
|
54
|
-
encryptionKey: CryptoKey,
|
|
55
|
-
) => {
|
|
56
|
-
const iv = crypto.getRandomValues(new Uint8Array(12)); // 12 bytes IV for AES-GCM
|
|
57
|
-
const encrypted = await subtle.encrypt(
|
|
58
|
-
{
|
|
59
|
-
name: 'AES-GCM',
|
|
60
|
-
iv: iv,
|
|
61
|
-
},
|
|
62
|
-
encryptionKey,
|
|
63
|
-
new TextEncoder().encode(embeddedWalletPrivateKey),
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
ciphertext: encrypted,
|
|
68
|
-
iv: iv,
|
|
69
|
-
};
|
|
70
|
-
};
|
|
File without changes
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { startRegistration } from '@simplewebauthn/browser';
|
|
2
|
-
import { generateEmbeddedWallet } from './embeddedWalletHelpers';
|
|
3
|
-
import axios from 'axios';
|
|
4
|
-
import { JsonRpcSigner, Signer } from 'ethers';
|
|
5
|
-
import { ReyaChainId } from '@reyaxyz/common';
|
|
6
|
-
import { signRegisterEmbeddedWallet } from '@reyaxyz/common';
|
|
7
|
-
|
|
8
|
-
// todo: p2: clean up function inputs (e.g. baseUrl) / introduce types
|
|
9
|
-
export const register = async (
|
|
10
|
-
baseUrl: string,
|
|
11
|
-
signer: Signer | JsonRpcSigner,
|
|
12
|
-
reyaChainId: ReyaChainId,
|
|
13
|
-
accountId: number,
|
|
14
|
-
) => {
|
|
15
|
-
// GET registration options from the endpoint that calls
|
|
16
|
-
// @simplewebauthn/server -> generateRegistrationOptions()
|
|
17
|
-
const registrationOptions = await axios.get(
|
|
18
|
-
`${baseUrl}/api/auth/generate-registration-options`,
|
|
19
|
-
);
|
|
20
|
-
let attestationResponse;
|
|
21
|
-
try {
|
|
22
|
-
// Pass the options to the authenticator and wait for a response
|
|
23
|
-
attestationResponse = await startRegistration(registrationOptions.data);
|
|
24
|
-
} catch (error) {
|
|
25
|
-
// if InvalidStateError -> Authenticator was probably already registered by user
|
|
26
|
-
console.error(error);
|
|
27
|
-
throw new Error('Failed to register');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const { embeddedWalletAddress, ciphertext, iv } =
|
|
31
|
-
await generateEmbeddedWallet(attestationResponse);
|
|
32
|
-
const signerAddress = await signer.getAddress();
|
|
33
|
-
const signature = await signRegisterEmbeddedWallet(
|
|
34
|
-
signer,
|
|
35
|
-
embeddedWalletAddress,
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
const verificationResponse = await axios.post(
|
|
39
|
-
`${baseUrl}/api/auth/verify-registration`,
|
|
40
|
-
{
|
|
41
|
-
registrationResponse: JSON.stringify(attestationResponse),
|
|
42
|
-
accountId: accountId,
|
|
43
|
-
signature: signature,
|
|
44
|
-
embeddedWalletAddress: embeddedWalletAddress,
|
|
45
|
-
embeddedWalletPrivateKeyCypherText: ciphertext,
|
|
46
|
-
embeddedWalletPrivateKeyIv: iv,
|
|
47
|
-
mainWalletAddress: signerAddress,
|
|
48
|
-
},
|
|
49
|
-
);
|
|
50
|
-
return await verificationResponse.data;
|
|
51
|
-
};
|