@cakioe/hmac-signer 1.0.2 → 1.0.4

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/hmac_signer.d.ts CHANGED
@@ -5,6 +5,6 @@ export class HmacSha256Signer {
5
5
  free(): void;
6
6
  [Symbol.dispose](): void;
7
7
  constructor(secret: string);
8
- sign(body: Uint8Array | number[], timestamp?: bigint | null): any;
9
- verify(body: Uint8Array | number[], timestamp: bigint, signature: string, tolerance?: bigint | null): boolean;
8
+ sign(body: any, timestamp?: bigint | null): any;
9
+ verify(body: any, timestamp: bigint, signature: string, tolerance?: bigint | null): boolean;
10
10
  }
package/hmac_signer_bg.js CHANGED
@@ -21,42 +21,30 @@ export class HmacSha256Signer {
21
21
  return this;
22
22
  }
23
23
  /**
24
- * @param {Uint8Array | number[]} body
24
+ * @param {any} body
25
25
  * @param {bigint | null} [timestamp]
26
26
  * @returns {any}
27
27
  */
28
28
  sign(body, timestamp) {
29
- const val2 = BigInt.asIntN(64, (isLikeNone(timestamp) ? BigInt(0) : timestamp));
30
- const ptr0 = passArray8ToWasm0(body, wasm.__wbindgen_malloc);
31
- const len0 = WASM_VECTOR_LEN;
32
- const ret = wasm.hmacsha256signer_sign(this.__wbg_ptr, ptr0, len0, !isLikeNone(timestamp), val2);
29
+ const ret = wasm.hmacsha256signer_sign(this.__wbg_ptr, body, !isLikeNone(timestamp), isLikeNone(timestamp) ? BigInt(0) : timestamp);
33
30
  if (ret[2]) {
34
31
  throw takeFromExternrefTable0(ret[1]);
35
32
  }
36
33
  return takeFromExternrefTable0(ret[0]);
37
34
  }
38
35
  /**
39
- * @param {Uint8Array | number[]} body
36
+ * @param {any} body
40
37
  * @param {bigint} timestamp
41
38
  * @param {string} signature
42
39
  * @param {bigint | null} [tolerance]
43
40
  * @returns {boolean}
44
41
  */
45
42
  verify(body, timestamp, signature, tolerance) {
46
- const val3 = BigInt.asIntN(64, timestamp);
47
- const val4 = BigInt.asIntN(64, (isLikeNone(tolerance) ? BigInt(0) : tolerance));
48
- let ptr0, len0, ptr1, len1;
49
- try {
50
- ptr0 = passArray8ToWasm0(body, wasm.__wbindgen_malloc);
51
- len0 = WASM_VECTOR_LEN;
52
- ptr1 = passStringToWasm0(signature, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
53
- len1 = WASM_VECTOR_LEN;
54
- } catch (e) {
55
- if (ptr1) { wasm.__wbindgen_free(ptr1, len1 * 1, 1); }
56
- if (ptr0) { wasm.__wbindgen_free(ptr0, len0 * 1, 1); }
57
- throw e;
58
- }
59
- const ret = wasm.hmacsha256signer_verify(this.__wbg_ptr, ptr0, len0, val3, ptr1, len1, !isLikeNone(tolerance), val4);
43
+ const val2 = BigInt.asIntN(64, timestamp);
44
+ const val3 = BigInt.asIntN(64, (isLikeNone(tolerance) ? BigInt(0) : tolerance));
45
+ const ptr0 = passStringToWasm0(signature, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
46
+ const len0 = WASM_VECTOR_LEN;
47
+ const ret = wasm.hmacsha256signer_verify(this.__wbg_ptr, body, val2, ptr0, len0, !isLikeNone(tolerance), val3);
60
48
  if (ret[2]) {
61
49
  throw takeFromExternrefTable0(ret[1]);
62
50
  }
@@ -64,6 +52,14 @@ export class HmacSha256Signer {
64
52
  }
65
53
  }
66
54
  if (Symbol.dispose) HmacSha256Signer.prototype[Symbol.dispose] = HmacSha256Signer.prototype.free;
55
+ export function __wbg___wbindgen_string_get_7ce8eee7fd327545(arg0, arg1) {
56
+ const obj = arg1;
57
+ const ret = typeof(obj) === 'string' ? obj : undefined;
58
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
59
+ var len1 = WASM_VECTOR_LEN;
60
+ getDataViewMemory0().setInt32((arg0 >>> 0) + 4 * 1, len1, true);
61
+ getDataViewMemory0().setInt32((arg0 >>> 0) + 4 * 0, ptr1, true);
62
+ }
67
63
  export function __wbg___wbindgen_throw_4c88d8bf264fd984(arg0, arg1) {
68
64
  throw new Error(getStringFromWasm0(arg0, arg1));
69
65
  }
@@ -71,10 +67,18 @@ export function __wbg_new_cd4348290afae586() {
71
67
  const ret = new Object();
72
68
  return ret;
73
69
  }
70
+ export function __wbg_now_463ac581d2fc7ea3() {
71
+ const ret = Date.now();
72
+ return ret;
73
+ }
74
74
  export function __wbg_set_2793479888329cb6() { return handleError(function (arg0, arg1, arg2) {
75
75
  const ret = Reflect.set(arg0, arg1, arg2);
76
76
  return ret;
77
77
  }, arguments); }
78
+ export function __wbg_stringify_0a0fbf2ef722380a() { return handleError(function (arg0) {
79
+ const ret = JSON.stringify(arg0);
80
+ return ret;
81
+ }, arguments); }
78
82
  export function __wbindgen_generic_0000000000000001(arg0) {
79
83
  // Cast intrinsic for `F64 -> Externref`.
80
84
  const ret = arg0;
@@ -103,6 +107,14 @@ function addToExternrefTable0(obj) {
103
107
  return idx;
104
108
  }
105
109
 
110
+ let cachedDataViewMemory0 = null;
111
+ function getDataViewMemory0() {
112
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
113
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
114
+ }
115
+ return cachedDataViewMemory0;
116
+ }
117
+
106
118
  function getStringFromWasm0(ptr, len) {
107
119
  ptr = ptr >>> 0;
108
120
  return decodeText(getUint8ArrayMemory0().subarray(ptr, ptr + len));
@@ -129,13 +141,6 @@ function isLikeNone(x) {
129
141
  return x === undefined || x === null;
130
142
  }
131
143
 
132
- function passArray8ToWasm0(arg, malloc) {
133
- const ptr = malloc(arg.length * 1, 1) >>> 0;
134
- getUint8ArrayMemory0().set(arg, ptr / 1);
135
- WASM_VECTOR_LEN = arg.length;
136
- return ptr;
137
- }
138
-
139
144
  function passStringToWasm0(arg, malloc, realloc) {
140
145
  if (realloc === undefined) {
141
146
  const buf = cachedTextEncoder.encode(arg);
Binary file
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "cleveng <cleveng@gmail.com>"
6
6
  ],
7
7
  "description": "Hmac Signer By Rust",
8
- "version": "1.0.2",
8
+ "version": "1.0.4",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",