@bitsocial/bitsocial-react-hooks 0.3.6 → 0.4.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 CHANGED
@@ -1,3 +1,17 @@
1
+ # [0.4.0](https://github.com/bitsocialnet/bitsocial-react-hooks/compare/v0.3.6...v0.4.0) (2026-11-25)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **accounts:** sign and verify author wallet proofs as BSIP-22 defines them, and prepare 0.4.0 ([#202](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/202)) ([84786f3](https://github.com/bitsocialnet/bitsocial-react-hooks/commit/84786f3fcee44c11be6f422c90b6fcd299909491)), closes [#186](https://github.com/bitsocialnet/bitsocial-react-hooks/issues/186)
7
+
8
+
9
+ ### BREAKING CHANGES
10
+
11
+ * **accounts:** validateEthWallet(wallet, authorPublicKey) takes the key address of the account's signing key (account.signer.address, 12D3KooW...) instead of author.address, and rejects a proof in the old format. To sign an external wallet in, have it sign getWalletMessageToSign(account.signer.address, walletAddress, timestamp) from @bitsocial/bitsocial-react-hooks/author-wallet-proof. An account signed in to an external wallet with an old-format proof is signed out of it when it loads and has to sign again.
12
+
13
+
14
+
1
15
  ## [0.3.6](https://github.com/bitsocialnet/bitsocial-react-hooks/compare/v0.3.5...v0.3.6) (2026-11-24)
2
16
 
3
17
 
package/dist/index.d.ts CHANGED
@@ -69,7 +69,7 @@ declare const hooks: {
69
69
  useClientsStates: typeof useClientsStates;
70
70
  useCommunitiesStates: typeof useCommunitiesStates;
71
71
  usePkcRpcSettings: typeof usePkcRpcSettings;
72
- getEthWalletFromPkcPrivateKey: (privateKeyBase64: string, authorAddress: string) => Promise<{
72
+ getEthWalletFromPkcPrivateKey: (privateKeyBase64: string, _authorAddress?: string) => Promise<{
73
73
  address: string;
74
74
  timestamp: number;
75
75
  signature: {
@@ -77,8 +77,8 @@ declare const hooks: {
77
77
  type: string;
78
78
  };
79
79
  } | undefined>;
80
- getEthPrivateKeyFromPkcPrivateKey: (privateKeyBase64: string, authorAddress: string) => Promise<string | undefined>;
81
- validateEthWallet: (wallet: import("./types.js").Wallet, authorAddress: string) => Promise<void>;
80
+ getEthPrivateKeyFromPkcPrivateKey: (privateKeyBase64: string, authorAddress?: string) => Promise<string | undefined>;
81
+ validateEthWallet: (wallet: import("./types.js").Wallet, authorPublicKey: string) => Promise<void>;
82
82
  setPkcJs: typeof setPkcJs;
83
83
  restorePkcJs: typeof restorePkcJs;
84
84
  deleteDatabases: () => Promise<void>;
@@ -0,0 +1,28 @@
1
+ export type AuthorWalletOutcome = {
2
+ outcome: "valid";
3
+ } | {
4
+ outcome: "unknown";
5
+ } | {
6
+ outcome: "invalid";
7
+ reason: string;
8
+ };
9
+ export declare const AUTHOR_WALLET_PROOF_CLOCK_ALLOWANCE_SECONDS = 300;
10
+ /**
11
+ * The exact string the wallet signs. Built by concatenation because BSIP-22 fixes the field order;
12
+ * it is valid JSON only so wallets can show the user what they sign. `authorPublicKey` is the key
13
+ * address of the author's signing key (12D3KooW...), never the runtime author.address.
14
+ */
15
+ export declare const getWalletMessageToSign: (authorPublicKey: string, walletAddress: string, timestamp: number) => string;
16
+ /**
17
+ * Verify one `author.wallets` entry. `authorPublicKey` is the key address (12D3KooW...) of the
18
+ * signing key of the publication or list carrying the entry; the proof counts only if that record's
19
+ * own signature is valid too. Rely on an entry (show it as the author's wallet, count holdings,
20
+ * send funds) only when the outcome is valid. An unknown entry uses a signature type this check
21
+ * doesn't implement: it is unproven, and communities don't reject publications over it.
22
+ */
23
+ export declare const verifyAuthorWallet: (wallet: unknown, authorPublicKey: string, options?: {
24
+ nowSeconds?: number;
25
+ }) => AuthorWalletOutcome;
26
+ /** The key address (12D3KooW...) of a PKC private key (base64 ed25519 seed), as pkc-js derives it. */
27
+ export declare const getKeyAddressFromPkcPrivateKey: (privateKeyBase64: string) => string;
28
+ //# sourceMappingURL=author-wallet-proof.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"author-wallet-proof.d.ts","sourceRoot":"","sources":["../../../src/lib/chain/author-wallet-proof.ts"],"names":[],"mappings":"AAcA,MAAM,MAAM,mBAAmB,GAC3B;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,GACpB;IAAE,OAAO,EAAE,SAAS,CAAA;CAAE,GACtB;IAAE,OAAO,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAG3C,eAAO,MAAM,2CAA2C,MAAM,CAAC;AAmB/D;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GACjC,iBAAiB,MAAM,EACvB,eAAe,MAAM,EACrB,WAAW,MAAM,WAIlB,CAAC;AA0BF;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,GAC7B,QAAQ,OAAO,EACf,iBAAiB,MAAM,EACvB,UAAU;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,KAChC,mBAoDF,CAAC;AAEF,sGAAsG;AACtG,eAAO,MAAM,8BAA8B,GAAI,kBAAkB,MAAM,WAQtE,CAAC"}
@@ -0,0 +1,118 @@
1
+ import { ed25519 } from "@noble/curves/ed25519.js";
2
+ import { secp256k1 } from "@noble/curves/secp256k1.js";
3
+ import { keccak_256 } from "@noble/hashes/sha3.js";
4
+ import { bytesToHex, hexToBytes, utf8ToBytes } from "@noble/hashes/utils.js";
5
+ import { toString as uint8ArrayToString } from "uint8arrays/to-string";
6
+ import { getPkcAddressFromPublicKey } from "../pkc-address.js";
7
+ // a proof dated more than five minutes ahead of the verifier's clock is not valid yet
8
+ export const AUTHOR_WALLET_PROOF_CLOCK_ALLOWANCE_SECONDS = 300;
9
+ const DOMAIN_SEPARATOR = "bitsocial-author-wallet";
10
+ const WALLET_ADDRESS_REGEX = /^0x[0-9a-fA-F]{40}$/;
11
+ const SIGNATURE_REGEX = /^0x[0-9a-fA-F]{130}$/;
12
+ // BSIP-10 key address: the base58btc peer id of an ed25519 key
13
+ const KEY_ADDRESS_REGEX = /^12D3KooW[1-9A-HJ-NP-Za-km-z]{44}$/;
14
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
15
+ const assertKeyAddress = (authorPublicKey, functionName) => {
16
+ if (typeof authorPublicKey !== "string" || !KEY_ADDRESS_REGEX.test(authorPublicKey)) {
17
+ throw Error(`${functionName} authorPublicKey '${authorPublicKey}' is not a key address (12D3KooW...): pass the key address of the author's signing key, never author.address or author.name`);
18
+ }
19
+ };
20
+ /**
21
+ * The exact string the wallet signs. Built by concatenation because BSIP-22 fixes the field order;
22
+ * it is valid JSON only so wallets can show the user what they sign. `authorPublicKey` is the key
23
+ * address of the author's signing key (12D3KooW...), never the runtime author.address.
24
+ */
25
+ export const getWalletMessageToSign = (authorPublicKey, walletAddress, timestamp) => {
26
+ assertKeyAddress(authorPublicKey, "getWalletMessageToSign");
27
+ return `{"domainSeparator":"${DOMAIN_SEPARATOR}","authorPublicKey":"${authorPublicKey}","walletAddress":"${walletAddress.toLowerCase()}","timestamp":${timestamp}}`;
28
+ };
29
+ // EIP-191 version 0x45 (personal_sign): keccak256("\x19Ethereum Signed Message:\n" + byteLength + message)
30
+ const hashPersonalMessage = (message) => {
31
+ const messageBytes = utf8ToBytes(message);
32
+ const prefix = utf8ToBytes(`\x19Ethereum Signed Message:\n${messageBytes.length}`);
33
+ const bytes = new Uint8Array(prefix.length + messageBytes.length);
34
+ bytes.set(prefix, 0);
35
+ bytes.set(messageBytes, prefix.length);
36
+ return keccak_256(bytes);
37
+ };
38
+ // the lowercase 0x address that signed `digest`, or undefined when no key recovers
39
+ const recoverAddress = (digest, signatureBytes) => {
40
+ try {
41
+ const signature = secp256k1.Signature.fromBytes(signatureBytes.slice(0, 64), "compact").addRecoveryBit(signatureBytes[64] - 27);
42
+ const publicKey = signature.recoverPublicKey(digest).toBytes(false);
43
+ return `0x${bytesToHex(keccak_256(publicKey.slice(1)).slice(12))}`;
44
+ }
45
+ catch (_a) {
46
+ return;
47
+ }
48
+ };
49
+ /**
50
+ * Verify one `author.wallets` entry. `authorPublicKey` is the key address (12D3KooW...) of the
51
+ * signing key of the publication or list carrying the entry; the proof counts only if that record's
52
+ * own signature is valid too. Rely on an entry (show it as the author's wallet, count holdings,
53
+ * send funds) only when the outcome is valid. An unknown entry uses a signature type this check
54
+ * doesn't implement: it is unproven, and communities don't reject publications over it.
55
+ */
56
+ export const verifyAuthorWallet = (wallet, authorPublicKey, options) => {
57
+ var _a;
58
+ // a malformed key can come from the record being read, so it's an outcome, as in pkc-js
59
+ if (typeof authorPublicKey !== "string" || !KEY_ADDRESS_REGEX.test(authorPublicKey)) {
60
+ return {
61
+ outcome: "invalid",
62
+ reason: "authorPublicKey is not a key address (12D3KooW...), never author.address or author.name",
63
+ };
64
+ }
65
+ const nowSeconds = (_a = options === null || options === void 0 ? void 0 : options.nowSeconds) !== null && _a !== void 0 ? _a : Math.floor(Date.now() / 1000);
66
+ const invalid = (reason) => ({ outcome: "invalid", reason });
67
+ // the shape every entry has, whatever its type; members BSIP-22 doesn't define are ignored
68
+ if (!isRecord(wallet))
69
+ return invalid("wallet is not an object");
70
+ const { address, timestamp, signature } = wallet;
71
+ if (typeof address !== "string")
72
+ return invalid("address is not a string");
73
+ if (typeof timestamp !== "number" || !Number.isInteger(timestamp)) {
74
+ return invalid("timestamp is not an integer");
75
+ }
76
+ if (!isRecord(signature))
77
+ return invalid("signature is not an object");
78
+ if (typeof signature.signature !== "string")
79
+ return invalid("signature.signature is not a string");
80
+ if (typeof signature.type !== "string")
81
+ return invalid("signature.type is not a string");
82
+ if (signature.type !== "eip191")
83
+ return { outcome: "unknown" };
84
+ if (!WALLET_ADDRESS_REGEX.test(address)) {
85
+ return invalid("address is not a 0x address with 40 hex digits");
86
+ }
87
+ if (timestamp < 0)
88
+ return invalid("timestamp is negative");
89
+ if (timestamp > nowSeconds + AUTHOR_WALLET_PROOF_CLOCK_ALLOWANCE_SECONDS) {
90
+ return invalid(`timestamp is more than ${AUTHOR_WALLET_PROOF_CLOCK_ALLOWANCE_SECONDS} seconds in the future`);
91
+ }
92
+ if (!SIGNATURE_REGEX.test(signature.signature)) {
93
+ return invalid("signature is not 65 bytes as 0x and 130 hex digits");
94
+ }
95
+ const signatureBytes = hexToBytes(signature.signature.slice(2));
96
+ // recovery libraries accept a v of 0/1 and a high s, so both are checked here
97
+ const v = signatureBytes[64];
98
+ if (v !== 27 && v !== 28)
99
+ return invalid("signature v is not 27 or 28");
100
+ const s = BigInt(`0x${bytesToHex(signatureBytes.slice(32, 64))}`);
101
+ if (s > secp256k1.Point.Fn.ORDER >> BigInt(1)) {
102
+ return invalid("signature s is in the upper half of the curve order");
103
+ }
104
+ const message = getWalletMessageToSign(authorPublicKey, address, timestamp);
105
+ if (recoverAddress(hashPersonalMessage(message), signatureBytes) !== address.toLowerCase()) {
106
+ return invalid("signature does not recover the wallet address");
107
+ }
108
+ return { outcome: "valid" };
109
+ };
110
+ /** The key address (12D3KooW...) of a PKC private key (base64 ed25519 seed), as pkc-js derives it. */
111
+ export const getKeyAddressFromPkcPrivateKey = (privateKeyBase64) => {
112
+ const privateKeyBytes = Uint8Array.from(atob(privateKeyBase64), (c) => c.charCodeAt(0));
113
+ if (privateKeyBytes.length !== 32) {
114
+ throw Error("failed getting key address from private key not 32 bytes");
115
+ }
116
+ return getPkcAddressFromPublicKey(uint8ArrayToString(ed25519.getPublicKey(privateKeyBytes), "base64"));
117
+ };
118
+ //# sourceMappingURL=author-wallet-proof.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"author-wallet-proof.js","sourceRoot":"","sources":["../../../src/lib/chain/author-wallet-proof.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AA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,MAAM,eAAe,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IACxF,IAAI,eAAe,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;QAClC,MAAM,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC1E,CAAC;IACD,OAAO,0BAA0B,CAC/B,kBAAkB,CAAC,OAAO,CAAC,YAAY,CAAC,eAAe,CAAC,EAAE,QAAQ,CAAC,CACpE,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { ed25519 } from \"@noble/curves/ed25519.js\";\nimport { secp256k1 } from \"@noble/curves/secp256k1.js\";\nimport { keccak_256 } from \"@noble/hashes/sha3.js\";\nimport { bytesToHex, hexToBytes, utf8ToBytes } from \"@noble/hashes/utils.js\";\nimport { toString as uint8ArrayToString } from \"uint8arrays/to-string\";\nimport { getPkcAddressFromPublicKey } from \"../pkc-address\";\n\n// Author wallet proofs as specified by BSIP-22 (https://github.com/bitsocialnet/BSIPs/blob/master/BSIPS/bsip-22.md).\n// The same rules as pkc-js src/signer/author-wallet-proof.ts, which communities apply on acceptance.\n// Verification is one hash and one public key recovery, so it is synchronous and needs no network.\n// Published as its own entry point, @bitsocial/bitsocial-react-hooks/author-wallet-proof, and imported\n// dynamically inside the hooks: a static import from the package root would put the curves (about\n// 55 KB) in every app's startup bundle, since the hooks load this module when accounts load.\n\nexport type AuthorWalletOutcome =\n | { outcome: \"valid\" }\n | { outcome: \"unknown\" }\n | { outcome: \"invalid\"; reason: string };\n\n// a proof dated more than five minutes ahead of the verifier's clock is not valid yet\nexport const AUTHOR_WALLET_PROOF_CLOCK_ALLOWANCE_SECONDS = 300;\n\nconst DOMAIN_SEPARATOR = \"bitsocial-author-wallet\";\nconst WALLET_ADDRESS_REGEX = /^0x[0-9a-fA-F]{40}$/;\nconst SIGNATURE_REGEX = /^0x[0-9a-fA-F]{130}$/;\n// BSIP-10 key address: the base58btc peer id of an ed25519 key\nconst KEY_ADDRESS_REGEX = /^12D3KooW[1-9A-HJ-NP-Za-km-z]{44}$/;\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst assertKeyAddress = (authorPublicKey: unknown, functionName: string) => {\n if (typeof authorPublicKey !== \"string\" || !KEY_ADDRESS_REGEX.test(authorPublicKey)) {\n throw Error(\n `${functionName} authorPublicKey '${authorPublicKey}' is not a key address (12D3KooW...): pass the key address of the author's signing key, never author.address or author.name`,\n );\n }\n};\n\n/**\n * The exact string the wallet signs. Built by concatenation because BSIP-22 fixes the field order;\n * it is valid JSON only so wallets can show the user what they sign. `authorPublicKey` is the key\n * address of the author's signing key (12D3KooW...), never the runtime author.address.\n */\nexport const getWalletMessageToSign = (\n authorPublicKey: string,\n walletAddress: string,\n timestamp: number,\n) => {\n assertKeyAddress(authorPublicKey, \"getWalletMessageToSign\");\n return `{\"domainSeparator\":\"${DOMAIN_SEPARATOR}\",\"authorPublicKey\":\"${authorPublicKey}\",\"walletAddress\":\"${walletAddress.toLowerCase()}\",\"timestamp\":${timestamp}}`;\n};\n\n// EIP-191 version 0x45 (personal_sign): keccak256(\"\\x19Ethereum Signed Message:\\n\" + byteLength + message)\nconst hashPersonalMessage = (message: string) => {\n const messageBytes = utf8ToBytes(message);\n const prefix = utf8ToBytes(`\\x19Ethereum Signed Message:\\n${messageBytes.length}`);\n const bytes = new Uint8Array(prefix.length + messageBytes.length);\n bytes.set(prefix, 0);\n bytes.set(messageBytes, prefix.length);\n return keccak_256(bytes);\n};\n\n// the lowercase 0x address that signed `digest`, or undefined when no key recovers\nconst recoverAddress = (digest: Uint8Array, signatureBytes: Uint8Array) => {\n try {\n const signature = secp256k1.Signature.fromBytes(\n signatureBytes.slice(0, 64),\n \"compact\",\n ).addRecoveryBit(signatureBytes[64] - 27);\n const publicKey = signature.recoverPublicKey(digest).toBytes(false);\n return `0x${bytesToHex(keccak_256(publicKey.slice(1)).slice(12))}`;\n } catch {\n return;\n }\n};\n\n/**\n * Verify one `author.wallets` entry. `authorPublicKey` is the key address (12D3KooW...) of the\n * signing key of the publication or list carrying the entry; the proof counts only if that record's\n * own signature is valid too. Rely on an entry (show it as the author's wallet, count holdings,\n * send funds) only when the outcome is valid. An unknown entry uses a signature type this check\n * doesn't implement: it is unproven, and communities don't reject publications over it.\n */\nexport const verifyAuthorWallet = (\n wallet: unknown,\n authorPublicKey: string,\n options?: { nowSeconds?: number },\n): AuthorWalletOutcome => {\n // a malformed key can come from the record being read, so it's an outcome, as in pkc-js\n if (typeof authorPublicKey !== \"string\" || !KEY_ADDRESS_REGEX.test(authorPublicKey)) {\n return {\n outcome: \"invalid\",\n reason:\n \"authorPublicKey is not a key address (12D3KooW...), never author.address or author.name\",\n };\n }\n const nowSeconds = options?.nowSeconds ?? Math.floor(Date.now() / 1000);\n const invalid = (reason: string): AuthorWalletOutcome => ({ outcome: \"invalid\", reason });\n\n // the shape every entry has, whatever its type; members BSIP-22 doesn't define are ignored\n if (!isRecord(wallet)) return invalid(\"wallet is not an object\");\n const { address, timestamp, signature } = wallet;\n if (typeof address !== \"string\") return invalid(\"address is not a string\");\n if (typeof timestamp !== \"number\" || !Number.isInteger(timestamp)) {\n return invalid(\"timestamp is not an integer\");\n }\n if (!isRecord(signature)) return invalid(\"signature is not an object\");\n if (typeof signature.signature !== \"string\")\n return invalid(\"signature.signature is not a string\");\n if (typeof signature.type !== \"string\") return invalid(\"signature.type is not a string\");\n\n if (signature.type !== \"eip191\") return { outcome: \"unknown\" };\n\n if (!WALLET_ADDRESS_REGEX.test(address)) {\n return invalid(\"address is not a 0x address with 40 hex digits\");\n }\n if (timestamp < 0) return invalid(\"timestamp is negative\");\n if (timestamp > nowSeconds + AUTHOR_WALLET_PROOF_CLOCK_ALLOWANCE_SECONDS) {\n return invalid(\n `timestamp is more than ${AUTHOR_WALLET_PROOF_CLOCK_ALLOWANCE_SECONDS} seconds in the future`,\n );\n }\n if (!SIGNATURE_REGEX.test(signature.signature)) {\n return invalid(\"signature is not 65 bytes as 0x and 130 hex digits\");\n }\n const signatureBytes = hexToBytes(signature.signature.slice(2));\n // recovery libraries accept a v of 0/1 and a high s, so both are checked here\n const v = signatureBytes[64];\n if (v !== 27 && v !== 28) return invalid(\"signature v is not 27 or 28\");\n const s = BigInt(`0x${bytesToHex(signatureBytes.slice(32, 64))}`);\n if (s > secp256k1.Point.Fn.ORDER >> BigInt(1)) {\n return invalid(\"signature s is in the upper half of the curve order\");\n }\n\n const message = getWalletMessageToSign(authorPublicKey, address, timestamp);\n if (recoverAddress(hashPersonalMessage(message), signatureBytes) !== address.toLowerCase()) {\n return invalid(\"signature does not recover the wallet address\");\n }\n return { outcome: \"valid\" };\n};\n\n/** The key address (12D3KooW...) of a PKC private key (base64 ed25519 seed), as pkc-js derives it. */\nexport const getKeyAddressFromPkcPrivateKey = (privateKeyBase64: string) => {\n const privateKeyBytes = Uint8Array.from(atob(privateKeyBase64), (c) => c.charCodeAt(0));\n if (privateKeyBytes.length !== 32) {\n throw Error(\"failed getting key address from private key not 32 bytes\");\n }\n return getPkcAddressFromPublicKey(\n uint8ArrayToString(ed25519.getPublicKey(privateKeyBytes), \"base64\"),\n );\n};\n"]}
@@ -4,8 +4,12 @@ export declare const getNftImageUrl: (...args: any) => Promise<any>;
4
4
  export declare const getNftMetadataUrl: (...args: any) => Promise<any>;
5
5
  export declare const getNftOwner: (...args: any) => Promise<any>;
6
6
  export declare const resolveEnsTxtRecord: (...args: any) => Promise<any>;
7
- export declare const getWalletMessageToSign: (authorAddress: string, timestamp: number) => string;
8
- export declare const getEthWalletFromPkcPrivateKey: (privateKeyBase64: string, authorAddress: string) => Promise<{
7
+ /**
8
+ * The author wallet derived from the author's PKC private key, with a BSIP-22 proof. The proof
9
+ * binds the key address of that private key, so it stays valid when author.address changes to a
10
+ * name. The second argument is ignored: it used to be author.address, which BSIP-22 forbids.
11
+ */
12
+ export declare const getEthWalletFromPkcPrivateKey: (privateKeyBase64: string, _authorAddress?: string) => Promise<{
9
13
  address: string;
10
14
  timestamp: number;
11
15
  signature: {
@@ -13,15 +17,19 @@ export declare const getEthWalletFromPkcPrivateKey: (privateKeyBase64: string, a
13
17
  type: string;
14
18
  };
15
19
  } | undefined>;
16
- export declare const getEthPrivateKeyFromPkcPrivateKey: (privateKeyBase64: string, authorAddress: string) => Promise<string | undefined>;
17
- export declare const validateEthWallet: (wallet: Wallet, authorAddress: string) => Promise<void>;
18
- export declare const validateEthWalletViem: (wallet: Wallet, authorAddress: string) => Promise<void>;
20
+ export declare const getEthPrivateKeyFromPkcPrivateKey: (privateKeyBase64: string, authorAddress?: string) => Promise<string | undefined>;
21
+ /**
22
+ * Resolve when `wallet` is a valid BSIP-22 proof for the author key address `authorPublicKey`
23
+ * (12D3KooW..., never author.address), throw otherwise, including for a signature type this check
24
+ * doesn't implement. Use verifyAuthorWallet to tell invalid and unknown entries apart.
25
+ */
26
+ export declare const validateEthWallet: (wallet: Wallet, authorPublicKey: string) => Promise<void>;
19
27
  declare const _default: {
20
28
  getNftOwner: (...args: any) => Promise<any>;
21
29
  getNftMetadataUrl: (...args: any) => Promise<any>;
22
30
  getNftImageUrl: (...args: any) => Promise<any>;
23
31
  resolveEnsTxtRecord: (...args: any) => Promise<any>;
24
- getEthWalletFromPkcPrivateKey: (privateKeyBase64: string, authorAddress: string) => Promise<{
32
+ getEthWalletFromPkcPrivateKey: (privateKeyBase64: string, _authorAddress?: string) => Promise<{
25
33
  address: string;
26
34
  timestamp: number;
27
35
  signature: {
@@ -29,9 +37,8 @@ declare const _default: {
29
37
  type: string;
30
38
  };
31
39
  } | undefined>;
32
- getEthPrivateKeyFromPkcPrivateKey: (privateKeyBase64: string, authorAddress: string) => Promise<string | undefined>;
33
- validateEthWallet: (wallet: Wallet, authorAddress: string) => Promise<void>;
34
- validateEthWalletViem: (wallet: Wallet, authorAddress: string) => Promise<void>;
40
+ getEthPrivateKeyFromPkcPrivateKey: (privateKeyBase64: string, authorAddress?: string) => Promise<string | undefined>;
41
+ validateEthWallet: (wallet: Wallet, authorPublicKey: string) => Promise<void>;
35
42
  };
36
43
  export default _default;
37
44
  //# sourceMappingURL=chain.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../../../src/lib/chain/chain.ts"],"names":[],"mappings":"AACA,OAAO,EAAuB,MAAM,EAAE,MAAM,aAAa,CAAC;AAe1D,eAAO,MAAM,4BAA4B,YAGxC,CAAC;AA+BF,eAAO,MAAM,cAAc,gCAAuD,CAAC;AA8CnF,eAAO,MAAM,iBAAiB,gCAA0D,CAAC;AA8BzF,eAAO,MAAM,WAAW,gCAGtB,CAAC;AAkBH,eAAO,MAAM,mBAAmB,gCAG9B,CAAC;AAyCH,eAAO,MAAM,sBAAsB,GAAI,eAAe,MAAM,EAAE,WAAW,MAAM,WAI9E,CAAC;AAEF,eAAO,MAAM,6BAA6B,GACxC,kBAAkB,MAAM,EACxB,eAAe,MAAM;;;;;;;cAuBtB,CAAC;AAEF,eAAO,MAAM,iCAAiC,GAC5C,kBAAkB,MAAM,EACxB,eAAe,MAAM,gCActB,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAU,QAAQ,MAAM,EAAE,eAAe,MAAM,kBAmC5E,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAU,QAAQ,MAAM,EAAE,eAAe,MAAM,kBAqChF,CAAC;;;;;;sDAtHkB,MAAM,iBACT,MAAM;;;;;;;;0DA0BH,MAAM,iBACT,MAAM;gCAgByB,MAAM,iBAAiB,MAAM;oCAqCzB,MAAM,iBAAiB,MAAM;;AAuCjF,wBASE"}
1
+ {"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../../../src/lib/chain/chain.ts"],"names":[],"mappings":"AACA,OAAO,EAAuB,MAAM,EAAE,MAAM,aAAa,CAAC;AAkB1D,eAAO,MAAM,4BAA4B,YAGxC,CAAC;AA+BF,eAAO,MAAM,cAAc,gCAAuD,CAAC;AA8CnF,eAAO,MAAM,iBAAiB,gCAA0D,CAAC;AA8BzF,eAAO,MAAM,WAAW,gCAGtB,CAAC;AAkBH,eAAO,MAAM,mBAAmB,gCAG9B,CAAC;AAiDH;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,GACxC,kBAAkB,MAAM,EACxB,iBAAiB,MAAM;;;;;;;cAsBxB,CAAC;AAEF,eAAO,MAAM,iCAAiC,GAC5C,kBAAkB,MAAM,EACxB,gBAAgB,MAAM,gCAWvB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAAU,QAAQ,MAAM,EAAE,iBAAiB,MAAM,kBAS9E,CAAC;;;;;;sDAtDkB,MAAM,mBACP,MAAM;;;;;;;;0DAyBL,MAAM,kBACR,MAAM;gCAkBwB,MAAM,mBAAmB,MAAM;;AAW/E,wBAQE"}
@@ -17,6 +17,8 @@ const loadEthers = () => __awaiter(void 0, void 0, void 0, function* () {
17
17
  ethers || (ethers = (yield import("ethers")).ethers);
18
18
  return ethers;
19
19
  });
20
+ // The BSIP-22 proof code (noble curves) loads on demand for the same reason.
21
+ const loadAuthorWalletProof = () => import("./author-wallet-proof.js");
20
22
  // Account setup needs ethers (the author's eth wallet) and bso-resolver (the PKC client's name
21
23
  // resolvers) as soon as pkc-js loads. Starting both downloads when the accounts store initializes
22
24
  // loads them alongside pkc-js instead of one after another, without blocking the app's first render.
@@ -129,27 +131,33 @@ const nftAbi = [
129
131
  type: "function",
130
132
  },
131
133
  ];
132
- export const getWalletMessageToSign = (authorAddress, timestamp) => {
133
- // use plain JSON so the user can read what he's signing
134
- // property names must always be in this order for signature to match so don't use JSON.stringify
135
- return `{"domainSeparator":"pkc-author-wallet","authorAddress":"${authorAddress}","timestamp":${timestamp}}`;
134
+ const decodePkcPrivateKey = (privateKeyBase64) => {
135
+ const privateKeyBytes = Uint8Array.from(atob(privateKeyBase64), (c) => c.charCodeAt(0));
136
+ if (privateKeyBytes.length !== 32) {
137
+ throw Error("failed getting eth address from private key not 32 bytes");
138
+ }
139
+ return privateKeyBytes;
136
140
  };
137
- export const getEthWalletFromPkcPrivateKey = (privateKeyBase64, authorAddress) => __awaiter(void 0, void 0, void 0, function* () {
141
+ /**
142
+ * The author wallet derived from the author's PKC private key, with a BSIP-22 proof. The proof
143
+ * binds the key address of that private key, so it stays valid when author.address changes to a
144
+ * name. The second argument is ignored: it used to be author.address, which BSIP-22 forbids.
145
+ */
146
+ export const getEthWalletFromPkcPrivateKey = (privateKeyBase64, _authorAddress) => __awaiter(void 0, void 0, void 0, function* () {
138
147
  // ignore private key used in pkc-js signer mock so tests run faster, also make sure nobody uses it
139
148
  if (privateKeyBase64 === "private key") {
140
149
  return;
141
150
  }
142
- const privateKeyBytes = Uint8Array.from(atob(privateKeyBase64), (c) => c.charCodeAt(0));
143
- if (privateKeyBytes.length !== 32) {
144
- throw Error("failed getting eth address from private key not 32 bytes");
145
- }
151
+ const privateKeyBytes = decodePkcPrivateKey(privateKeyBase64);
152
+ const { getKeyAddressFromPkcPrivateKey, getWalletMessageToSign } = yield loadAuthorWalletProof();
153
+ const authorPublicKey = getKeyAddressFromPkcPrivateKey(privateKeyBase64);
146
154
  yield loadEthers();
147
155
  const publicKeyHex = ethers.utils.computePublicKey(privateKeyBytes, false);
148
156
  const privateKeyHex = ethers.utils.hexlify(privateKeyBytes);
149
157
  const ethAddress = ethers.utils.computeAddress(publicKeyHex);
150
- // generate signature
158
+ // ethers signs as a wallet does: EIP-191 personal message, low s, v of 27 or 28
151
159
  const timestamp = Math.floor(Date.now() / 1000);
152
- const signature = yield new ethers.Wallet(privateKeyHex).signMessage(getWalletMessageToSign(authorAddress, timestamp));
160
+ const signature = yield new ethers.Wallet(privateKeyHex).signMessage(getWalletMessageToSign(authorPublicKey, ethAddress, timestamp));
153
161
  return { address: ethAddress, timestamp, signature: { signature, type: "eip191" } };
154
162
  });
155
163
  export const getEthPrivateKeyFromPkcPrivateKey = (privateKeyBase64, authorAddress) => __awaiter(void 0, void 0, void 0, function* () {
@@ -157,49 +165,25 @@ export const getEthPrivateKeyFromPkcPrivateKey = (privateKeyBase64, authorAddres
157
165
  if (privateKeyBase64 === "private key") {
158
166
  return;
159
167
  }
160
- const privateKeyBytes = Uint8Array.from(atob(privateKeyBase64), (c) => c.charCodeAt(0));
161
- if (privateKeyBytes.length !== 32) {
162
- throw Error("failed getting eth address from private key not 32 bytes");
163
- }
168
+ const privateKeyBytes = decodePkcPrivateKey(privateKeyBase64);
164
169
  yield loadEthers();
165
170
  const privateKeyHex = ethers.utils.hexlify(privateKeyBytes);
166
171
  return privateKeyHex;
167
172
  });
168
- export const validateEthWallet = (wallet, authorAddress) => __awaiter(void 0, void 0, void 0, function* () {
169
- var _a, _b, _c;
170
- assert(wallet && typeof wallet === "object", `validateEthWallet invalid wallet argument '${wallet}'`);
171
- assert(wallet === null || wallet === void 0 ? void 0 : wallet.address, `validateEthWallet invalid wallet.address '${wallet === null || wallet === void 0 ? void 0 : wallet.address}'`);
172
- assert(typeof (wallet === null || wallet === void 0 ? void 0 : wallet.timestamp) === "number", `validateEthWallet invalid wallet.timestamp '${wallet === null || wallet === void 0 ? void 0 : wallet.timestamp}' not a number`);
173
- assert(wallet === null || wallet === void 0 ? void 0 : wallet.signature, `validateEthWallet invalid wallet.signature '${wallet === null || wallet === void 0 ? void 0 : wallet.signature}'`);
174
- assert((_a = wallet === null || wallet === void 0 ? void 0 : wallet.signature) === null || _a === void 0 ? void 0 : _a.signature, `validateEthWallet invalid wallet.signature.signature '${(_b = wallet === null || wallet === void 0 ? void 0 : wallet.signature) === null || _b === void 0 ? void 0 : _b.signature}'`);
175
- assert(wallet.signature.type === "eip191", `validateEthWallet invalid wallet.signature.type '${(_c = wallet === null || wallet === void 0 ? void 0 : wallet.signature) === null || _c === void 0 ? void 0 : _c.type}'`);
176
- assert(authorAddress && typeof authorAddress === "string", `validateEthWallet invalid authorAddress '${authorAddress}'`);
177
- assert((wallet === null || wallet === void 0 ? void 0 : wallet.timestamp) <= Date.now() / 1000, `validateEthWallet invalid wallet.timestamp '${wallet === null || wallet === void 0 ? void 0 : wallet.timestamp}' greater than current Date.now() / 1000`);
178
- yield loadEthers();
179
- const signatureAddress = ethers.utils.verifyMessage(getWalletMessageToSign(authorAddress, wallet.timestamp), wallet.signature.signature);
180
- if (wallet.address.toLowerCase() !== signatureAddress.toLowerCase()) {
181
- throw Error("wallet address does not equal signature address");
173
+ /**
174
+ * Resolve when `wallet` is a valid BSIP-22 proof for the author key address `authorPublicKey`
175
+ * (12D3KooW..., never author.address), throw otherwise, including for a signature type this check
176
+ * doesn't implement. Use verifyAuthorWallet to tell invalid and unknown entries apart.
177
+ */
178
+ export const validateEthWallet = (wallet, authorPublicKey) => __awaiter(void 0, void 0, void 0, function* () {
179
+ var _a;
180
+ const { verifyAuthorWallet } = yield loadAuthorWalletProof();
181
+ const result = verifyAuthorWallet(wallet, authorPublicKey);
182
+ if (result.outcome === "unknown") {
183
+ throw Error(`validateEthWallet unknown wallet.signature.type '${(_a = wallet === null || wallet === void 0 ? void 0 : wallet.signature) === null || _a === void 0 ? void 0 : _a.type}'`);
182
184
  }
183
- });
184
- export const validateEthWalletViem = (wallet, authorAddress) => __awaiter(void 0, void 0, void 0, function* () {
185
- var _a, _b, _c;
186
- // sanity checks
187
- assert(wallet && typeof wallet === "object", `validateEthWallet invalid wallet argument '${wallet}'`);
188
- assert(wallet === null || wallet === void 0 ? void 0 : wallet.address, `validateEthWallet invalid wallet.address '${wallet === null || wallet === void 0 ? void 0 : wallet.address}'`);
189
- assert(typeof (wallet === null || wallet === void 0 ? void 0 : wallet.timestamp) === "number", `validateEthWallet invalid wallet.timestamp '${wallet === null || wallet === void 0 ? void 0 : wallet.timestamp}' not a number`);
190
- assert(wallet === null || wallet === void 0 ? void 0 : wallet.signature, `validateEthWallet invalid wallet.signature '${wallet === null || wallet === void 0 ? void 0 : wallet.signature}'`);
191
- assert((_a = wallet === null || wallet === void 0 ? void 0 : wallet.signature) === null || _a === void 0 ? void 0 : _a.signature, `validateEthWallet invalid wallet.signature.signature '${(_b = wallet === null || wallet === void 0 ? void 0 : wallet.signature) === null || _b === void 0 ? void 0 : _b.signature}'`);
192
- assert(wallet.signature.type === "eip191", `validateEthWallet invalid wallet.signature.type '${(_c = wallet === null || wallet === void 0 ? void 0 : wallet.signature) === null || _c === void 0 ? void 0 : _c.type}'`);
193
- assert(authorAddress && typeof authorAddress === "string", `validateEthWallet invalid authorAddress '${authorAddress}'`);
194
- assert((wallet === null || wallet === void 0 ? void 0 : wallet.timestamp) <= Date.now() / 1000, `validateEthWallet invalid wallet.timestamp '${wallet === null || wallet === void 0 ? void 0 : wallet.timestamp}' greater than current Date.now() / 1000`);
195
- const { verifyMessage } = yield import("viem");
196
- const valid = yield verifyMessage({
197
- address: wallet.address,
198
- message: getWalletMessageToSign(authorAddress, wallet.timestamp),
199
- signature: wallet.signature.signature,
200
- });
201
- if (!valid) {
202
- throw Error("wallet address does not equal signature address");
185
+ if (result.outcome === "invalid") {
186
+ throw Error(`validateEthWallet invalid wallet: ${result.reason}`);
203
187
  }
204
188
  });
205
189
  export default {
@@ -210,6 +194,5 @@ export default {
210
194
  getEthWalletFromPkcPrivateKey,
211
195
  getEthPrivateKeyFromPkcPrivateKey,
212
196
  validateEthWallet,
213
- validateEthWalletViem,
214
197
  };
215
198
  //# sourceMappingURL=chain.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"chain.js","sourceRoot":"","sources":["../../../src/lib/chain/chain.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,MAAM,MAAM,WAAW,CAAC;AAE/B,OAAO,KAAK,MAAM,UAAU,CAAC;AAE7B,gGAAgG;AAChG,4FAA4F;AAC5F,+DAA+D;AAC/D,IAAI,MAAsC,CAAC;AAC3C,MAAM,UAAU,GAAG,GAAS,EAAE;IAC5B,MAAM,KAAN,MAAM,GAAK,CAAC,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAA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ert from \"../assert\";\nimport { Nft, ChainProviders, Wallet } from \"../../types\";\nimport utils from \"../utils\";\n\n// ethers and viem are large and only needed once an author wallet, NFT avatar, or ENS record is\n// used, so they load on demand instead of with the hooks that apps import at startup. Every\n// function below that uses `ethers` awaits loadEthers() first.\nlet ethers: typeof import(\"ethers\").ethers;\nconst loadEthers = async () => {\n ethers ||= (await import(\"ethers\")).ethers;\n return ethers;\n};\n\n// Account setup needs ethers (the author's eth wallet) and bso-resolver (the PKC client's name\n// resolvers) as soon as pkc-js loads. Starting both downloads when the accounts store initializes\n// loads them alongside pkc-js instead of one after another, without blocking the app's first render.\nexport const preloadAccountChainLibraries = () => {\n loadEthers().catch(() => {});\n import(\"@bitsocial/bso-resolver\").catch(() => {});\n};\n\n// NOTE: getNftImageUrl tests are skipped, if changes are made they must be tested manually\nconst getNftImageUrlNoCache = async (nftMetadataUrl: string, ipfsGatewayUrl: string) => {\n assert(\n nftMetadataUrl && typeof nftMetadataUrl === \"string\",\n `getNftImageUrl invalid nftMetadataUrl '${nftMetadataUrl}'`,\n );\n assert(\n ipfsGatewayUrl && typeof ipfsGatewayUrl === \"string\",\n `getNftImageUrl invalid ipfsGatewayUrl '${ipfsGatewayUrl}'`,\n );\n\n let nftImageUrl;\n\n // if the ipfs file is json, it probably has an 'image' property\n const text = await fetch(nftMetadataUrl).then((resp: any) => resp.text());\n try {\n nftImageUrl = JSON.parse(text).image;\n } catch (e) {\n // dont throw the json parse error, instead throw the http response\n throw Error(text);\n }\n\n // if the image property is an ipfs url, get the image url using the ipfs gateway in account settings\n if (nftImageUrl.startsWith(\"ipfs://\")) {\n nftImageUrl = `${ipfsGatewayUrl}/${nftImageUrl.replace(\"://\", \"/\")}`;\n }\n\n return nftImageUrl;\n};\nexport const getNftImageUrl = utils.memo(getNftImageUrlNoCache, { maxSize: 5000 });\n\n// NOTE: getNftMetadataUrl tests are skipped, if changes are made they must be tested manually\n// don't use objects in arguments for faster caching\nconst getNftMetadataUrlNoCache = async (\n nftAddress: string,\n nftId: string,\n chainTicker: string,\n chainProviderUrl: string,\n chainId: number,\n ipfsGatewayUrl: string,\n) => {\n assert(\n nftAddress && typeof nftAddress === \"string\",\n `getNftMetadataUrl invalid nftAddress '${nftAddress}'`,\n );\n assert(nftId && typeof nftId === \"string\", `getNftMetadataUrl invalid nftId '${nftId}'`);\n assert(\n chainTicker && typeof chainTicker === \"string\",\n `getNftMetadataUrl invalid chainTicker '${chainTicker}'`,\n );\n assert(\n chainProviderUrl && typeof chainProviderUrl === \"string\",\n `getNftMetadataUrl invalid chainProviderUrl '${chainProviderUrl}'`,\n );\n assert(\n typeof chainId === \"number\",\n `getNftMetadataUrl invalid chainId '${chainId}' not a number`,\n );\n assert(\n ipfsGatewayUrl && typeof ipfsGatewayUrl === \"string\",\n `getNftMetadataUrl invalid ipfsGatewayUrl '${ipfsGatewayUrl}'`,\n );\n\n await loadEthers();\n const chainProvider = getChainProvider(chainTicker, chainProviderUrl, chainId);\n const nftContract = new ethers.Contract(nftAddress, nftAbi, chainProvider);\n let nftMetadataUrl = await nftContract.tokenURI(nftId);\n\n // if the image property is an ipfs url, get the image url using the ipfs gateway in account settings\n if (nftMetadataUrl.startsWith(\"ipfs://\")) {\n nftMetadataUrl = `${ipfsGatewayUrl}/${nftMetadataUrl.replace(\"://\", \"/\")}`;\n }\n\n return nftMetadataUrl;\n};\nexport const getNftMetadataUrl = utils.memo(getNftMetadataUrlNoCache, { maxSize: 5000 });\n\n// don't use objects in arguments for faster caching\nconst getNftOwnerNoCache = async (\n nftAddress: string,\n nftId: string,\n chainTicker: string,\n chainProviderUrl: string,\n chainId: number,\n) => {\n assert(\n nftAddress && typeof nftAddress === \"string\",\n `getNftOwner invalid nftAddress '${nftAddress}'`,\n );\n assert(nftId && typeof nftId === \"string\", `getNftOwner invalid nftId '${nftId}'`);\n assert(\n chainTicker && typeof chainTicker === \"string\",\n `getNftOwner invalid chainTicker '${chainTicker}'`,\n );\n assert(\n chainProviderUrl && typeof chainProviderUrl === \"string\",\n `getNftOwner invalid chainProviderUrl '${chainProviderUrl}'`,\n );\n assert(typeof chainId === \"number\", `getNftOwner invalid chainId '${chainId}' not a number`);\n await loadEthers();\n const chainProvider = getChainProvider(chainTicker, chainProviderUrl, chainId);\n const nftContract = new ethers.Contract(nftAddress, nftAbi, chainProvider);\n const currentNftOwnerAddress = await nftContract.ownerOf(nftId);\n return currentNftOwnerAddress;\n};\nexport const getNftOwner = utils.memo(getNftOwnerNoCache, {\n maxSize: 5000,\n maxAge: 1000 * 60 * 60 * 24,\n});\n\nconst resolveEnsTxtRecordNoCache = async (\n ensName: string,\n txtRecordName: string,\n chainTicker: string,\n chainProviderUrl?: string,\n chainId?: number,\n) => {\n await loadEthers();\n const chainProvider = getChainProvider(chainTicker, chainProviderUrl, chainId);\n const resolver = await chainProvider.getResolver(ensName);\n if (!resolver) {\n throw Error(`name not registered or network error`);\n }\n const txtRecordResult = await resolver.getText(txtRecordName);\n return txtRecordResult;\n};\nexport const resolveEnsTxtRecord = utils.memo(resolveEnsTxtRecordNoCache, {\n maxSize: 10000,\n maxAge: 1000 * 60 * 60 * 24,\n});\n\n// cache the chain providers because only 1 should be running at the same time\nconst getChainProviderNoCache = (\n chainTicker: string,\n chainProviderUrl?: string,\n chainId?: number,\n) => {\n if (chainTicker === \"eth\") {\n // if using eth, use ethers' default provider unless another provider is specified\n if (!chainProviderUrl || chainProviderUrl === \"ethers.js\") {\n return ethers.getDefaultProvider();\n }\n }\n if (!chainProviderUrl) {\n throw Error(`getChainProvider invalid chainProviderUrl '${chainProviderUrl}'`);\n }\n if (!chainId && chainId !== 0) {\n throw Error(`getChainProvider invalid chainId '${chainId}'`);\n }\n return new ethers.providers.JsonRpcProvider({ url: chainProviderUrl }, chainId);\n};\nconst getChainProvider = utils.memoSync(getChainProviderNoCache, { maxSize: 1000 });\n\nconst nftAbi = [\n {\n inputs: [{ internalType: \"uint256\", name: \"tokenId\", type: \"uint256\" }],\n name: \"tokenURI\",\n outputs: [{ internalType: \"string\", name: \"\", type: \"string\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [{ internalType: \"uint256\", name: \"tokenId\", type: \"uint256\" }],\n name: \"ownerOf\",\n outputs: [{ internalType: \"address\", name: \"\", type: \"address\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n];\n\nexport const getWalletMessageToSign = (authorAddress: string, timestamp: number) => {\n // use plain JSON so the user can read what he's signing\n // property names must always be in this order for signature to match so don't use JSON.stringify\n return `{\"domainSeparator\":\"pkc-author-wallet\",\"authorAddress\":\"${authorAddress}\",\"timestamp\":${timestamp}}`;\n};\n\nexport const getEthWalletFromPkcPrivateKey = async (\n privateKeyBase64: string,\n authorAddress: string,\n) => {\n // ignore private key used in pkc-js signer mock so tests run faster, also make sure nobody uses it\n if (privateKeyBase64 === \"private key\") {\n return;\n }\n\n const privateKeyBytes = Uint8Array.from(atob(privateKeyBase64), (c) => c.charCodeAt(0));\n if (privateKeyBytes.length !== 32) {\n throw Error(\"failed getting eth address from private key not 32 bytes\");\n }\n await loadEthers();\n const publicKeyHex = ethers.utils.computePublicKey(privateKeyBytes, false);\n const privateKeyHex = ethers.utils.hexlify(privateKeyBytes);\n const ethAddress = ethers.utils.computeAddress(publicKeyHex);\n\n // generate signature\n const timestamp = Math.floor(Date.now() / 1000);\n const signature = await new ethers.Wallet(privateKeyHex).signMessage(\n getWalletMessageToSign(authorAddress, timestamp),\n );\n\n return { address: ethAddress, timestamp, signature: { signature, type: \"eip191\" } };\n};\n\nexport const getEthPrivateKeyFromPkcPrivateKey = async (\n privateKeyBase64: string,\n authorAddress: string,\n) => {\n // ignore private key used in pkc-js signer mock so tests run faster, also make sure nobody uses it\n if (privateKeyBase64 === \"private key\") {\n return;\n }\n\n const privateKeyBytes = Uint8Array.from(atob(privateKeyBase64), (c) => c.charCodeAt(0));\n if (privateKeyBytes.length !== 32) {\n throw Error(\"failed getting eth address from private key not 32 bytes\");\n }\n await loadEthers();\n const privateKeyHex = ethers.utils.hexlify(privateKeyBytes);\n return privateKeyHex;\n};\n\nexport const validateEthWallet = async (wallet: Wallet, authorAddress: string) => {\n assert(\n wallet && typeof wallet === \"object\",\n `validateEthWallet invalid wallet argument '${wallet}'`,\n );\n assert(wallet?.address, `validateEthWallet invalid wallet.address '${wallet?.address}'`);\n assert(\n typeof wallet?.timestamp === \"number\",\n `validateEthWallet invalid wallet.timestamp '${wallet?.timestamp}' not a number`,\n );\n assert(wallet?.signature, `validateEthWallet invalid wallet.signature '${wallet?.signature}'`);\n assert(\n wallet?.signature?.signature,\n `validateEthWallet invalid wallet.signature.signature '${wallet?.signature?.signature}'`,\n );\n assert(\n wallet.signature.type === \"eip191\",\n `validateEthWallet invalid wallet.signature.type '${wallet?.signature?.type}'`,\n );\n assert(\n authorAddress && typeof authorAddress === \"string\",\n `validateEthWallet invalid authorAddress '${authorAddress}'`,\n );\n assert(\n wallet?.timestamp <= Date.now() / 1000,\n `validateEthWallet invalid wallet.timestamp '${wallet?.timestamp}' greater than current Date.now() / 1000`,\n );\n await loadEthers();\n const signatureAddress = ethers.utils.verifyMessage(\n getWalletMessageToSign(authorAddress, wallet.timestamp),\n wallet.signature.signature,\n );\n if (wallet.address.toLowerCase() !== signatureAddress.toLowerCase()) {\n throw Error(\"wallet address does not equal signature address\");\n }\n};\n\nexport const validateEthWalletViem = async (wallet: Wallet, authorAddress: string) => {\n // sanity checks\n assert(\n wallet && typeof wallet === \"object\",\n `validateEthWallet invalid wallet argument '${wallet}'`,\n );\n assert(wallet?.address, `validateEthWallet invalid wallet.address '${wallet?.address}'`);\n assert(\n typeof wallet?.timestamp === \"number\",\n `validateEthWallet invalid wallet.timestamp '${wallet?.timestamp}' not a number`,\n );\n assert(wallet?.signature, `validateEthWallet invalid wallet.signature '${wallet?.signature}'`);\n assert(\n wallet?.signature?.signature,\n `validateEthWallet invalid wallet.signature.signature '${wallet?.signature?.signature}'`,\n );\n assert(\n wallet.signature.type === \"eip191\",\n `validateEthWallet invalid wallet.signature.type '${wallet?.signature?.type}'`,\n );\n assert(\n authorAddress && typeof authorAddress === \"string\",\n `validateEthWallet invalid authorAddress '${authorAddress}'`,\n );\n assert(\n wallet?.timestamp <= Date.now() / 1000,\n `validateEthWallet invalid wallet.timestamp '${wallet?.timestamp}' greater than current Date.now() / 1000`,\n );\n const { verifyMessage } = await import(\"viem\");\n const valid = await verifyMessage({\n address: wallet.address,\n message: getWalletMessageToSign(authorAddress, wallet.timestamp),\n signature: wallet.signature.signature,\n });\n if (!valid) {\n throw Error(\"wallet address does not equal signature address\");\n }\n};\n\nexport default {\n getNftOwner,\n getNftMetadataUrl,\n getNftImageUrl,\n resolveEnsTxtRecord,\n getEthWalletFromPkcPrivateKey,\n getEthPrivateKeyFromPkcPrivateKey,\n validateEthWallet,\n validateEthWalletViem,\n};\n"]}
1
+ {"version":3,"file":"chain.js","sourceRoot":"","sources":["../../../src/lib/chain/chain.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,MAAM,MAAM,WAAW,CAAC;AAE/B,OAAO,KAAK,MAAM,UAAU,CAAC;AAE7B,gGAAgG;AAChG,4FAA4F;AAC5F,+DAA+D;AAC/D,IAAI,MAAsC,CAAC;AAC3C,MAAM,UAAU,GAAG,GAAS,EAAE;IAC5B,MAAM,KAAN,MAAM,GAAK,CAAC,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAC;IAC3C,OAAO,MAAM,CAAC;AAChB,CAAC,CAAA,CAAC;AAEF,6EAA6E;AAC7E,MAAM,qBAAqB,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,uBAAuB,CAAC,CAAC;AAEpE,+FAA+F;AAC/F,kGAAkG;AAClG,qGAAqG;AACrG,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAAG,EAAE;IAC/C,UAAU,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAC7B,MAAM,CAAC,yBAAyB,CAAC,CAAC,KAAK,CAAC,GAAG,EAA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,MAAM,iBAAiB,GAAG,CAAO,MAAc,EAAE,eAAuB,EAAE,EAAE;;IACjF,MAAM,EAAE,kBAAkB,EAAE,GAAG,MAAM,qBAAqB,EAAE,CAAC;IAC7D,MAAM,MAAM,GAAG,kBAAkB,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC3D,IAAI,MAAM,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QACjC,MAAM,KAAK,CAAC,oDAAoD,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,SAAS,0CAAE,IAAI,GAAG,CAAC,CAAC;IAC9F,CAAC;IACD,IAAI,MAAM,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QACjC,MAAM,KAAK,CAAC,qCAAqC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IACpE,CAAC;AACH,CAAC,CAAA,CAAC;AAEF,eAAe;IACb,WAAW;IACX,iBAAiB;IACjB,cAAc;IACd,mBAAmB;IACnB,6BAA6B;IAC7B,iCAAiC;IACjC,iBAAiB;CAClB,CAAC","sourcesContent":["import assert from \"../assert\";\nimport { Nft, ChainProviders, Wallet } from \"../../types\";\nimport utils from \"../utils\";\n\n// ethers and viem are large and only needed once an author wallet, NFT avatar, or ENS record is\n// used, so they load on demand instead of with the hooks that apps import at startup. Every\n// function below that uses `ethers` awaits loadEthers() first.\nlet ethers: typeof import(\"ethers\").ethers;\nconst loadEthers = async () => {\n ethers ||= (await import(\"ethers\")).ethers;\n return ethers;\n};\n\n// The BSIP-22 proof code (noble curves) loads on demand for the same reason.\nconst loadAuthorWalletProof = () => import(\"./author-wallet-proof\");\n\n// Account setup needs ethers (the author's eth wallet) and bso-resolver (the PKC client's name\n// resolvers) as soon as pkc-js loads. Starting both downloads when the accounts store initializes\n// loads them alongside pkc-js instead of one after another, without blocking the app's first render.\nexport const preloadAccountChainLibraries = () => {\n loadEthers().catch(() => {});\n import(\"@bitsocial/bso-resolver\").catch(() => {});\n};\n\n// NOTE: getNftImageUrl tests are skipped, if changes are made they must be tested manually\nconst getNftImageUrlNoCache = async (nftMetadataUrl: string, ipfsGatewayUrl: string) => {\n assert(\n nftMetadataUrl && typeof nftMetadataUrl === \"string\",\n `getNftImageUrl invalid nftMetadataUrl '${nftMetadataUrl}'`,\n );\n assert(\n ipfsGatewayUrl && typeof ipfsGatewayUrl === \"string\",\n `getNftImageUrl invalid ipfsGatewayUrl '${ipfsGatewayUrl}'`,\n );\n\n let nftImageUrl;\n\n // if the ipfs file is json, it probably has an 'image' property\n const text = await fetch(nftMetadataUrl).then((resp: any) => resp.text());\n try {\n nftImageUrl = JSON.parse(text).image;\n } catch (e) {\n // dont throw the json parse error, instead throw the http response\n throw Error(text);\n }\n\n // if the image property is an ipfs url, get the image url using the ipfs gateway in account settings\n if (nftImageUrl.startsWith(\"ipfs://\")) {\n nftImageUrl = `${ipfsGatewayUrl}/${nftImageUrl.replace(\"://\", \"/\")}`;\n }\n\n return nftImageUrl;\n};\nexport const getNftImageUrl = utils.memo(getNftImageUrlNoCache, { maxSize: 5000 });\n\n// NOTE: getNftMetadataUrl tests are skipped, if changes are made they must be tested manually\n// don't use objects in arguments for faster caching\nconst getNftMetadataUrlNoCache = async (\n nftAddress: string,\n nftId: string,\n chainTicker: string,\n chainProviderUrl: string,\n chainId: number,\n ipfsGatewayUrl: string,\n) => {\n assert(\n nftAddress && typeof nftAddress === \"string\",\n `getNftMetadataUrl invalid nftAddress '${nftAddress}'`,\n );\n assert(nftId && typeof nftId === \"string\", `getNftMetadataUrl invalid nftId '${nftId}'`);\n assert(\n chainTicker && typeof chainTicker === \"string\",\n `getNftMetadataUrl invalid chainTicker '${chainTicker}'`,\n );\n assert(\n chainProviderUrl && typeof chainProviderUrl === \"string\",\n `getNftMetadataUrl invalid chainProviderUrl '${chainProviderUrl}'`,\n );\n assert(\n typeof chainId === \"number\",\n `getNftMetadataUrl invalid chainId '${chainId}' not a number`,\n );\n assert(\n ipfsGatewayUrl && typeof ipfsGatewayUrl === \"string\",\n `getNftMetadataUrl invalid ipfsGatewayUrl '${ipfsGatewayUrl}'`,\n );\n\n await loadEthers();\n const chainProvider = getChainProvider(chainTicker, chainProviderUrl, chainId);\n const nftContract = new ethers.Contract(nftAddress, nftAbi, chainProvider);\n let nftMetadataUrl = await nftContract.tokenURI(nftId);\n\n // if the image property is an ipfs url, get the image url using the ipfs gateway in account settings\n if (nftMetadataUrl.startsWith(\"ipfs://\")) {\n nftMetadataUrl = `${ipfsGatewayUrl}/${nftMetadataUrl.replace(\"://\", \"/\")}`;\n }\n\n return nftMetadataUrl;\n};\nexport const getNftMetadataUrl = utils.memo(getNftMetadataUrlNoCache, { maxSize: 5000 });\n\n// don't use objects in arguments for faster caching\nconst getNftOwnerNoCache = async (\n nftAddress: string,\n nftId: string,\n chainTicker: string,\n chainProviderUrl: string,\n chainId: number,\n) => {\n assert(\n nftAddress && typeof nftAddress === \"string\",\n `getNftOwner invalid nftAddress '${nftAddress}'`,\n );\n assert(nftId && typeof nftId === \"string\", `getNftOwner invalid nftId '${nftId}'`);\n assert(\n chainTicker && typeof chainTicker === \"string\",\n `getNftOwner invalid chainTicker '${chainTicker}'`,\n );\n assert(\n chainProviderUrl && typeof chainProviderUrl === \"string\",\n `getNftOwner invalid chainProviderUrl '${chainProviderUrl}'`,\n );\n assert(typeof chainId === \"number\", `getNftOwner invalid chainId '${chainId}' not a number`);\n await loadEthers();\n const chainProvider = getChainProvider(chainTicker, chainProviderUrl, chainId);\n const nftContract = new ethers.Contract(nftAddress, nftAbi, chainProvider);\n const currentNftOwnerAddress = await nftContract.ownerOf(nftId);\n return currentNftOwnerAddress;\n};\nexport const getNftOwner = utils.memo(getNftOwnerNoCache, {\n maxSize: 5000,\n maxAge: 1000 * 60 * 60 * 24,\n});\n\nconst resolveEnsTxtRecordNoCache = async (\n ensName: string,\n txtRecordName: string,\n chainTicker: string,\n chainProviderUrl?: string,\n chainId?: number,\n) => {\n await loadEthers();\n const chainProvider = getChainProvider(chainTicker, chainProviderUrl, chainId);\n const resolver = await chainProvider.getResolver(ensName);\n if (!resolver) {\n throw Error(`name not registered or network error`);\n }\n const txtRecordResult = await resolver.getText(txtRecordName);\n return txtRecordResult;\n};\nexport const resolveEnsTxtRecord = utils.memo(resolveEnsTxtRecordNoCache, {\n maxSize: 10000,\n maxAge: 1000 * 60 * 60 * 24,\n});\n\n// cache the chain providers because only 1 should be running at the same time\nconst getChainProviderNoCache = (\n chainTicker: string,\n chainProviderUrl?: string,\n chainId?: number,\n) => {\n if (chainTicker === \"eth\") {\n // if using eth, use ethers' default provider unless another provider is specified\n if (!chainProviderUrl || chainProviderUrl === \"ethers.js\") {\n return ethers.getDefaultProvider();\n }\n }\n if (!chainProviderUrl) {\n throw Error(`getChainProvider invalid chainProviderUrl '${chainProviderUrl}'`);\n }\n if (!chainId && chainId !== 0) {\n throw Error(`getChainProvider invalid chainId '${chainId}'`);\n }\n return new ethers.providers.JsonRpcProvider({ url: chainProviderUrl }, chainId);\n};\nconst getChainProvider = utils.memoSync(getChainProviderNoCache, { maxSize: 1000 });\n\nconst nftAbi = [\n {\n inputs: [{ internalType: \"uint256\", name: \"tokenId\", type: \"uint256\" }],\n name: \"tokenURI\",\n outputs: [{ internalType: \"string\", name: \"\", type: \"string\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [{ internalType: \"uint256\", name: \"tokenId\", type: \"uint256\" }],\n name: \"ownerOf\",\n outputs: [{ internalType: \"address\", name: \"\", type: \"address\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n];\n\nconst decodePkcPrivateKey = (privateKeyBase64: string) => {\n const privateKeyBytes = Uint8Array.from(atob(privateKeyBase64), (c) => c.charCodeAt(0));\n if (privateKeyBytes.length !== 32) {\n throw Error(\"failed getting eth address from private key not 32 bytes\");\n }\n return privateKeyBytes;\n};\n\n/**\n * The author wallet derived from the author's PKC private key, with a BSIP-22 proof. The proof\n * binds the key address of that private key, so it stays valid when author.address changes to a\n * name. The second argument is ignored: it used to be author.address, which BSIP-22 forbids.\n */\nexport const getEthWalletFromPkcPrivateKey = async (\n privateKeyBase64: string,\n _authorAddress?: string,\n) => {\n // ignore private key used in pkc-js signer mock so tests run faster, also make sure nobody uses it\n if (privateKeyBase64 === \"private key\") {\n return;\n }\n\n const privateKeyBytes = decodePkcPrivateKey(privateKeyBase64);\n const { getKeyAddressFromPkcPrivateKey, getWalletMessageToSign } = await loadAuthorWalletProof();\n const authorPublicKey = getKeyAddressFromPkcPrivateKey(privateKeyBase64);\n await loadEthers();\n const publicKeyHex = ethers.utils.computePublicKey(privateKeyBytes, false);\n const privateKeyHex = ethers.utils.hexlify(privateKeyBytes);\n const ethAddress = ethers.utils.computeAddress(publicKeyHex);\n\n // ethers signs as a wallet does: EIP-191 personal message, low s, v of 27 or 28\n const timestamp = Math.floor(Date.now() / 1000);\n const signature = await new ethers.Wallet(privateKeyHex).signMessage(\n getWalletMessageToSign(authorPublicKey, ethAddress, timestamp),\n );\n\n return { address: ethAddress, timestamp, signature: { signature, type: \"eip191\" } };\n};\n\nexport const getEthPrivateKeyFromPkcPrivateKey = async (\n privateKeyBase64: string,\n authorAddress?: string,\n) => {\n // ignore private key used in pkc-js signer mock so tests run faster, also make sure nobody uses it\n if (privateKeyBase64 === \"private key\") {\n return;\n }\n\n const privateKeyBytes = decodePkcPrivateKey(privateKeyBase64);\n await loadEthers();\n const privateKeyHex = ethers.utils.hexlify(privateKeyBytes);\n return privateKeyHex;\n};\n\n/**\n * Resolve when `wallet` is a valid BSIP-22 proof for the author key address `authorPublicKey`\n * (12D3KooW..., never author.address), throw otherwise, including for a signature type this check\n * doesn't implement. Use verifyAuthorWallet to tell invalid and unknown entries apart.\n */\nexport const validateEthWallet = async (wallet: Wallet, authorPublicKey: string) => {\n const { verifyAuthorWallet } = await loadAuthorWalletProof();\n const result = verifyAuthorWallet(wallet, authorPublicKey);\n if (result.outcome === \"unknown\") {\n throw Error(`validateEthWallet unknown wallet.signature.type '${wallet?.signature?.type}'`);\n }\n if (result.outcome === \"invalid\") {\n throw Error(`validateEthWallet invalid wallet: ${result.reason}`);\n }\n};\n\nexport default {\n getNftOwner,\n getNftMetadataUrl,\n getNftImageUrl,\n resolveEnsTxtRecord,\n getEthWalletFromPkcPrivateKey,\n getEthPrivateKeyFromPkcPrivateKey,\n validateEthWallet,\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"accounts-actions.d.ts","sourceRoot":"","sources":["../../../src/stores/accounts/accounts-actions.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,OAAO,EAEP,qBAAqB,EAGrB,kBAAkB,EAClB,yBAAyB,EACzB,+BAA+B,EAC/B,2BAA2B,EAC3B,sBAAsB,EACtB,sBAAsB,EACtB,eAAe,EAEf,cAAc,EAGf,MAAM,aAAa,CAAC;AAyYrB,sGAAsG;AACtG,eAAO,MAAM,yBAAyB,GACpC,kBAAkB,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,EACvC,WAAW,MAAM,EACjB,OAAO,MAAM,EACb,SAAS,CAAC,eAAe,EAAE,GAAG,EAAE,EAAE,cAAc,EAAE,GAAG,KAAK,IAAI;;;;;;CAO/D,CAAC;AAoCF,eAAO,MAAM,0BAA0B,GAAI,mBAAmB,GAAG,EAAE,yBAAyB,GAAG,YAGtC,CAAC;AAE1D,eAAO,MAAM,yBAAyB,GAAI,mBAAmB,GAAG,QAK/D,CAAC;AAuCF,eAAO,MAAM,kCAAkC,GAC7C,wBAAwB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAC3D,WAAW,MAAM,EACjB,mBAAmB,GAAG;;CAsCvB,CAAC;AAEF,eAAO,MAAM,uCAAuC,GAClD,wBAAwB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAC3D,eAAe,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,EACpD,WAAW,MAAM,EACjB,mBAA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AEF,eAAO,MAAM,aAAa,GAAU,YAAY,MAAM,EAAE,cAAc,MAAM,kBAE3E,CAAC;AAoBF,eAAO,MAAM,cAAc,GACzB,uBAAuB,qBAAqB,EAC5C,cAAc,MAAM,4BA0mBrB,CAAC;AAEF,eAAO,MAAM,aAAa,GACxB,iCAAiC,MAAM,GAAG,MAAM,EAChD,cAAc,MAAM,kBAkCrB,CAAC;AA0CF,eAAO,MAAM,WAAW,GAAU,oBAAoB,kBAAkB,EAAE,cAAc,MAAM,kBA8N7F,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,WAAW,GAAU,YAAY,MAAM,EAAE,cAAc,MAAM,kBAiBzE,CAAC;AA4BF,eAAO,MAAM,kBAAkB,GAC7B,2BAA2B,yBAAyB,EACpD,cAAc,MAAM,kBAgJrB,CAAC;AAEF,eAAO,MAAM,wBAAwB,GACnC,iCAAiC,+BAA+B,EAChE,cAAc,MAAM,kBAgKrB,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAC/B,kBAAkB,MAAM,EACxB,6BAA6B,2BAA2B,EACxD,cAAc,MAAM,kBAmKrB,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,wBAAwB,sBAAsB,EAC9C,cAAc,MAAM,iBAmBrB,CAAC;AAEF,eAAO,MAAM,eAAe,GAAU,kBAAkB,MAAM,EAAE,cAAc,MAAM,kBAsDnF,CAAC"}
@@ -25,7 +25,6 @@ import accountsDatabase from "./accounts-database.js";
25
25
  import accountGenerator from "./account-generator.js";
26
26
  import Logger from "@pkcprotocol/pkc-logger";
27
27
  import validator from "../../lib/validator.js";
28
- import chain from "../../lib/chain/index.js";
29
28
  import assert from "../../lib/assert.js";
30
29
  const log = Logger("bitsocial-react-hooks:accounts:stores");
31
30
  import * as accountsActionsInternal from "./accounts-actions-internal.js";
@@ -633,7 +632,6 @@ export const setActiveAccount = (accountName) => __awaiter(void 0, void 0, void
633
632
  accountsStore.setState({ activeAccountId: accountId });
634
633
  });
635
634
  export const setAccount = (account) => __awaiter(void 0, void 0, void 0, function* () {
636
- var _a;
637
635
  const { accounts } = accountsStore.getState();
638
636
  validator.validateAccountsActionsSetAccountArguments(account);
639
637
  assert(accounts === null || accounts === void 0 ? void 0 : accounts[account.id], `cannot set account with account.id '${account.id}' id does not exist in database`);
@@ -643,14 +641,7 @@ export const setAccount = (account) => __awaiter(void 0, void 0, void 0, functio
643
641
  if (account.author.address !== accounts[account.id].author.address) {
644
642
  const communities = getAccountCommunities(account, communitiesStore.getState().communities);
645
643
  account = Object.assign(Object.assign({}, account), { communities });
646
- // wallet.signature changes if author.address changes
647
- if ((_a = account.author.wallets) === null || _a === void 0 ? void 0 : _a.eth) {
648
- const pkcSignerWalletWithNewAuthorAddress = yield chain.getEthWalletFromPkcPrivateKey(account.signer.privateKey, account.author.address);
649
- // wallet is using pkc signer, redo signature with new author.address
650
- if (account.author.wallets.eth.address === (pkcSignerWalletWithNewAuthorAddress === null || pkcSignerWalletWithNewAuthorAddress === void 0 ? void 0 : pkcSignerWalletWithNewAuthorAddress.address)) {
651
- account.author.wallets = Object.assign(Object.assign({}, account.author.wallets), { eth: pkcSignerWalletWithNewAuthorAddress });
652
- }
653
- }
644
+ // wallet proofs bind the signer's key address (BSIP-22), not author.address, so they stay valid
654
645
  }
655
646
  // use this function to serialize and update all databases
656
647
  yield accountsDatabase.addAccount(account);