Skip to content

Commit

Permalink
0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ovx committed Jul 12, 2024
1 parent c1f2b98 commit d5ac63a
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 30 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ const challenge = await createChallenge({
const ok = await verifySolution(payload, hmacKey);
```

### Usage with Node.js 16

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:

```ts
globalThis.crypto = require('node:crypto').webcrypto;
```

Or with `import` syntax:

```ts
import { webcrypto } from 'node:crypto';

globalThis.crypto = webcrypto;
```

## API

### `createChallenge(options)`
Expand Down
1 change: 0 additions & 1 deletion cjs/dist/crypto.d.ts

This file was deleted.

6 changes: 0 additions & 6 deletions cjs/dist/crypto.js

This file was deleted.

1 change: 0 additions & 1 deletion cjs/dist/helpers.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import './crypto.js';
import type { Algorithm } from './types.js';
export declare const encoder: TextEncoder;
export declare function ab2hex(ab: ArrayBuffer | Uint8Array): string;
Expand Down
2 changes: 0 additions & 2 deletions cjs/dist/helpers.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.randomInt = exports.randomBytes = exports.hmacHex = exports.hmac = exports.hashHex = exports.hash = exports.ab2hex = exports.encoder = void 0;
// @denoify-line-ignore
require("./crypto.js");
exports.encoder = new TextEncoder();
function ab2hex(ab) {
return [...new Uint8Array(ab)]
Expand Down
16 changes: 16 additions & 0 deletions deno_dist/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ const challenge = await createChallenge({
const ok = await verifySolution(payload, hmacKey);
```

### Usage with Node.js 16

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:

```ts
globalThis.crypto = require('node:crypto').webcrypto;
```

Or with `import` syntax:

```ts
import { webcrypto } from 'node:crypto';

globalThis.crypto = webcrypto;
```

## API

### `createChallenge(options)`
Expand Down
4 changes: 0 additions & 4 deletions deno_dist/crypto.ts

This file was deleted.

1 change: 0 additions & 1 deletion dist/crypto.d.ts

This file was deleted.

5 changes: 0 additions & 5 deletions dist/crypto.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/helpers.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import './crypto.js';
import type { Algorithm } from './types.js';
export declare const encoder: TextEncoder;
export declare function ab2hex(ab: ArrayBuffer | Uint8Array): string;
Expand Down
2 changes: 0 additions & 2 deletions dist/helpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @denoify-line-ignore
import './crypto.js';
export const encoder = new TextEncoder();
export function ab2hex(ab) {
return [...new Uint8Array(ab)]
Expand Down
4 changes: 0 additions & 4 deletions lib/crypto.ts

This file was deleted.

2 changes: 0 additions & 2 deletions lib/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @denoify-line-ignore
import './crypto.js';
import type { Algorithm } from './types.js';

export const encoder = new TextEncoder();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "altcha-lib",
"version": "0.3.0",
"version": "0.4.0",
"description": "A library for creating and verifying ALTCHA challenges for Node.js, Bun and Deno.",
"author": "Daniel Regeci",
"license": "MIT",
Expand Down
5 changes: 5 additions & 0 deletions tests/challenge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import {
} from '../lib/index.js';
import { Challenge } from '../lib/types.js';

if (!('crypto' in globalThis)) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
globalThis.crypto = require('node:crypto').webcrypto;
}

describe('challenge', () => {
const hmacKey = 'test key';

Expand Down
5 changes: 5 additions & 0 deletions tests/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import {
randomInt,
} from '../lib/helpers.js';

if (!('crypto' in globalThis)) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
globalThis.crypto = require('node:crypto').webcrypto;
}

const encoder = new TextEncoder();

describe('helpers', () => {
Expand Down
5 changes: 5 additions & 0 deletions tests/serversignature.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { describe, expect, it } from 'vitest';
import { verifyServerSignature } from '../lib/index.js';
import { hash, hmacHex } from '../lib/helpers.js';

if (!('crypto' in globalThis)) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
globalThis.crypto = require('node:crypto').webcrypto;
}

describe('server signature', () => {
const hmacKey = 'test key';

Expand Down

0 comments on commit d5ac63a

Please sign in to comment.