@reclaimprotocol/client 0.1.11 → 0.1.13

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.
@@ -12,9 +12,9 @@
12
12
  */
13
13
  import { keccak_256 } from '@noble/hashes/sha3.js';
14
14
  import { createSignDataForClaim } from '@reclaimprotocol/attestor-core';
15
+ import { eip191Digest } from "./eip191.js";
15
16
  import { base64urlToBytes, bytesToHex } from "./encoding.js";
16
17
  import { secp } from "./secp.js";
17
- const ENC = new TextEncoder();
18
18
  function decodeJson(b64url) {
19
19
  return JSON.parse(new TextDecoder().decode(base64urlToBytes(b64url)));
20
20
  }
@@ -38,18 +38,6 @@ function createSignData(claim) {
38
38
  epoch: Number(claim.epoch ?? 0),
39
39
  });
40
40
  }
41
- /** Standard EIP-191 / personal_sign digest: keccak256 of
42
- * `0x19 ‖ "Ethereum Signed Message:\n" ‖ len ‖ data`. */
43
- function eip191Digest(data) {
44
- const bytes = ENC.encode(data);
45
- const prefix = ENC.encode('\x19Ethereum Signed Message:\n');
46
- const len = ENC.encode(String(bytes.length));
47
- const merged = new Uint8Array(prefix.length + len.length + bytes.length);
48
- merged.set(prefix, 0);
49
- merged.set(len, prefix.length);
50
- merged.set(bytes, prefix.length + len.length);
51
- return keccak_256(merged);
52
- }
53
41
  /** Recover the lowercase ETH address from a 65-byte r‖s‖v signature. */
54
42
  function recoverEthAddress(digest, sig) {
55
43
  const v = sig[64];
@@ -0,0 +1,9 @@
1
+ /** Standard EIP-191 / personal_sign digest: keccak256 of
2
+ * `0x19 ‖ "Ethereum Signed Message:\n" ‖ len ‖ data`. */
3
+ export declare function eip191Digest(data: string): Uint8Array;
4
+ /** EIP-191 personal_sign over `message` with a raw 0x-hex eth private key.
5
+ * Returns the standard 65-byte `r ‖ s ‖ v` hex signature that
6
+ * `ethers.verifyMessage(message, signature)` accepts — noble's `'recovered'`
7
+ * format prepends the recovery byte instead, so it's reordered to the end
8
+ * here (a raw `0`/`1` recovery byte is fine there, no `+27` needed). */
9
+ export declare function signEip191(message: string, privateKeyHex: string): string;
package/lib/eip191.js ADDED
@@ -0,0 +1,38 @@
1
+ /**
2
+ * EIP-191 / `personal_sign` primitives shared by the verification paths
3
+ * (attestor-proof recovery) and by callers that need to *produce* a
4
+ * personal_sign signature with a raw eth key (e.g. the old-devtools
5
+ * link-app flow) — without pulling in a full wallet library.
6
+ */
7
+ import { keccak_256 } from '@noble/hashes/sha3.js';
8
+ import { bytesToHex, hexToBytes } from "./encoding.js";
9
+ import { secp } from "./secp.js";
10
+ const ENC = new TextEncoder();
11
+ /** Standard EIP-191 / personal_sign digest: keccak256 of
12
+ * `0x19 ‖ "Ethereum Signed Message:\n" ‖ len ‖ data`. */
13
+ export function eip191Digest(data) {
14
+ const bytes = ENC.encode(data);
15
+ const prefix = ENC.encode('\x19Ethereum Signed Message:\n');
16
+ const len = ENC.encode(String(bytes.length));
17
+ const merged = new Uint8Array(prefix.length + len.length + bytes.length);
18
+ merged.set(prefix, 0);
19
+ merged.set(len, prefix.length);
20
+ merged.set(bytes, prefix.length + len.length);
21
+ return keccak_256(merged);
22
+ }
23
+ /** EIP-191 personal_sign over `message` with a raw 0x-hex eth private key.
24
+ * Returns the standard 65-byte `r ‖ s ‖ v` hex signature that
25
+ * `ethers.verifyMessage(message, signature)` accepts — noble's `'recovered'`
26
+ * format prepends the recovery byte instead, so it's reordered to the end
27
+ * here (a raw `0`/`1` recovery byte is fine there, no `+27` needed). */
28
+ export function signEip191(message, privateKeyHex) {
29
+ const digest = eip191Digest(message);
30
+ const privateKey = hexToBytes(privateKeyHex);
31
+ const recovered = secp.sign(digest, privateKey, {
32
+ prehash: false,
33
+ format: 'recovered',
34
+ });
35
+ const recovery = recovered[0];
36
+ const rs = recovered.slice(1);
37
+ return '0x' + bytesToHex(rs) + recovery.toString(16).padStart(2, '0');
38
+ }
package/lib/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export { addressFromPublicKey, deriveFromPrivateKey, type EthKeypair, generateKe
7
7
  export { canonicalJson } from './canonical.ts';
8
8
  export { b64url, base64urlToBytes, bytesToHex, hexToBytes, } from './encoding.ts';
9
9
  export { addressFromUncompressedPubkey, secp, } from './secp.ts';
10
+ export { eip191Digest, signEip191 } from './eip191.ts';
10
11
  export { type CallbackBody, decodeJwsPayload, decryptCallback, type DeliveryEnvelope, encryptForEthPublicKey, type Jws, ResultVerificationError, type ResultProofOutcome, signResultJws, verifyJwsSignature, verifyResult, verifyResultFull, type VerifyResultFullOptions, type VerifyResultFullOutcome, type VerifyResultOptions, type VerifyResultOutcome, } from './result.ts';
11
12
  export { type DecryptionKey, type DecryptionKeyInput, generateEthKeypair, type GeneratedEthKeypair, loadDecryptionKey, pubkeyJwkToEthAddress, uncompressedPubkeyToJwk, } from './enckeys.ts';
12
13
  export { createReclaim, type CreateSessionInput, type Reclaim, type ReclaimConfig, type ReceiveOptions, type ReceivedDelivery, type RegisterCallbackInput, type SetKeypairInput, TERMINAL_EVENTS, } from './reclaim.ts';
package/lib/index.js CHANGED
@@ -5,6 +5,7 @@ export { addressFromPublicKey, deriveFromPrivateKey, generateKeypair, } from "./
5
5
  export { canonicalJson } from "./canonical.js";
6
6
  export { b64url, base64urlToBytes, bytesToHex, hexToBytes, } from "./encoding.js";
7
7
  export { addressFromUncompressedPubkey, secp, } from "./secp.js";
8
+ export { eip191Digest, signEip191 } from "./eip191.js";
8
9
  export { decodeJwsPayload, decryptCallback, encryptForEthPublicKey, ResultVerificationError, signResultJws, verifyJwsSignature, verifyResult, verifyResultFull, } from "./result.js";
9
10
  export { generateEthKeypair, loadDecryptionKey, pubkeyJwkToEthAddress, uncompressedPubkeyToJwk, } from "./enckeys.js";
10
11
  export { createReclaim, TERMINAL_EVENTS, } from "./reclaim.js";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@reclaimprotocol/client",
3
3
  "title": "Reclaim Client",
4
- "version": "0.1.11",
4
+ "version": "0.1.13",
5
5
  "description": "Typed SDK/HTTP client SDK for the Reclaim Protocol — the programmatic way to use Reclaim Protocol to verify **data points** about your users (a follower count, an account balance, an order). Can be directly integrated by apps to request verification for their users using Reclaim Protocol and verify the results.",
6
6
  "type": "module",
7
7
  "sideEffects": false,
@@ -12,11 +12,10 @@
12
12
  */
13
13
  import { keccak_256 } from '@noble/hashes/sha3.js'
14
14
  import { createSignDataForClaim } from '@reclaimprotocol/attestor-core'
15
+ import { eip191Digest } from './eip191.ts'
15
16
  import { base64urlToBytes, bytesToHex } from './encoding.ts'
16
17
  import { secp } from './secp.ts'
17
18
 
18
- const ENC = new TextEncoder()
19
-
20
19
  function decodeJson(b64url: string): Record<string, unknown> {
21
20
  return JSON.parse(new TextDecoder().decode(base64urlToBytes(b64url)))
22
21
  }
@@ -42,19 +41,6 @@ function createSignData(claim: Record<string, unknown>): string {
42
41
  })
43
42
  }
44
43
 
45
- /** Standard EIP-191 / personal_sign digest: keccak256 of
46
- * `0x19 ‖ "Ethereum Signed Message:\n" ‖ len ‖ data`. */
47
- function eip191Digest(data: string): Uint8Array {
48
- const bytes = ENC.encode(data)
49
- const prefix = ENC.encode('\x19Ethereum Signed Message:\n')
50
- const len = ENC.encode(String(bytes.length))
51
- const merged = new Uint8Array(prefix.length + len.length + bytes.length)
52
- merged.set(prefix, 0)
53
- merged.set(len, prefix.length)
54
- merged.set(bytes, prefix.length + len.length)
55
- return keccak_256(merged)
56
- }
57
-
58
44
  /** Recover the lowercase ETH address from a 65-byte r‖s‖v signature. */
59
45
  function recoverEthAddress(digest: Uint8Array, sig: Uint8Array): string {
60
46
  const v = sig[64]
package/src/eip191.ts ADDED
@@ -0,0 +1,41 @@
1
+ /**
2
+ * EIP-191 / `personal_sign` primitives shared by the verification paths
3
+ * (attestor-proof recovery) and by callers that need to *produce* a
4
+ * personal_sign signature with a raw eth key (e.g. the old-devtools
5
+ * link-app flow) — without pulling in a full wallet library.
6
+ */
7
+ import { keccak_256 } from '@noble/hashes/sha3.js'
8
+ import { bytesToHex, hexToBytes } from './encoding.ts'
9
+ import { secp } from './secp.ts'
10
+
11
+ const ENC = new TextEncoder()
12
+
13
+ /** Standard EIP-191 / personal_sign digest: keccak256 of
14
+ * `0x19 ‖ "Ethereum Signed Message:\n" ‖ len ‖ data`. */
15
+ export function eip191Digest(data: string): Uint8Array {
16
+ const bytes = ENC.encode(data)
17
+ const prefix = ENC.encode('\x19Ethereum Signed Message:\n')
18
+ const len = ENC.encode(String(bytes.length))
19
+ const merged = new Uint8Array(prefix.length + len.length + bytes.length)
20
+ merged.set(prefix, 0)
21
+ merged.set(len, prefix.length)
22
+ merged.set(bytes, prefix.length + len.length)
23
+ return keccak_256(merged)
24
+ }
25
+
26
+ /** EIP-191 personal_sign over `message` with a raw 0x-hex eth private key.
27
+ * Returns the standard 65-byte `r ‖ s ‖ v` hex signature that
28
+ * `ethers.verifyMessage(message, signature)` accepts — noble's `'recovered'`
29
+ * format prepends the recovery byte instead, so it's reordered to the end
30
+ * here (a raw `0`/`1` recovery byte is fine there, no `+27` needed). */
31
+ export function signEip191(message: string, privateKeyHex: string): string {
32
+ const digest = eip191Digest(message)
33
+ const privateKey = hexToBytes(privateKeyHex)
34
+ const recovered = secp.sign(digest, privateKey, {
35
+ prehash: false,
36
+ format: 'recovered',
37
+ }) as Uint8Array
38
+ const recovery = recovered[0]
39
+ const rs = recovered.slice(1)
40
+ return '0x' + bytesToHex(rs) + recovery.toString(16).padStart(2, '0')
41
+ }
package/src/index.ts CHANGED
@@ -20,6 +20,7 @@ export {
20
20
  addressFromUncompressedPubkey,
21
21
  secp,
22
22
  } from './secp.ts'
23
+ export { eip191Digest, signEip191 } from './eip191.ts'
23
24
  export {
24
25
  type CallbackBody,
25
26
  decodeJwsPayload,
@@ -7,8 +7,8 @@ export type RequestBodyContent<T> = T extends {
7
7
  }
8
8
  ? R
9
9
  : T extends { content: { 'application/x-www-form-urlencoded': infer R } }
10
- ? R
11
- : undefined
10
+ ? R
11
+ : undefined
12
12
 
13
13
  export type IJsonRequestBody<T extends IOperationId> = operations[T] extends {
14
14
  requestBody?: infer B
@@ -21,10 +21,10 @@ type AnySuccess<R> = R extends {
21
21
  }
22
22
  ? J
23
23
  : R extends { 201: { content: { 'application/json': infer J } } }
24
- ? J
25
- : R extends { 204: unknown }
26
- ? void
27
- : unknown
24
+ ? J
25
+ : R extends { 204: unknown }
26
+ ? void
27
+ : unknown
28
28
 
29
29
  export type IJsonResponseBody<T extends IOperationId> = operations[T] extends {
30
30
  responses: infer R
@@ -66,8 +66,8 @@ export type IOperationArgs<T extends IOperationId> = {
66
66
  [IQuery<T>] extends [undefined] ? unknown : { query: IQuery<T> }
67
67
  ) & (
68
68
  [IJsonRequestBody<T>] extends [undefined]
69
- ? unknown
70
- : { body: IJsonRequestBody<T> }
69
+ ? unknown
70
+ : { body: IJsonRequestBody<T> }
71
71
  ) & (
72
72
  [IHeaders<T>] extends [undefined] ? unknown : { headers: IHeaders<T> }
73
73
  )