@calimero-network/mero-js 14.0.0 → 15.0.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@calimero-network/mero-js",
3
- "version": "14.0.0",
3
+ "version": "15.0.0",
4
4
  "description": "Pure JavaScript SDK for Calimero",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,43 +0,0 @@
1
- /**
2
- * Account id encoding.
3
- *
4
- * **Core is hex everywhere now** — the admin API and every other id it spells.
5
- * This module used to describe a deliberate split, hex on the admin API against
6
- * base58 in contract data, and the core half of that is gone.
7
- *
8
- * The app half can remain. `env::account_id()` hands a guest 32 **raw bytes**,
9
- * not a string, so whatever an app stores in `sender` or keys `get_profiles` by
10
- * is the app's own rendering. An app that base58-encodes those bytes still
11
- * produces contract data that a hex admin id will not `===` — and for that app,
12
- * these helpers are still the boundary.
13
- *
14
- * So they stay, with their reason corrected: the mismatch they bridge is an
15
- * application convention, not something core imposes. An app that hex-encodes
16
- * needs none of this, and `toAccountHex` is a no-op on what it already holds.
17
- *
18
- * They convert accounts and nothing else: a device key, an alias or any other
19
- * value is returned unchanged, because converting is this module's job and
20
- * destroying what it cannot convert is not.
21
- */
22
- /**
23
- * Canonicalise an account id to hex — the form every admin route expects.
24
- *
25
- * Returns the input unchanged if it is not a 32-byte account, so a device key
26
- * or an alias survives a call to this function intact.
27
- */
28
- export declare function toAccountHex(id: string | null | undefined): string;
29
- /**
30
- * Canonicalise an account id to base58 — the form the contract stamps on
31
- * `sender` and keys `get_profiles` by.
32
- *
33
- * Returns the input unchanged if it is not a 32-byte account.
34
- */
35
- export declare function toAccountBase58(id: string | null | undefined): string;
36
- /**
37
- * True when both ids name the same account, whichever encoding each is in.
38
- *
39
- * This is the comparison to reach for when checking a contract-sourced
40
- * `sender` against an admin-sourced member id. Two ids that are not accounts
41
- * compare false rather than accidentally matching as raw strings.
42
- */
43
- export declare function sameAccount(a: string | null | undefined, b: string | null | undefined): boolean;
@@ -1,139 +0,0 @@
1
- /**
2
- * Account id encoding.
3
- *
4
- * **Core is hex everywhere now** — the admin API and every other id it spells.
5
- * This module used to describe a deliberate split, hex on the admin API against
6
- * base58 in contract data, and the core half of that is gone.
7
- *
8
- * The app half can remain. `env::account_id()` hands a guest 32 **raw bytes**,
9
- * not a string, so whatever an app stores in `sender` or keys `get_profiles` by
10
- * is the app's own rendering. An app that base58-encodes those bytes still
11
- * produces contract data that a hex admin id will not `===` — and for that app,
12
- * these helpers are still the boundary.
13
- *
14
- * So they stay, with their reason corrected: the mismatch they bridge is an
15
- * application convention, not something core imposes. An app that hex-encodes
16
- * needs none of this, and `toAccountHex` is a no-op on what it already holds.
17
- *
18
- * They convert accounts and nothing else: a device key, an alias or any other
19
- * value is returned unchanged, because converting is this module's job and
20
- * destroying what it cannot convert is not.
21
- */
22
- const BASE58_ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
23
- /** A 32-byte account rendered as 64 hex characters. */
24
- const HEX_ACCOUNT = /^[0-9a-f]{64}$/i;
25
- /** Bytes → base58. Leading zero bytes become leading '1's, as in bitcoin base58. */
26
- function encodeBase58(bytes) {
27
- if (bytes.length === 0)
28
- return '';
29
- const digits = [0];
30
- for (const byte of bytes) {
31
- let carry = byte;
32
- for (let i = 0; i < digits.length; i++) {
33
- carry += digits[i] << 8;
34
- digits[i] = carry % 58;
35
- carry = (carry / 58) | 0;
36
- }
37
- while (carry > 0) {
38
- digits.push(carry % 58);
39
- carry = (carry / 58) | 0;
40
- }
41
- }
42
- let out = '';
43
- for (const byte of bytes) {
44
- if (byte !== 0)
45
- break;
46
- out += BASE58_ALPHABET[0];
47
- }
48
- for (let i = digits.length - 1; i >= 0; i--) {
49
- out += BASE58_ALPHABET[digits[i]];
50
- }
51
- return out;
52
- }
53
- /** base58 → bytes. Returns null when the input is not valid base58. */
54
- function decodeBase58(value) {
55
- if (value.length === 0)
56
- return null;
57
- const bytes = [0];
58
- for (const char of value) {
59
- const index = BASE58_ALPHABET.indexOf(char);
60
- if (index < 0)
61
- return null;
62
- let carry = index;
63
- for (let i = 0; i < bytes.length; i++) {
64
- carry += bytes[i] * 58;
65
- bytes[i] = carry & 0xff;
66
- carry >>= 8;
67
- }
68
- while (carry > 0) {
69
- bytes.push(carry & 0xff);
70
- carry >>= 8;
71
- }
72
- }
73
- let leadingZeros = 0;
74
- for (const char of value) {
75
- if (char !== BASE58_ALPHABET[0])
76
- break;
77
- leadingZeros++;
78
- }
79
- return Uint8Array.from([
80
- ...new Array(leadingZeros).fill(0),
81
- ...bytes.reverse(),
82
- ]);
83
- }
84
- function toHex(bytes) {
85
- let out = '';
86
- for (const byte of bytes)
87
- out += byte.toString(16).padStart(2, '0');
88
- return out;
89
- }
90
- function fromHex(hex) {
91
- const bytes = new Uint8Array(hex.length / 2);
92
- for (let i = 0; i < bytes.length; i++) {
93
- bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
94
- }
95
- return bytes;
96
- }
97
- /**
98
- * Canonicalise an account id to hex — the form every admin route expects.
99
- *
100
- * Returns the input unchanged if it is not a 32-byte account, so a device key
101
- * or an alias survives a call to this function intact.
102
- */
103
- export function toAccountHex(id) {
104
- const trimmed = (id ?? '').trim();
105
- if (!trimmed)
106
- return '';
107
- if (HEX_ACCOUNT.test(trimmed))
108
- return trimmed.toLowerCase();
109
- const decoded = decodeBase58(trimmed);
110
- if (!decoded || decoded.length !== 32)
111
- return trimmed;
112
- return toHex(decoded);
113
- }
114
- /**
115
- * Canonicalise an account id to base58 — the form the contract stamps on
116
- * `sender` and keys `get_profiles` by.
117
- *
118
- * Returns the input unchanged if it is not a 32-byte account.
119
- */
120
- export function toAccountBase58(id) {
121
- const trimmed = (id ?? '').trim();
122
- if (!trimmed)
123
- return '';
124
- if (!HEX_ACCOUNT.test(trimmed))
125
- return trimmed;
126
- return encodeBase58(fromHex(trimmed));
127
- }
128
- /**
129
- * True when both ids name the same account, whichever encoding each is in.
130
- *
131
- * This is the comparison to reach for when checking a contract-sourced
132
- * `sender` against an admin-sourced member id. Two ids that are not accounts
133
- * compare false rather than accidentally matching as raw strings.
134
- */
135
- export function sameAccount(a, b) {
136
- const left = toAccountHex(a);
137
- const right = toAccountHex(b);
138
- return HEX_ACCOUNT.test(left) && left === right;
139
- }