@calimero-network/mero-js 13.4.0 → 14.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/dist/account/index.d.ts +15 -15
- package/dist/account/index.js +15 -15
- package/dist/admin-api/admin-client.d.ts +10 -5
- package/dist/admin-api/admin-client.js +10 -5
- package/dist/admin-api/admin-types.d.ts +8 -7
- package/dist/events/group.d.ts +1 -1
- package/dist/index.browser.mjs +2 -2
- package/dist/index.browser.mjs.map +3 -3
- package/dist/index.cjs +11 -48
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +1 -1
- package/dist/index.mjs +11 -48
- package/dist/index.mjs.map +2 -2
- package/dist/warrant/warrant.d.ts +5 -6
- package/dist/warrant/warrant.js +1 -54
- package/package.json +1 -1
|
@@ -24,13 +24,12 @@
|
|
|
24
24
|
/** What a warrant authorises. */
|
|
25
25
|
export interface WarrantInput {
|
|
26
26
|
/**
|
|
27
|
-
* The context,
|
|
27
|
+
* The context, hex — the same string every other method here takes.
|
|
28
28
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
* than accepting "32 bytes, somehow".
|
|
29
|
+
* Hex like everything else on this interface. It was base58 while the node
|
|
30
|
+
* spelled `ContextId` and `PublicKey` that way and `AccountId` and `DeviceId`
|
|
31
|
+
* in hex; that split is gone, so this module no longer needs a rule per field
|
|
32
|
+
* and no longer needs a base58 decoder to enforce one.
|
|
34
33
|
*/
|
|
35
34
|
context: string;
|
|
36
35
|
/** The author's account, hex — whose consent this is. */
|
package/dist/warrant/warrant.js
CHANGED
|
@@ -28,7 +28,6 @@ const PKCS8_ED25519_PREFIX = new Uint8Array([
|
|
|
28
28
|
0x30, 0x2e, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x70, 0x04,
|
|
29
29
|
0x22, 0x04, 0x20,
|
|
30
30
|
]);
|
|
31
|
-
const B58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
32
31
|
function hex(bytes) {
|
|
33
32
|
return Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('');
|
|
34
33
|
}
|
|
@@ -46,58 +45,6 @@ function fromHex(value, label, expectedBytes) {
|
|
|
46
45
|
}
|
|
47
46
|
return bytes;
|
|
48
47
|
}
|
|
49
|
-
/**
|
|
50
|
-
* Decode base58 to exactly 32 bytes.
|
|
51
|
-
*
|
|
52
|
-
* Hand-rolled rather than pulled in: it is fifteen lines, and a dependency here
|
|
53
|
-
* would be this package's first.
|
|
54
|
-
*/
|
|
55
|
-
function fromBase58(value, label) {
|
|
56
|
-
const clean = value.trim();
|
|
57
|
-
let n = 0n;
|
|
58
|
-
for (const char of clean) {
|
|
59
|
-
const digit = B58.indexOf(char);
|
|
60
|
-
if (digit < 0) {
|
|
61
|
-
throw new Error(`${label} is not base58: unexpected character '${char}'`);
|
|
62
|
-
}
|
|
63
|
-
n = n * 58n + BigInt(digit);
|
|
64
|
-
}
|
|
65
|
-
const out = new Uint8Array(32);
|
|
66
|
-
for (let i = 31; i >= 0; i -= 1) {
|
|
67
|
-
out[i] = Number(n & 0xffn);
|
|
68
|
-
n >>= 8n;
|
|
69
|
-
}
|
|
70
|
-
if (n !== 0n) {
|
|
71
|
-
throw new Error(`${label} decodes to more than 32 bytes`);
|
|
72
|
-
}
|
|
73
|
-
// Round-trip, because decoding alone accepts too much. Hex digits are mostly
|
|
74
|
-
// valid base58 characters, so a context handed over in hex by mistake can
|
|
75
|
-
// decode to a real-looking 32 bytes instead of failing — `'11'.repeat(32)`
|
|
76
|
-
// decodes to all zeros. Re-encoding catches it: the canonical form of those
|
|
77
|
-
// bytes is 32 '1's, not 64.
|
|
78
|
-
if (toBase58(out) !== clean) {
|
|
79
|
-
throw new Error(`${label} is not a canonical base58 32-byte id. If you have it in hex, ` +
|
|
80
|
-
`note that ${label} is base58 here while accounts are hex`);
|
|
81
|
-
}
|
|
82
|
-
return out;
|
|
83
|
-
}
|
|
84
|
-
/** Encode 32 bytes as base58, for the canonical check above. */
|
|
85
|
-
function toBase58(bytes) {
|
|
86
|
-
let n = 0n;
|
|
87
|
-
for (const byte of bytes) {
|
|
88
|
-
n = (n << 8n) | BigInt(byte);
|
|
89
|
-
}
|
|
90
|
-
let out = '';
|
|
91
|
-
while (n > 0n) {
|
|
92
|
-
out = B58[Number(n % 58n)] + out;
|
|
93
|
-
n /= 58n;
|
|
94
|
-
}
|
|
95
|
-
let leadingZeros = 0;
|
|
96
|
-
while (leadingZeros < bytes.length && bytes[leadingZeros] === 0) {
|
|
97
|
-
leadingZeros += 1;
|
|
98
|
-
}
|
|
99
|
-
return '1'.repeat(leadingZeros) + out;
|
|
100
|
-
}
|
|
101
48
|
function u64le(value) {
|
|
102
49
|
const out = new Uint8Array(8);
|
|
103
50
|
new DataView(out.buffer).setBigUint64(0, BigInt(value), true);
|
|
@@ -159,7 +106,7 @@ async function importSigningKey(secretHex) {
|
|
|
159
106
|
* was signed.
|
|
160
107
|
*/
|
|
161
108
|
export async function signWarrant(input) {
|
|
162
|
-
const context =
|
|
109
|
+
const context = fromHex(input.context, 'context', 32);
|
|
163
110
|
const authorAccount = fromHex(input.authorAccount, 'authorAccount', 32);
|
|
164
111
|
const executor = fromHex(input.executor, 'executor', 32);
|
|
165
112
|
const key = await importSigningKey(input.deviceSecret);
|