@cakioe/hmac-signer 1.0.0 → 1.0.1
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/README.md +3 -0
- package/hmac_signer.d.ts +3 -1
- package/hmac_signer_bg.js +138 -0
- package/hmac_signer_bg.wasm +0 -0
- package/package.json +2 -2
package/README.md
CHANGED
package/hmac_signer.d.ts
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
|
|
4
4
|
export class HmacSha256Signer {
|
|
5
|
-
private constructor();
|
|
6
5
|
free(): void;
|
|
7
6
|
[Symbol.dispose](): void;
|
|
7
|
+
constructor(secret: string);
|
|
8
|
+
sign(timestamp: bigint, body: Uint8Array | number[]): string;
|
|
9
|
+
verify(timestamp: bigint, body: Uint8Array | number[], signature: string, tolerance?: bigint | null): boolean;
|
|
8
10
|
}
|
package/hmac_signer_bg.js
CHANGED
|
@@ -9,11 +9,80 @@ export class HmacSha256Signer {
|
|
|
9
9
|
const ptr = this.__destroy_into_raw();
|
|
10
10
|
wasm.__wbg_hmacsha256signer_free(ptr, 0);
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* @param {string} secret
|
|
14
|
+
*/
|
|
15
|
+
constructor(secret) {
|
|
16
|
+
const ptr0 = passStringToWasm0(secret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
17
|
+
const len0 = WASM_VECTOR_LEN;
|
|
18
|
+
const ret = wasm.hmacsha256signer_new(ptr0, len0);
|
|
19
|
+
this.__wbg_ptr = ret;
|
|
20
|
+
HmacSha256SignerFinalization.register(this, this.__wbg_ptr, this);
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* @param {bigint} timestamp
|
|
25
|
+
* @param {Uint8Array | number[]} body
|
|
26
|
+
* @returns {string}
|
|
27
|
+
*/
|
|
28
|
+
sign(timestamp, body) {
|
|
29
|
+
let deferred4_0;
|
|
30
|
+
let deferred4_1;
|
|
31
|
+
try {
|
|
32
|
+
const val2 = BigInt.asIntN(64, timestamp);
|
|
33
|
+
const ptr0 = passArray8ToWasm0(body, wasm.__wbindgen_malloc);
|
|
34
|
+
const len0 = WASM_VECTOR_LEN;
|
|
35
|
+
const ret = wasm.hmacsha256signer_sign(this.__wbg_ptr, val2, ptr0, len0);
|
|
36
|
+
var ptr3 = ret[0];
|
|
37
|
+
var len3 = ret[1];
|
|
38
|
+
if (ret[3]) {
|
|
39
|
+
ptr3 = 0; len3 = 0;
|
|
40
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
41
|
+
}
|
|
42
|
+
deferred4_0 = ptr3;
|
|
43
|
+
deferred4_1 = len3;
|
|
44
|
+
return getStringFromWasm0(ptr3, len3);
|
|
45
|
+
} finally {
|
|
46
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* @param {bigint} timestamp
|
|
51
|
+
* @param {Uint8Array | number[]} body
|
|
52
|
+
* @param {string} signature
|
|
53
|
+
* @param {bigint | null} [tolerance]
|
|
54
|
+
* @returns {boolean}
|
|
55
|
+
*/
|
|
56
|
+
verify(timestamp, body, signature, tolerance) {
|
|
57
|
+
const val3 = BigInt.asIntN(64, timestamp);
|
|
58
|
+
const val4 = BigInt.asIntN(64, (isLikeNone(tolerance) ? BigInt(0) : tolerance));
|
|
59
|
+
let ptr0, len0, ptr1, len1;
|
|
60
|
+
try {
|
|
61
|
+
ptr0 = passArray8ToWasm0(body, wasm.__wbindgen_malloc);
|
|
62
|
+
len0 = WASM_VECTOR_LEN;
|
|
63
|
+
ptr1 = passStringToWasm0(signature, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
64
|
+
len1 = WASM_VECTOR_LEN;
|
|
65
|
+
} catch (e) {
|
|
66
|
+
if (ptr1) { wasm.__wbindgen_free(ptr1, len1 * 1, 1); }
|
|
67
|
+
if (ptr0) { wasm.__wbindgen_free(ptr0, len0 * 1, 1); }
|
|
68
|
+
throw e;
|
|
69
|
+
}
|
|
70
|
+
const ret = wasm.hmacsha256signer_verify(this.__wbg_ptr, val3, ptr0, len0, ptr1, len1, !isLikeNone(tolerance), val4);
|
|
71
|
+
if (ret[2]) {
|
|
72
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
73
|
+
}
|
|
74
|
+
return ret[0] !== 0;
|
|
75
|
+
}
|
|
12
76
|
}
|
|
13
77
|
if (Symbol.dispose) HmacSha256Signer.prototype[Symbol.dispose] = HmacSha256Signer.prototype.free;
|
|
14
78
|
export function __wbg___wbindgen_throw_4c88d8bf264fd984(arg0, arg1) {
|
|
15
79
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
16
80
|
}
|
|
81
|
+
export function __wbindgen_generic_0000000000000001(arg0, arg1) {
|
|
82
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
83
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
84
|
+
return ret;
|
|
85
|
+
}
|
|
17
86
|
export function __wbindgen_init_externref_table() {
|
|
18
87
|
const table = wasm.__wbindgen_externrefs;
|
|
19
88
|
table.set(0, undefined);
|
|
@@ -39,6 +108,60 @@ function getUint8ArrayMemory0() {
|
|
|
39
108
|
return cachedUint8ArrayMemory0;
|
|
40
109
|
}
|
|
41
110
|
|
|
111
|
+
function isLikeNone(x) {
|
|
112
|
+
return x === undefined || x === null;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
116
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
117
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
118
|
+
WASM_VECTOR_LEN = arg.length;
|
|
119
|
+
return ptr;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
123
|
+
if (realloc === undefined) {
|
|
124
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
125
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
126
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
127
|
+
WASM_VECTOR_LEN = buf.length;
|
|
128
|
+
return ptr;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
let len = arg.length;
|
|
132
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
133
|
+
|
|
134
|
+
const mem = getUint8ArrayMemory0();
|
|
135
|
+
|
|
136
|
+
let offset = 0;
|
|
137
|
+
|
|
138
|
+
for (; offset < len; offset++) {
|
|
139
|
+
const code = arg.charCodeAt(offset);
|
|
140
|
+
if (code > 0x7F) break;
|
|
141
|
+
mem[ptr + offset] = code;
|
|
142
|
+
}
|
|
143
|
+
if (offset !== len) {
|
|
144
|
+
if (offset !== 0) {
|
|
145
|
+
arg = arg.slice(offset);
|
|
146
|
+
}
|
|
147
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
148
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
149
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
150
|
+
|
|
151
|
+
offset += ret.written;
|
|
152
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
WASM_VECTOR_LEN = offset;
|
|
156
|
+
return ptr;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function takeFromExternrefTable0(idx) {
|
|
160
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
161
|
+
wasm.__externref_table_dealloc(idx);
|
|
162
|
+
return value;
|
|
163
|
+
}
|
|
164
|
+
|
|
42
165
|
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true });
|
|
43
166
|
cachedTextDecoder.decode();
|
|
44
167
|
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
@@ -53,6 +176,21 @@ function decodeText(bytes) {
|
|
|
53
176
|
return cachedTextDecoder.decode(bytes);
|
|
54
177
|
}
|
|
55
178
|
|
|
179
|
+
const cachedTextEncoder = new TextEncoder();
|
|
180
|
+
|
|
181
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
182
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
183
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
184
|
+
view.set(buf);
|
|
185
|
+
return {
|
|
186
|
+
read: arg.length,
|
|
187
|
+
written: buf.length
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
let WASM_VECTOR_LEN = 0;
|
|
193
|
+
|
|
56
194
|
|
|
57
195
|
let wasm;
|
|
58
196
|
export function __wbg_set_wasm(val) {
|
package/hmac_signer_bg.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
"cleveng <cleveng@gmail.com>"
|
|
6
6
|
],
|
|
7
7
|
"description": "Hmac Signer By Rust",
|
|
8
|
-
"version": "1.0.
|
|
8
|
+
"version": "1.0.1",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "
|
|
12
|
+
"url": "https://github.com/cleveng/hmac-signer.git"
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
15
15
|
"hmac_signer_bg.wasm",
|