@unchainedshop/api 3.1.0 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/resolvers/mutations/accounts/verifyWeb3Address.d.ts +1 -1
- package/lib/resolvers/mutations/accounts/verifyWeb3Address.d.ts.map +1 -1
- package/lib/resolvers/mutations/accounts/verifyWeb3Address.js +9 -8
- package/lib/resolvers/mutations/accounts/verifyWeb3Address.js.map +1 -1
- package/package.json +5 -5
- package/src/resolvers/mutations/accounts/verifyWeb3Address.ts +13 -10
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Context } from '../../../context.js';
|
|
2
2
|
export default function verifyWeb3Address(root: never, { address, hash }: {
|
|
3
3
|
address: string;
|
|
4
|
-
hash: string
|
|
4
|
+
hash: `0x${string}`;
|
|
5
5
|
}, { modules, userId, user }: Context): Promise<import("@unchainedshop/core-users").User>;
|
|
6
6
|
//# sourceMappingURL=verifyWeb3Address.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verifyWeb3Address.d.ts","sourceRoot":"","sources":["../../../../src/resolvers/mutations/accounts/verifyWeb3Address.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,wBAA8B,iBAAiB,CAC7C,IAAI,EAAE,KAAK,EACX,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"verifyWeb3Address.d.ts","sourceRoot":"","sources":["../../../../src/resolvers/mutations/accounts/verifyWeb3Address.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,wBAA8B,iBAAiB,CAC7C,IAAI,EAAE,KAAK,EACX,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,KAAK,MAAM,EAAE,CAAA;CAAE,EAC3D,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,OAAO,qDAwDnC"}
|
|
@@ -8,16 +8,17 @@ export default async function verifyWeb3Address(root, { address, hash }, { modul
|
|
|
8
8
|
if (!foundCredentials) {
|
|
9
9
|
throw new UserWeb3AddressNotFoundError({ userId, address });
|
|
10
10
|
}
|
|
11
|
-
const msg = `0x${Buffer.from(foundCredentials.nonce, 'utf8').toString('hex')}`;
|
|
12
11
|
// eslint-disable-next-line
|
|
13
12
|
// @ts-ignore
|
|
14
|
-
const {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
13
|
+
const { bufferToHex, fromRpcSig, ecrecover, toBuffer, hashPersonalMessage, publicToAddress } = await import('@ethereumjs/util');
|
|
14
|
+
const message = `0x${Buffer.from(foundCredentials.nonce, 'utf8').toString('hex')}`;
|
|
15
|
+
const messageHash = hashPersonalMessage(toBuffer(message));
|
|
16
|
+
const sigParams = fromRpcSig(hash);
|
|
17
|
+
const publicKey = ecrecover(messageHash, sigParams.v, sigParams.r, sigParams.s);
|
|
18
|
+
const sender = publicToAddress(publicKey);
|
|
19
|
+
const recoveredAddr = bufferToHex(sender);
|
|
20
|
+
const isSignatureCorrectForAddress = recoveredAddr.toLowerCase() === foundCredentials.address.toLowerCase();
|
|
21
|
+
if (!isSignatureCorrectForAddress) {
|
|
21
22
|
throw new UserWeb3AddressSignatureError({ userId, address: foundCredentials.address });
|
|
22
23
|
}
|
|
23
24
|
const web3Services = user.services.web3.map((service) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verifyWeb3Address.js","sourceRoot":"","sources":["../../../../src/resolvers/mutations/accounts/verifyWeb3Address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAC;AAC5C,OAAO,EAAE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
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"main": "lib/api-index.js",
|
|
5
5
|
"types": "lib/api-index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
},
|
|
32
32
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
33
33
|
"peerDependencies": {
|
|
34
|
+
"@ethereumjs/util": ">= 8 < 10",
|
|
34
35
|
"@fastify/cookie": ">= 11.0 < 12",
|
|
35
36
|
"@fastify/session": ">= 11.0 < 12",
|
|
36
|
-
"@metamask/eth-sig-util": ">= 8.1 < 9",
|
|
37
37
|
"connect-mongo": ">= 5.1.0 < 6",
|
|
38
38
|
"express": ">= 5.0 < 6",
|
|
39
39
|
"express-session": ">= 1.18 < 2",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"connect-mongo": {
|
|
49
49
|
"optional": false
|
|
50
50
|
},
|
|
51
|
-
"@
|
|
51
|
+
"@ethereumjs/util": {
|
|
52
52
|
"optional": true
|
|
53
53
|
},
|
|
54
54
|
"@fastify/cookie": {
|
|
@@ -84,11 +84,11 @@
|
|
|
84
84
|
"p-memoize": "^7.1.1"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
|
+
"@ethereumjs/util": "^9.1.0",
|
|
87
88
|
"@fastify/cookie": "^11.0.2",
|
|
88
89
|
"@fastify/session": "^11.1.0",
|
|
89
|
-
"@metamask/eth-sig-util": "^8.2.0",
|
|
90
90
|
"@types/express": "^5.0.0",
|
|
91
|
-
"@types/node": "^22.13.
|
|
91
|
+
"@types/node": "^22.13.4",
|
|
92
92
|
"express": "^5.0.1",
|
|
93
93
|
"express-session": "^1.18.1",
|
|
94
94
|
"fastify": "^5.2.1",
|
|
@@ -4,7 +4,7 @@ import { Context } from '../../../context.js';
|
|
|
4
4
|
|
|
5
5
|
export default async function verifyWeb3Address(
|
|
6
6
|
root: never,
|
|
7
|
-
{ address, hash }: { address: string; hash: string },
|
|
7
|
+
{ address, hash }: { address: string; hash: `0x${string}` },
|
|
8
8
|
{ modules, userId, user }: Context,
|
|
9
9
|
) {
|
|
10
10
|
log(`mutation verifyWeb3Address ${address} ${user.username}`, {
|
|
@@ -18,21 +18,24 @@ export default async function verifyWeb3Address(
|
|
|
18
18
|
throw new UserWeb3AddressNotFoundError({ userId, address });
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
const msg = `0x${Buffer.from(foundCredentials.nonce, 'utf8').toString('hex')}`;
|
|
22
|
-
|
|
23
21
|
// eslint-disable-next-line
|
|
24
22
|
// @ts-ignore
|
|
25
|
-
const {
|
|
23
|
+
const { bufferToHex, fromRpcSig, ecrecover, toBuffer, hashPersonalMessage, publicToAddress } =
|
|
24
|
+
await import('@ethereumjs/util');
|
|
26
25
|
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
const message = `0x${Buffer.from(foundCredentials.nonce, 'utf8').toString('hex')}`;
|
|
27
|
+
const messageHash = hashPersonalMessage(toBuffer(message));
|
|
28
|
+
|
|
29
|
+
const sigParams = fromRpcSig(hash);
|
|
30
|
+
const publicKey = ecrecover(messageHash, sigParams.v, sigParams.r, sigParams.s);
|
|
31
|
+
|
|
32
|
+
const sender = publicToAddress(publicKey);
|
|
33
|
+
const recoveredAddr = bufferToHex(sender);
|
|
31
34
|
|
|
32
|
-
const
|
|
35
|
+
const isSignatureCorrectForAddress =
|
|
33
36
|
recoveredAddr.toLowerCase() === foundCredentials.address.toLowerCase();
|
|
34
37
|
|
|
35
|
-
if (!
|
|
38
|
+
if (!isSignatureCorrectForAddress) {
|
|
36
39
|
throw new UserWeb3AddressSignatureError({ userId, address: foundCredentials.address });
|
|
37
40
|
}
|
|
38
41
|
|