Skip to content

Commit d5ac63a

Browse files
committed
0.4.0
1 parent c1f2b98 commit d5ac63a

17 files changed

+48
-30
lines changed

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ const challenge = await createChallenge({
2828
const ok = await verifySolution(payload, hmacKey);
2929
```
3030

31+
### Usage with Node.js 16
32+
33+
In Node.js version 16, there is no global reference to crypto by default. To use this library, you need to add the following code to your codebase:
34+
35+
```ts
36+
globalThis.crypto = require('node:crypto').webcrypto;
37+
```
38+
39+
Or with `import` syntax:
40+
41+
```ts
42+
import { webcrypto } from 'node:crypto';
43+
44+
globalThis.crypto = webcrypto;
45+
```
46+
3147
## API
3248

3349
### `createChallenge(options)`

cjs/dist/crypto.d.ts

-1
This file was deleted.

cjs/dist/crypto.js

-6
This file was deleted.

cjs/dist/helpers.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import './crypto.js';
21
import type { Algorithm } from './types.js';
32
export declare const encoder: TextEncoder;
43
export declare function ab2hex(ab: ArrayBuffer | Uint8Array): string;

cjs/dist/helpers.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
33
exports.randomInt = exports.randomBytes = exports.hmacHex = exports.hmac = exports.hashHex = exports.hash = exports.ab2hex = exports.encoder = void 0;
4-
// @denoify-line-ignore
5-
require("./crypto.js");
64
exports.encoder = new TextEncoder();
75
function ab2hex(ab) {
86
return [...new Uint8Array(ab)]

deno_dist/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ const challenge = await createChallenge({
2828
const ok = await verifySolution(payload, hmacKey);
2929
```
3030

31+
### Usage with Node.js 16
32+
33+
In Node.js version 16, there is no global reference to crypto by default. To use this library, you need to add the following code to your codebase:
34+
35+
```ts
36+
globalThis.crypto = require('node:crypto').webcrypto;
37+
```
38+
39+
Or with `import` syntax:
40+
41+
```ts
42+
import { webcrypto } from 'node:crypto';
43+
44+
globalThis.crypto = webcrypto;
45+
```
46+
3147
## API
3248

3349
### `createChallenge(options)`

deno_dist/crypto.ts

-4
This file was deleted.

dist/crypto.d.ts

-1
This file was deleted.

dist/crypto.js

-5
This file was deleted.

dist/helpers.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import './crypto.js';
21
import type { Algorithm } from './types.js';
32
export declare const encoder: TextEncoder;
43
export declare function ab2hex(ab: ArrayBuffer | Uint8Array): string;

dist/helpers.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @denoify-line-ignore
2-
import './crypto.js';
31
export const encoder = new TextEncoder();
42
export function ab2hex(ab) {
53
return [...new Uint8Array(ab)]

lib/crypto.ts

-4
This file was deleted.

lib/helpers.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @denoify-line-ignore
2-
import './crypto.js';
31
import type { Algorithm } from './types.js';
42

53
export const encoder = new TextEncoder();

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "altcha-lib",
3-
"version": "0.3.0",
3+
"version": "0.4.0",
44
"description": "A library for creating and verifying ALTCHA challenges for Node.js, Bun and Deno.",
55
"author": "Daniel Regeci",
66
"license": "MIT",

tests/challenge.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import {
88
} from '../lib/index.js';
99
import { Challenge } from '../lib/types.js';
1010

11+
if (!('crypto' in globalThis)) {
12+
// eslint-disable-next-line @typescript-eslint/no-var-requires
13+
globalThis.crypto = require('node:crypto').webcrypto;
14+
}
15+
1116
describe('challenge', () => {
1217
const hmacKey = 'test key';
1318

tests/helpers.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import {
77
randomInt,
88
} from '../lib/helpers.js';
99

10+
if (!('crypto' in globalThis)) {
11+
// eslint-disable-next-line @typescript-eslint/no-var-requires
12+
globalThis.crypto = require('node:crypto').webcrypto;
13+
}
14+
1015
const encoder = new TextEncoder();
1116

1217
describe('helpers', () => {

tests/serversignature.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import { describe, expect, it } from 'vitest';
22
import { verifyServerSignature } from '../lib/index.js';
33
import { hash, hmacHex } from '../lib/helpers.js';
44

5+
if (!('crypto' in globalThis)) {
6+
// eslint-disable-next-line @typescript-eslint/no-var-requires
7+
globalThis.crypto = require('node:crypto').webcrypto;
8+
}
9+
510
describe('server signature', () => {
611
const hmacKey = 'test key';
712

0 commit comments

Comments
 (0)