@cakioe/hmac-signer 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +281 -2
- package/hmac_signer.d.ts +10 -0
- package/hmac_signer.js +9 -0
- package/hmac_signer_bg.js +198 -0
- package/hmac_signer_bg.wasm +0 -0
- package/package.json +24 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 cleveng
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,282 @@
|
|
|
1
|
-
#
|
|
1
|
+
# HMAC SHA256 Signer
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A lightweight HMAC-SHA256 signing and verification library written in Rust.
|
|
4
|
+
|
|
5
|
+
Supports both native Rust applications and WebAssembly (WASM), allowing the same implementation to be used in Rust, JavaScript, and TypeScript projects.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- HMAC-SHA256 signature generation.
|
|
10
|
+
- HMAC-SHA256 signature verification.
|
|
11
|
+
- Optional timestamp tolerance validation.
|
|
12
|
+
- Hexadecimal signature encoding.
|
|
13
|
+
- Constant-time signature verification.
|
|
14
|
+
- Native Rust library support.
|
|
15
|
+
- WebAssembly support.
|
|
16
|
+
- TypeScript type definitions through `wasm-bindgen`.
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
### Rust
|
|
21
|
+
|
|
22
|
+
Add the dependency to your `Cargo.toml`:
|
|
23
|
+
|
|
24
|
+
```toml
|
|
25
|
+
[dependencies]
|
|
26
|
+
hmac-signer = "1.0.0"
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### TypeScript / JavaScript
|
|
30
|
+
|
|
31
|
+
Install from npm:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
pnpm add hmac-signer
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Or:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm install hmac-signer
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Usage
|
|
44
|
+
|
|
45
|
+
### Rust usage
|
|
46
|
+
|
|
47
|
+
Import the signer:
|
|
48
|
+
|
|
49
|
+
```rust
|
|
50
|
+
use hmac_signer::{HmacSha256Signer, HmacSha256SignerTrait};
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
#### Create a signer
|
|
54
|
+
|
|
55
|
+
```rust
|
|
56
|
+
let signer = HmacSha256Signer::new("your-secret-key");
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
#### Generate a signature
|
|
60
|
+
|
|
61
|
+
```rust
|
|
62
|
+
let timestamp = 1793352268_i64;
|
|
63
|
+
let body = br#"{"amount":100,"currency":"USD"}"#;
|
|
64
|
+
|
|
65
|
+
let signature = signer.sign(timestamp, body)?;
|
|
66
|
+
|
|
67
|
+
println!("Signature: {}", signature);
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
#### Verify a signature
|
|
71
|
+
|
|
72
|
+
```rust
|
|
73
|
+
let valid = signer.verify(
|
|
74
|
+
timestamp,
|
|
75
|
+
body,
|
|
76
|
+
&signature,
|
|
77
|
+
Some(300),
|
|
78
|
+
)?;
|
|
79
|
+
|
|
80
|
+
println!("Valid: {}", valid);
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
#### Disable timestamp validation
|
|
84
|
+
|
|
85
|
+
Pass `None` as the tolerance parameter:
|
|
86
|
+
|
|
87
|
+
```rust
|
|
88
|
+
let valid = signer.verify(
|
|
89
|
+
timestamp,
|
|
90
|
+
body,
|
|
91
|
+
&signature,
|
|
92
|
+
None,
|
|
93
|
+
)?;
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### TypeScript / JavaScript usage
|
|
97
|
+
|
|
98
|
+
Import the signer:
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
import { HmacSha256Signer } from 'hmac-signer';
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
#### Create a signer by typescript
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
const signer = new HmacSha256Signer('your-secret-key');
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
#### Generate a signature by typescript
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
const timestamp = BigInt(Math.floor(Date.now() / 1000));
|
|
114
|
+
|
|
115
|
+
const body = new TextEncoder().encode(
|
|
116
|
+
JSON.stringify({
|
|
117
|
+
amount: 100,
|
|
118
|
+
currency: 'USD',
|
|
119
|
+
})
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
const signature = signer.sign(timestamp, body);
|
|
123
|
+
|
|
124
|
+
console.log(signature);
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
#### Verify a signature by typescript
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
const valid = signer.verify(timestamp, body, signature, 300n);
|
|
131
|
+
|
|
132
|
+
console.log(valid);
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
#### Disable timestamp validation by typescript
|
|
136
|
+
|
|
137
|
+
Pass `undefined`:
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
const valid = signer.verify(timestamp, body, signature, undefined);
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Signature Format
|
|
144
|
+
|
|
145
|
+
The signature is generated using HMAC-SHA256.
|
|
146
|
+
|
|
147
|
+
The signed message format is:
|
|
148
|
+
|
|
149
|
+
```text
|
|
150
|
+
timestamp + "." + request_body
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
The signature generation algorithm:
|
|
154
|
+
|
|
155
|
+
```text
|
|
156
|
+
HMAC-SHA256(
|
|
157
|
+
secret,
|
|
158
|
+
timestamp + "." + request_body
|
|
159
|
+
)
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
The resulting digest is encoded as a lowercase hexadecimal string.
|
|
163
|
+
|
|
164
|
+
Example:
|
|
165
|
+
|
|
166
|
+
```text
|
|
167
|
+
timestamp = 1793352268
|
|
168
|
+
body = {"amount":100}
|
|
169
|
+
|
|
170
|
+
message = 1793352268.{"amount":100}
|
|
171
|
+
|
|
172
|
+
signature = HMAC-SHA256(secret, message)
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Timestamp Tolerance
|
|
176
|
+
|
|
177
|
+
The `verify` method accepts an optional `tolerance` parameter.
|
|
178
|
+
|
|
179
|
+
| Parameter | Description |
|
|
180
|
+
| ----------- | ------------------------------------------------- |
|
|
181
|
+
| `Some(300)` | Allow a timestamp difference of up to 300 seconds |
|
|
182
|
+
| `Some(60)` | Allow a timestamp difference of up to 60 seconds |
|
|
183
|
+
| `Some(0)` | Require the timestamp to match the current second |
|
|
184
|
+
| `None` | Disable timestamp validation |
|
|
185
|
+
|
|
186
|
+
If the timestamp is outside the allowed window, verification returns an error.
|
|
187
|
+
|
|
188
|
+
## API Reference
|
|
189
|
+
|
|
190
|
+
### HmacSha256Signer
|
|
191
|
+
|
|
192
|
+
Creates an HMAC-SHA256 signer.
|
|
193
|
+
|
|
194
|
+
```rust
|
|
195
|
+
HmacSha256Signer::new(secret: impl Into<String>) -> Self
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### sign
|
|
199
|
+
|
|
200
|
+
Generates a signature.
|
|
201
|
+
|
|
202
|
+
```rust
|
|
203
|
+
fn sign(
|
|
204
|
+
&self,
|
|
205
|
+
timestamp: i64,
|
|
206
|
+
body: &[u8],
|
|
207
|
+
) -> Result<String, anyhow::Error>
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### verify
|
|
211
|
+
|
|
212
|
+
Verifies a signature.
|
|
213
|
+
|
|
214
|
+
```rust
|
|
215
|
+
fn verify(
|
|
216
|
+
&self,
|
|
217
|
+
timestamp: i64,
|
|
218
|
+
body: &[u8],
|
|
219
|
+
signature: &str,
|
|
220
|
+
tolerance: Option<i64>,
|
|
221
|
+
) -> Result<bool, anyhow::Error>
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Building from Source
|
|
225
|
+
|
|
226
|
+
### Native Rust
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
cargo build --release
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
Run tests:
|
|
233
|
+
|
|
234
|
+
```bash
|
|
235
|
+
cargo test
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### WebAssembly
|
|
239
|
+
|
|
240
|
+
Install the WASM target:
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
rustup target add wasm32-unknown-unknown
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
Install `wasm-pack`:
|
|
247
|
+
|
|
248
|
+
```bash
|
|
249
|
+
cargo install wasm-pack
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
Build the WASM package:
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
wasm-pack build --target bundler --release -- --features wasm
|
|
256
|
+
|
|
257
|
+
wasm-pack build \
|
|
258
|
+
--target bundler \
|
|
259
|
+
--release \
|
|
260
|
+
--scope cakioe \
|
|
261
|
+
--out-dir pkg \
|
|
262
|
+
--out-name hmac_signer \
|
|
263
|
+
-- --features wasm
|
|
264
|
+
|
|
265
|
+
cd pkg
|
|
266
|
+
npm stage publish --access public
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
The generated npm package will be available in the `pkg/` directory.
|
|
270
|
+
|
|
271
|
+
## Security Considerations
|
|
272
|
+
|
|
273
|
+
- Keep your secret key confidential.
|
|
274
|
+
- Always use HTTPS when transmitting signatures.
|
|
275
|
+
- Use timestamp validation to reduce replay attack risks.
|
|
276
|
+
- Verify the original raw request body instead of re-serialized JSON.
|
|
277
|
+
- Use sufficiently random secret keys.
|
|
278
|
+
- Implement replay protection when strict request uniqueness is required.
|
|
279
|
+
|
|
280
|
+
## License
|
|
281
|
+
|
|
282
|
+
MIT
|
package/hmac_signer.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
export class HmacSha256Signer {
|
|
5
|
+
free(): void;
|
|
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;
|
|
10
|
+
}
|
package/hmac_signer.js
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
export class HmacSha256Signer {
|
|
2
|
+
__destroy_into_raw() {
|
|
3
|
+
const ptr = this.__wbg_ptr;
|
|
4
|
+
this.__wbg_ptr = 0;
|
|
5
|
+
HmacSha256SignerFinalization.unregister(this);
|
|
6
|
+
return ptr;
|
|
7
|
+
}
|
|
8
|
+
free() {
|
|
9
|
+
const ptr = this.__destroy_into_raw();
|
|
10
|
+
wasm.__wbg_hmacsha256signer_free(ptr, 0);
|
|
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
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (Symbol.dispose) HmacSha256Signer.prototype[Symbol.dispose] = HmacSha256Signer.prototype.free;
|
|
78
|
+
export function __wbg___wbindgen_throw_4c88d8bf264fd984(arg0, arg1) {
|
|
79
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
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
|
+
}
|
|
86
|
+
export function __wbindgen_init_externref_table() {
|
|
87
|
+
const table = wasm.__wbindgen_externrefs;
|
|
88
|
+
table.set(0, undefined);
|
|
89
|
+
table.set(1024, undefined);
|
|
90
|
+
table.set(1025, null);
|
|
91
|
+
table.set(1026, true);
|
|
92
|
+
table.set(1027, false);
|
|
93
|
+
}
|
|
94
|
+
const HmacSha256SignerFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
95
|
+
? { register: () => {}, unregister: () => {} }
|
|
96
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_hmacsha256signer_free(ptr, 1));
|
|
97
|
+
|
|
98
|
+
function getStringFromWasm0(ptr, len) {
|
|
99
|
+
ptr = ptr >>> 0;
|
|
100
|
+
return decodeText(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
let cachedUint8ArrayMemory0 = null;
|
|
104
|
+
function getUint8ArrayMemory0() {
|
|
105
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
106
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
107
|
+
}
|
|
108
|
+
return cachedUint8ArrayMemory0;
|
|
109
|
+
}
|
|
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
|
+
|
|
165
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true });
|
|
166
|
+
cachedTextDecoder.decode();
|
|
167
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
168
|
+
let numBytesDecoded = 0;
|
|
169
|
+
function decodeText(bytes) {
|
|
170
|
+
numBytesDecoded += bytes.length;
|
|
171
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
172
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true });
|
|
173
|
+
cachedTextDecoder.decode();
|
|
174
|
+
numBytesDecoded = bytes.length;
|
|
175
|
+
}
|
|
176
|
+
return cachedTextDecoder.decode(bytes);
|
|
177
|
+
}
|
|
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
|
+
|
|
194
|
+
|
|
195
|
+
let wasm;
|
|
196
|
+
export function __wbg_set_wasm(val) {
|
|
197
|
+
wasm = val;
|
|
198
|
+
}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cakioe/hmac-signer",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
"type": "module",
|
|
4
|
+
"collaborators": [
|
|
5
|
+
"cleveng <cleveng@gmail.com>"
|
|
6
|
+
],
|
|
7
|
+
"description": "Hmac Signer By Rust",
|
|
8
|
+
"version": "1.0.1",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/cleveng/hmac-signer.git"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"hmac_signer_bg.wasm",
|
|
16
|
+
"hmac_signer.js",
|
|
17
|
+
"hmac_signer_bg.js",
|
|
18
|
+
"hmac_signer.d.ts"
|
|
19
|
+
],
|
|
20
|
+
"main": "hmac_signer.js",
|
|
21
|
+
"types": "hmac_signer.d.ts",
|
|
22
|
+
"sideEffects": [
|
|
23
|
+
"./hmac_signer.js",
|
|
24
|
+
"./snippets/*"
|
|
25
|
+
]
|
|
26
|
+
}
|