Skip to content

Commit

Permalink
Merge pull request #1 from MariusVatasoiu/master
Browse files Browse the repository at this point in the history
Update deps to [email protected]
  • Loading branch information
iFaxity authored Feb 7, 2021
2 parents 13ee1ce + 486eb4b commit 9c9dfbb
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v2
- uses: denolib/setup-deno@master
with:
deno-version: 1.1.0
deno-version: 1.7.2

- run: deno --version
- run: deno fmt --check
Expand Down
56 changes: 28 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
keygrip
==========================
# keygrip

A verification mechanism using multiple different keys stored in a keychain to cryptographically sign data using SHA256 or SHA512 with HMAC. Code based on `https://github.com/crypto-utils/keygrip`.
A verification mechanism using multiple different keys stored in a keychain to
cryptographically sign data using SHA256 or SHA512 with HMAC. Code based on
`https://github.com/crypto-utils/keygrip`.


API
--------------------------
## API

```js
import { Keygrip, Algorithm } from 'https://deno.land/x/keygrip/mod.ts';
import { Algorithm, Keygrip } from "https://deno.land/x/keygrip/mod.ts";
```

### [keygrip = new Keygrip( keys [, algo=Algorithm.SHA256] )](#keygrip)

Creates a class for storing private keys in a keychain to easily hash and verify data with multiple different keys.
Creates a class for storing private keys in a keychain to easily hash and verify
data with multiple different keys.

**Returns:** A new instance of the keygrip class

#### Parameters
* `keys {string[]}` -
* `algo {Algorithm}` -

- `keys {string[]}` -
- `algo {Algorithm}` -

### [keygrip.sign( data [, key] )](#sign)

Expand All @@ -29,20 +29,23 @@ Cryptographically sign data by a secret key
**Returns:** a string with the signed hash of the data.

#### Parameters
* `data {string}` - Data to sign
* `key {string|number}` - If key is a number it resolves the key as an index in the keychain. If it is a string it is used directly. Defaults to first key in the keychain.

- `data {string}` - Data to sign
- `key {string|number}` - If key is a number it resolves the key as an index in
the keychain. If it is a string it is used directly. Defaults to first key in
the keychain.

### [keygrip.verify( data, digest )](#verify)

Verifies if the data matches the digest with any of the keys in the keychain.

**Returns:** A boolean if any key in the chain could be used to achieve the same digest.
**Returns:** A boolean if any key in the chain could be used to achieve the same
digest.

#### Parameters
* `data {string}` - Data to digest and verify
* `digest {string}` - Digested hash to compare against

- `data {string}` - Data to digest and verify
- `digest {string}` - Digested hash to compare against

### [keygrip.index( data, digest )](#index)

Expand All @@ -51,39 +54,36 @@ Resolve the index of which key was used to digest specified data.
**Returns:** A number from -1 to the last index of the keychain

#### Parameters
* `data {string}` - Data to digest
* `digest {string}` - Digested hash to compare against

- `data {string}` - Data to digest
- `digest {string}` - Digested hash to compare against

Examples
--------------------------
## Examples

```js
import { Keygrip, Algorithm } from 'https://deno.land/x/keygrip/mod.ts';
import { Algorithm, Keygrip } from "https://deno.land/x/keygrip/mod.ts";

// Uses sha256 by default, could be changed to sha512 with second parameter
const keygrip = new Keygrip([ 'shh', 'secret', 'keys' ]);
const keygrip = new Keygrip(["shh", "secret", "keys"]);

// Sign data with default key
const hash = keygrip.sign('some_important_data');
const hash = keygrip.sign("some_important_data");

// Verify the data using the hash
keygrip.verify('some_important_data', hash);
keygrip.verify("some_important_data", hash);
// returns true

// Get index of key in keygrip
keygrip.index('some_important_data', hash);
keygrip.index("some_important_data", hash);
// returns 0, for key at index 0 in the Keygrip keychain
```

Testing
--------------------------
## Testing

```sh
$ deno test
```

License
--------------------------
## License

[MIT](./LICENSE)
6 changes: 3 additions & 3 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// First party libraries
export { HmacSha256 } from "https://deno.land/std@v0.57.0/hash/sha256.ts";
export { HmacSha512 } from "https://deno.land/std@v0.57.0/hash/sha512.ts";
export * as base64url from "https://deno.land/std@v0.57.0/encoding/base64url.ts";
export { HmacSha256 } from "https://deno.land/std@0.86.0/hash/sha256.ts";
export { HmacSha512 } from "https://deno.land/std@0.86.0/hash/sha512.ts";
export * as base64url from "https://deno.land/std@0.86.0/encoding/base64url.ts";
4 changes: 2 additions & 2 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright(c) 2020 Christian Norrman
* MIT Licensed
*/
import { HmacSha256, HmacSha512, base64url } from "./deps.ts";
import { base64url, HmacSha256, HmacSha512 } from "./deps.ts";

/**
* Enum of supported algorithms for keygrip
Expand Down Expand Up @@ -61,7 +61,7 @@ export class Keygrip {
break;
}

return base64url.encode(buf);
return base64url.encode(new Uint8Array(buf));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
assert,
assertEquals,
} from "https://deno.land/std@v0.57.0/testing/asserts.ts";
import { Keygrip, Algorithm } from "./mod.ts";
} from "https://deno.land/std@0.86.0/testing/asserts.ts";
import { Algorithm, Keygrip } from "./mod.ts";
const { test } = Deno;

const keygrip = new Keygrip(["secret", "key", "right?"]);
Expand Down

0 comments on commit 9c9dfbb

Please sign in to comment.