zano_web3 9.6.0 → 10.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +17 -9
- package/server/dist/server.d.ts +13 -2
- package/server/dist/server.js +68 -6
- package/server/dist/server.js.map +1 -1
- package/server/dist/types.d.ts +24 -24
- package/server/src/server.ts +101 -8
- package/server/src/types.ts +111 -111
- package/shared/dist/utils.d.ts +61 -0
- package/shared/dist/utils.js +188 -0
- package/shared/dist/utils.js.map +1 -1
- package/shared/src/utils.ts +276 -1
- package/web/dist/index.d.ts +2 -4
- package/web/dist/index.js +2 -4
- package/web/dist/index.js.map +1 -1
- package/web/dist/types/errors/index.d.ts +7 -0
- package/web/dist/types/errors/index.js +9 -0
- package/web/dist/types/errors/index.js.map +1 -0
- package/web/dist/types/index.d.ts +4 -0
- package/web/dist/types/index.js +5 -0
- package/web/dist/types/index.js.map +1 -0
- package/web/dist/types/params/companion-requests/index.d.ts +1 -0
- package/web/dist/types/params/companion-requests/index.js +2 -0
- package/web/dist/types/params/companion-requests/index.js.map +1 -0
- package/web/dist/types/params/companion-requests/request-permissions/index.d.ts +5 -0
- package/web/dist/types/params/companion-requests/request-permissions/index.js +2 -0
- package/web/dist/types/params/companion-requests/request-permissions/index.js.map +1 -0
- package/web/dist/types/params/index.d.ts +1 -0
- package/web/dist/types/params/index.js +2 -0
- package/web/dist/types/params/index.js.map +1 -0
- package/web/dist/types/responses/companion-methods/create-alias/index.d.ts +13 -0
- package/web/dist/types/responses/companion-methods/create-alias/index.js +10 -0
- package/web/dist/types/responses/companion-methods/create-alias/index.js.map +1 -0
- package/web/dist/types/responses/companion-methods/get-address-by-alias/index.d.ts +12 -0
- package/web/dist/types/responses/companion-methods/get-address-by-alias/index.js +8 -0
- package/web/dist/types/responses/companion-methods/get-address-by-alias/index.js.map +1 -0
- package/web/dist/types/responses/companion-methods/get-wallet-data/index.d.ts +73 -0
- package/web/dist/types/responses/companion-methods/get-wallet-data/index.js +39 -0
- package/web/dist/types/responses/companion-methods/get-wallet-data/index.js.map +1 -0
- package/web/dist/types/responses/companion-methods/index.d.ts +5 -0
- package/web/dist/types/responses/companion-methods/index.js +2 -0
- package/web/dist/types/responses/companion-methods/index.js.map +1 -0
- package/web/dist/types/responses/companion-methods/request-message-sign/index.d.ts +23 -0
- package/web/dist/types/responses/companion-methods/request-message-sign/index.js +16 -0
- package/web/dist/types/responses/companion-methods/request-message-sign/index.js.map +1 -0
- package/web/dist/types/responses/companion-methods/request-permissions/index.d.ts +13 -0
- package/web/dist/types/responses/companion-methods/request-permissions/index.js +10 -0
- package/web/dist/types/responses/companion-methods/request-permissions/index.js.map +1 -0
- package/web/dist/types/responses/index.d.ts +1 -0
- package/web/dist/types/responses/index.js +2 -0
- package/web/dist/types/responses/index.js.map +1 -0
- package/web/dist/types/special/index.d.ts +1 -0
- package/web/dist/types/special/index.js +2 -0
- package/web/dist/types/special/index.js.map +1 -0
- package/web/dist/types/special/zano-window/index.d.ts +7 -0
- package/web/dist/types/special/zano-window/index.js +2 -0
- package/web/dist/types/special/zano-window/index.js.map +1 -0
- package/web/dist/zano-wallet.d.ts +11 -0
- package/web/dist/zano-wallet.js +125 -0
- package/web/dist/zano-wallet.js.map +1 -0
- package/web/src/index.ts +4 -7
- package/web/src/types/errors/index.ts +10 -0
- package/web/src/types/index.ts +4 -0
- package/web/src/types/params/companion-requests/index.ts +1 -0
- package/web/src/types/params/companion-requests/request-permissions/index.ts +10 -0
- package/web/src/types/params/index.ts +1 -0
- package/web/src/types/responses/companion-methods/create-alias/index.ts +19 -0
- package/web/src/types/responses/companion-methods/get-address-by-alias/index.ts +18 -0
- package/web/src/types/responses/companion-methods/get-wallet-data/index.ts +52 -0
- package/web/src/types/responses/companion-methods/index.ts +5 -0
- package/web/src/types/responses/companion-methods/request-message-sign/index.ts +33 -0
- package/web/src/types/responses/companion-methods/request-permissions/index.ts +19 -0
- package/web/src/types/responses/index.ts +2 -0
- package/web/src/types/special/index.ts +1 -0
- package/web/src/types/special/zano-window/index.ts +9 -0
- package/web/src/zano-wallet.ts +161 -0
- package/web/dist/hooks.d.ts +0 -3
- package/web/dist/hooks.js +0 -14
- package/web/dist/hooks.js.map +0 -1
- package/web/dist/types.d.ts +0 -32
- package/web/dist/types.js +0 -2
- package/web/dist/types.js.map +0 -1
- package/web/dist/zanoWallet.d.ts +0 -42
- package/web/dist/zanoWallet.js +0 -156
- package/web/dist/zanoWallet.js.map +0 -1
- package/web/src/hooks.ts +0 -18
- package/web/src/types.ts +0 -35
- package/web/src/zanoWallet.ts +0 -240
package/server/src/types.ts
CHANGED
|
@@ -1,111 +1,111 @@
|
|
|
1
|
-
export interface BaseAuthData {
|
|
2
|
-
address: string;
|
|
3
|
-
signature: string;
|
|
4
|
-
message: string;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export interface AliasAuth extends BaseAuthData {
|
|
8
|
-
alias: string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface PkeyAuth extends BaseAuthData {
|
|
12
|
-
pkey: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export type AuthData = AliasAuth | PkeyAuth;
|
|
16
|
-
|
|
17
|
-
export interface ValidationParams {
|
|
18
|
-
buff: string;
|
|
19
|
-
sig: string;
|
|
20
|
-
alias?: string;
|
|
21
|
-
pkey?: string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface APIAsset {
|
|
25
|
-
asset_id: string;
|
|
26
|
-
current_supply: number;
|
|
27
|
-
decimal_point: number;
|
|
28
|
-
full_name: string;
|
|
29
|
-
hidden_supply: boolean;
|
|
30
|
-
meta_info: string;
|
|
31
|
-
owner: string;
|
|
32
|
-
ticker: string;
|
|
33
|
-
total_max_supply: number;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface APIBalance {
|
|
37
|
-
asset_info: APIAsset;
|
|
38
|
-
awaiting_in: number;
|
|
39
|
-
awaiting_out: number;
|
|
40
|
-
total: number;
|
|
41
|
-
unlocked: number;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface BalanceInfo {
|
|
45
|
-
name: string;
|
|
46
|
-
ticker: string;
|
|
47
|
-
id: string;
|
|
48
|
-
amount: string;
|
|
49
|
-
awaiting_in: string;
|
|
50
|
-
awaiting_out: string;
|
|
51
|
-
total: string;
|
|
52
|
-
unlocked: string;
|
|
53
|
-
asset_info: APIAsset;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export interface SubTransfer {
|
|
57
|
-
amount: number;
|
|
58
|
-
asset_id: string;
|
|
59
|
-
is_income: boolean;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export interface EmployedEntry {
|
|
63
|
-
amount: number;
|
|
64
|
-
asset_id: string;
|
|
65
|
-
index: number;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export interface Transfer {
|
|
69
|
-
employed_entries: {
|
|
70
|
-
receive: EmployedEntry[];
|
|
71
|
-
spent: EmployedEntry[];
|
|
72
|
-
};
|
|
73
|
-
subtransfers: SubTransfer[];
|
|
74
|
-
comment: string;
|
|
75
|
-
fee: number;
|
|
76
|
-
height: number;
|
|
77
|
-
is_mining: boolean;
|
|
78
|
-
is_mixing: boolean;
|
|
79
|
-
is_service: boolean;
|
|
80
|
-
payment_id: string;
|
|
81
|
-
show_sender: boolean;
|
|
82
|
-
timestamp: number;
|
|
83
|
-
transfer_internal_index: number;
|
|
84
|
-
tx_blob_size: number;
|
|
85
|
-
tx_hash: string;
|
|
86
|
-
tx_type: number;
|
|
87
|
-
unlock_time: number;
|
|
88
|
-
remote_addresses: string[] | undefined;
|
|
89
|
-
remote_aliases: string[] | undefined;
|
|
90
|
-
}
|
|
91
|
-
export interface TxInfo {
|
|
92
|
-
last_item_index: number;
|
|
93
|
-
pi: {
|
|
94
|
-
balance: number;
|
|
95
|
-
curent_height: number;
|
|
96
|
-
transfer_entries_count: number;
|
|
97
|
-
transfers_count: number;
|
|
98
|
-
unlocked_balance: number;
|
|
99
|
-
};
|
|
100
|
-
total_transfers: number;
|
|
101
|
-
transfers: Transfer[];
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export interface AliasDetails {
|
|
105
|
-
alias_details: {
|
|
106
|
-
address: string;
|
|
107
|
-
comment: string;
|
|
108
|
-
tracking_key: string;
|
|
109
|
-
};
|
|
110
|
-
status: 'OK' | 'NOT_FOUND';
|
|
111
|
-
}
|
|
1
|
+
export interface BaseAuthData {
|
|
2
|
+
address: string;
|
|
3
|
+
signature: string;
|
|
4
|
+
message: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface AliasAuth extends BaseAuthData {
|
|
8
|
+
alias: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface PkeyAuth extends BaseAuthData {
|
|
12
|
+
pkey: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type AuthData = AliasAuth | PkeyAuth;
|
|
16
|
+
|
|
17
|
+
export interface ValidationParams {
|
|
18
|
+
buff: string;
|
|
19
|
+
sig: string;
|
|
20
|
+
alias?: string;
|
|
21
|
+
pkey?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface APIAsset {
|
|
25
|
+
asset_id: string;
|
|
26
|
+
current_supply: number | string;
|
|
27
|
+
decimal_point: number | string;
|
|
28
|
+
full_name: string;
|
|
29
|
+
hidden_supply: boolean;
|
|
30
|
+
meta_info: string;
|
|
31
|
+
owner: string;
|
|
32
|
+
ticker: string;
|
|
33
|
+
total_max_supply: number | string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface APIBalance {
|
|
37
|
+
asset_info: APIAsset;
|
|
38
|
+
awaiting_in: number | string;
|
|
39
|
+
awaiting_out: number | string;
|
|
40
|
+
total: number | string;
|
|
41
|
+
unlocked: number | string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface BalanceInfo {
|
|
45
|
+
name: string;
|
|
46
|
+
ticker: string;
|
|
47
|
+
id: string;
|
|
48
|
+
amount: string;
|
|
49
|
+
awaiting_in: string;
|
|
50
|
+
awaiting_out: string;
|
|
51
|
+
total: string;
|
|
52
|
+
unlocked: string;
|
|
53
|
+
asset_info: APIAsset;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface SubTransfer {
|
|
57
|
+
amount: number | string;
|
|
58
|
+
asset_id: string;
|
|
59
|
+
is_income: boolean;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface EmployedEntry {
|
|
63
|
+
amount: number | string;
|
|
64
|
+
asset_id: string;
|
|
65
|
+
index: number | string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface Transfer {
|
|
69
|
+
employed_entries: {
|
|
70
|
+
receive: EmployedEntry[];
|
|
71
|
+
spent: EmployedEntry[];
|
|
72
|
+
};
|
|
73
|
+
subtransfers: SubTransfer[];
|
|
74
|
+
comment: string;
|
|
75
|
+
fee: number | string;
|
|
76
|
+
height: number | string;
|
|
77
|
+
is_mining: boolean;
|
|
78
|
+
is_mixing: boolean;
|
|
79
|
+
is_service: boolean;
|
|
80
|
+
payment_id: string;
|
|
81
|
+
show_sender: boolean;
|
|
82
|
+
timestamp: number | string;
|
|
83
|
+
transfer_internal_index: number | string;
|
|
84
|
+
tx_blob_size: number | string;
|
|
85
|
+
tx_hash: string;
|
|
86
|
+
tx_type: number | string;
|
|
87
|
+
unlock_time: number | string;
|
|
88
|
+
remote_addresses: string[] | undefined;
|
|
89
|
+
remote_aliases: string[] | undefined;
|
|
90
|
+
}
|
|
91
|
+
export interface TxInfo {
|
|
92
|
+
last_item_index: number | string;
|
|
93
|
+
pi: {
|
|
94
|
+
balance: number | string;
|
|
95
|
+
curent_height: number | string;
|
|
96
|
+
transfer_entries_count: number | string;
|
|
97
|
+
transfers_count: number | string;
|
|
98
|
+
unlocked_balance: number | string;
|
|
99
|
+
};
|
|
100
|
+
total_transfers: number | string;
|
|
101
|
+
transfers: Transfer[];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface AliasDetails {
|
|
105
|
+
alias_details: {
|
|
106
|
+
address: string;
|
|
107
|
+
comment: string;
|
|
108
|
+
tracking_key: string;
|
|
109
|
+
};
|
|
110
|
+
status: 'OK' | 'NOT_FOUND';
|
|
111
|
+
}
|
package/shared/dist/utils.d.ts
CHANGED
|
@@ -5,3 +5,64 @@ export declare function validateTokensInput(input: string | number, decimal_poin
|
|
|
5
5
|
valid: boolean;
|
|
6
6
|
error?: undefined;
|
|
7
7
|
};
|
|
8
|
+
export type GenerateSecureMessageForSigningResult = {
|
|
9
|
+
success: true;
|
|
10
|
+
message: string;
|
|
11
|
+
} | {
|
|
12
|
+
success: false;
|
|
13
|
+
error: 'NONCE_TOO_SHORT' | 'CONTROL_CHARACTERS_NOT_ALLOWED';
|
|
14
|
+
};
|
|
15
|
+
export declare function generateSecureMessageForSigning({ domain, address, statement, uri, nonce, expirationTime, isTestnet }: {
|
|
16
|
+
domain: string;
|
|
17
|
+
address: string;
|
|
18
|
+
statement: string;
|
|
19
|
+
uri: string;
|
|
20
|
+
nonce: string;
|
|
21
|
+
expirationTime: Date;
|
|
22
|
+
isTestnet?: boolean;
|
|
23
|
+
}): GenerateSecureMessageForSigningResult;
|
|
24
|
+
export type ParseSecureMessageForSigningResult = {
|
|
25
|
+
success: true;
|
|
26
|
+
parsingResult: {
|
|
27
|
+
isSecureMessage: true;
|
|
28
|
+
isValidSecureMessage: true;
|
|
29
|
+
values: {
|
|
30
|
+
domain: string;
|
|
31
|
+
address: string;
|
|
32
|
+
statement: string;
|
|
33
|
+
uri: string;
|
|
34
|
+
nonce: string;
|
|
35
|
+
expirationTime: Date;
|
|
36
|
+
chainId: string;
|
|
37
|
+
version: string;
|
|
38
|
+
};
|
|
39
|
+
} | {
|
|
40
|
+
isSecureMessage: boolean;
|
|
41
|
+
isValidSecureMessage: false;
|
|
42
|
+
};
|
|
43
|
+
} | {
|
|
44
|
+
success: false;
|
|
45
|
+
error: never;
|
|
46
|
+
};
|
|
47
|
+
export declare function parseSecureMessageForSigning({ message, }: {
|
|
48
|
+
message: string;
|
|
49
|
+
}): ParseSecureMessageForSigningResult;
|
|
50
|
+
/**
|
|
51
|
+
* Extracts the public spend key (`pkey`) from a Zano address.
|
|
52
|
+
*
|
|
53
|
+
* This is a pure-TS port of the decode path used by the native
|
|
54
|
+
* `zano-node-util` addon (`base58::decode_addr` -> parse `account_public_address`):
|
|
55
|
+
* 1. CryptoNote block-based base58 decode of the address.
|
|
56
|
+
* 2. Split the blob into `varint(prefix) | data | checksum(4)`.
|
|
57
|
+
* 3. Verify the checksum (first 4 bytes of keccak-256 over `prefix | data`).
|
|
58
|
+
* 4. Read the `spend_public_key` (first 32 bytes of `data`) as the pkey.
|
|
59
|
+
*
|
|
60
|
+
* The `pkey` accepted by the `validate_signature` daemon RPC is exactly this
|
|
61
|
+
* spend public key, so this can be used to bind a claimed address to a pkey.
|
|
62
|
+
*
|
|
63
|
+
* @returns The spend public key as a lowercase hex string, or `null` if the
|
|
64
|
+
* address is malformed (too short, checksum mismatch, or missing key).
|
|
65
|
+
*/
|
|
66
|
+
export declare function getPkeyFromAddress({ address }: {
|
|
67
|
+
address: string;
|
|
68
|
+
}): string | null;
|
package/shared/dist/utils.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import Decimal from "decimal.js";
|
|
2
|
+
import { keccak_256 } from "@noble/hashes/sha3.js";
|
|
3
|
+
import { bytesToHex } from "@noble/hashes/utils.js";
|
|
4
|
+
import { base58xmr } from "@scure/base";
|
|
2
5
|
export function validateTokensInput(input, decimal_point = 12) {
|
|
3
6
|
if (typeof input === 'number') {
|
|
4
7
|
input = input.toString();
|
|
@@ -67,4 +70,189 @@ export function validateTokensInput(input, decimal_point = 12) {
|
|
|
67
70
|
valid: true
|
|
68
71
|
};
|
|
69
72
|
}
|
|
73
|
+
export function generateSecureMessageForSigning({ domain, address, statement, uri, nonce, expirationTime, isTestnet }) {
|
|
74
|
+
// C0/C1 controls (covers \n, \r, \t, NUL, DEL, …) plus Unicode line/paragraph
|
|
75
|
+
// separators (U+2028/U+2029), which split('\n') would not catch but still break
|
|
76
|
+
// the positional, line-based message layout.
|
|
77
|
+
const CONTROL_CHARS = /[\p{Cc}\p{Zl}\p{Zp}]/u;
|
|
78
|
+
for (const field of ['domain', 'address', 'statement', 'uri', 'nonce']) {
|
|
79
|
+
const value = { domain, address, statement, uri, nonce }[field];
|
|
80
|
+
if (CONTROL_CHARS.test(value)) {
|
|
81
|
+
return { success: false, error: 'CONTROL_CHARACTERS_NOT_ALLOWED' };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (nonce.length < 8) {
|
|
85
|
+
return {
|
|
86
|
+
success: false,
|
|
87
|
+
error: 'NONCE_TOO_SHORT'
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
let result = '';
|
|
91
|
+
result += `${domain} wants you to sign in with your Zano account:\n`;
|
|
92
|
+
result += `${address}\n`;
|
|
93
|
+
result += `\n`;
|
|
94
|
+
result += `${statement}\n`;
|
|
95
|
+
result += `\n`;
|
|
96
|
+
result += `URI: ${uri}\n`;
|
|
97
|
+
result += `Version: 1\n`;
|
|
98
|
+
result += `Chain ID: ${isTestnet ? 'zano:testnet' : 'zano:mainnet'}\n`;
|
|
99
|
+
result += `Nonce: ${nonce}\n`;
|
|
100
|
+
result += `Expiration Time: ${expirationTime.toISOString()}`;
|
|
101
|
+
return {
|
|
102
|
+
success: true,
|
|
103
|
+
message: result
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
export function parseSecureMessageForSigning({ message, }) {
|
|
107
|
+
// The message layout is fixed and positional (see
|
|
108
|
+
// generateSecureMessageForSigning):
|
|
109
|
+
//
|
|
110
|
+
// 0: "{domain} wants you to sign in with your Zano account:"
|
|
111
|
+
// 1: {address}
|
|
112
|
+
// 2: ""
|
|
113
|
+
// 3: {statement}
|
|
114
|
+
// 4: ""
|
|
115
|
+
// 5+: "Key: value" fields (URI, Version, Chain ID, Nonce, Expiration Time)
|
|
116
|
+
const HEADER_SUFFIX = ' wants you to sign in with your Zano account:';
|
|
117
|
+
const HEADER_LINE_COUNT = 5;
|
|
118
|
+
// A "Version: ..." line is the cheap signal that this is a secure message at
|
|
119
|
+
// all, independent of whether it fully parses.
|
|
120
|
+
const isSecureMessage = /(\r|\n)Version:.*/g.test(message);
|
|
121
|
+
const lines = message.split('\n');
|
|
122
|
+
if (lines.length < HEADER_LINE_COUNT ||
|
|
123
|
+
!lines[0].endsWith(HEADER_SUFFIX) ||
|
|
124
|
+
lines[2] !== '' ||
|
|
125
|
+
lines[4] !== '') {
|
|
126
|
+
return {
|
|
127
|
+
success: true,
|
|
128
|
+
parsingResult: { isSecureMessage, isValidSecureMessage: false }
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
const domain = lines[0].slice(0, -HEADER_SUFFIX.length);
|
|
132
|
+
const address = lines[1];
|
|
133
|
+
const statement = lines[3];
|
|
134
|
+
// The remaining lines are "Key: value" fields and may appear in any order.
|
|
135
|
+
const fields = new Map();
|
|
136
|
+
for (const line of lines.slice(HEADER_LINE_COUNT)) {
|
|
137
|
+
const separatorIndex = line.indexOf(': ');
|
|
138
|
+
if (separatorIndex === -1) {
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
fields.set(line.slice(0, separatorIndex), line.slice(separatorIndex + 2));
|
|
142
|
+
}
|
|
143
|
+
const uri = fields.get('URI');
|
|
144
|
+
const version = fields.get('Version');
|
|
145
|
+
const chainId = fields.get('Chain ID');
|
|
146
|
+
const nonce = fields.get('Nonce');
|
|
147
|
+
const expirationTimeRaw = fields.get('Expiration Time');
|
|
148
|
+
// Every field that carries a value we expose must be present.
|
|
149
|
+
if (domain.length === 0 ||
|
|
150
|
+
uri === undefined ||
|
|
151
|
+
version === undefined ||
|
|
152
|
+
chainId === undefined ||
|
|
153
|
+
nonce === undefined ||
|
|
154
|
+
expirationTimeRaw === undefined) {
|
|
155
|
+
return {
|
|
156
|
+
success: true,
|
|
157
|
+
parsingResult: { isSecureMessage, isValidSecureMessage: false }
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
// Fixed-value fields must match what generateSecureMessageForSigning emits,
|
|
161
|
+
// and the nonce carries the same minimum length it enforces.
|
|
162
|
+
if (nonce.length < 8 ||
|
|
163
|
+
version !== '1' ||
|
|
164
|
+
(chainId !== 'zano:mainnet' && chainId !== 'zano:testnet')) {
|
|
165
|
+
return {
|
|
166
|
+
success: true,
|
|
167
|
+
parsingResult: { isSecureMessage, isValidSecureMessage: false }
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
// Expiration Time must be a valid timestamp that has not already passed.
|
|
171
|
+
const expirationTime = new Date(expirationTimeRaw);
|
|
172
|
+
if (Number.isNaN(expirationTime.getTime()) ||
|
|
173
|
+
expirationTime.getTime() <= Date.now()) {
|
|
174
|
+
return {
|
|
175
|
+
success: true,
|
|
176
|
+
parsingResult: { isSecureMessage, isValidSecureMessage: false }
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
success: true,
|
|
181
|
+
parsingResult: {
|
|
182
|
+
isSecureMessage: true,
|
|
183
|
+
isValidSecureMessage: true,
|
|
184
|
+
values: {
|
|
185
|
+
domain,
|
|
186
|
+
address,
|
|
187
|
+
statement,
|
|
188
|
+
uri,
|
|
189
|
+
nonce,
|
|
190
|
+
expirationTime,
|
|
191
|
+
chainId,
|
|
192
|
+
version
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
function readVarint(buf, start) {
|
|
198
|
+
let result = 0n;
|
|
199
|
+
let shift = 0n;
|
|
200
|
+
let i = start;
|
|
201
|
+
while (true) {
|
|
202
|
+
const byte = buf[i++];
|
|
203
|
+
result |= BigInt(byte & 0x7f) << shift;
|
|
204
|
+
if ((byte & 0x80) === 0) {
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
shift += 7n;
|
|
208
|
+
}
|
|
209
|
+
return [result, i];
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Extracts the public spend key (`pkey`) from a Zano address.
|
|
213
|
+
*
|
|
214
|
+
* This is a pure-TS port of the decode path used by the native
|
|
215
|
+
* `zano-node-util` addon (`base58::decode_addr` -> parse `account_public_address`):
|
|
216
|
+
* 1. CryptoNote block-based base58 decode of the address.
|
|
217
|
+
* 2. Split the blob into `varint(prefix) | data | checksum(4)`.
|
|
218
|
+
* 3. Verify the checksum (first 4 bytes of keccak-256 over `prefix | data`).
|
|
219
|
+
* 4. Read the `spend_public_key` (first 32 bytes of `data`) as the pkey.
|
|
220
|
+
*
|
|
221
|
+
* The `pkey` accepted by the `validate_signature` daemon RPC is exactly this
|
|
222
|
+
* spend public key, so this can be used to bind a claimed address to a pkey.
|
|
223
|
+
*
|
|
224
|
+
* @returns The spend public key as a lowercase hex string, or `null` if the
|
|
225
|
+
* address is malformed (too short, checksum mismatch, or missing key).
|
|
226
|
+
*/
|
|
227
|
+
export function getPkeyFromAddress({ address }) {
|
|
228
|
+
let blob;
|
|
229
|
+
try {
|
|
230
|
+
blob = base58xmr.decode(address);
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
// Layout: varint(prefix) | data | checksum(4)
|
|
236
|
+
const ADDRESS_CHECKSUM_SIZE = 4;
|
|
237
|
+
if (blob.length < ADDRESS_CHECKSUM_SIZE) {
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
const body = blob.subarray(0, blob.length - ADDRESS_CHECKSUM_SIZE);
|
|
241
|
+
const checksum = blob.subarray(blob.length - ADDRESS_CHECKSUM_SIZE);
|
|
242
|
+
const expectedChecksum = keccak_256(body).subarray(0, ADDRESS_CHECKSUM_SIZE);
|
|
243
|
+
for (let i = 0; i < ADDRESS_CHECKSUM_SIZE; i++) {
|
|
244
|
+
if (checksum[i] !== expectedChecksum[i]) {
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
// Skip the prefix varint; `account_public_address` begins with the
|
|
249
|
+
// 32-byte spend_public_key, followed by the 32-byte view_public_key.
|
|
250
|
+
const [, dataStart] = readVarint(body, 0);
|
|
251
|
+
const data = body.subarray(dataStart);
|
|
252
|
+
const PUBLIC_KEY_SIZE = 32;
|
|
253
|
+
if (data.length < PUBLIC_KEY_SIZE * 2) {
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
return bytesToHex(data.subarray(0, PUBLIC_KEY_SIZE));
|
|
257
|
+
}
|
|
70
258
|
//# sourceMappingURL=utils.js.map
|
package/shared/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,UAAU,mBAAmB,CAAC,KAAsB,EAAE,gBAAwB,EAAE;IAElF,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC5B,KAAK,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;IAC7B,CAAC;IAED,IAAI,KAAK,KAAK,EAAE,EAAE,CAAC;QACf,OAAO;YACH,KAAK,EAAE,KAAK;YACZ,KAAK,EAAE,eAAe;SACzB,CAAC;IACN,CAAC;IAED,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IAEvC,MAAM,UAAU,GAAG,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC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