@owlmeans/basic-keys 0.1.18-rc.5 → 0.1.18-rc.50
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/README.md +12 -12
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/basic-keys/SKILL.md +43 -13
- package/build/auth/types.d.ts +10 -0
- package/build/auth/types.d.ts.map +1 -0
- package/build/auth/types.js +2 -0
- package/build/auth/types.js.map +1 -0
- package/build/auth.d.ts +3 -4
- package/build/auth.d.ts.map +1 -1
- package/build/auth.js +43 -39
- package/build/auth.js.map +1 -1
- package/build/bin.d.ts +1 -0
- package/build/bin.js +1 -0
- package/build/bin.js.map +1 -1
- package/build/helper/types.d.ts +11 -0
- package/build/helper/types.d.ts.map +1 -0
- package/build/helper/types.js +2 -0
- package/build/helper/types.js.map +1 -0
- package/build/helper.d.ts +4 -1
- package/build/helper.d.ts.map +1 -1
- package/build/helper.js +21 -15
- package/build/helper.js.map +1 -1
- package/build/index.d.ts +2 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js.map +1 -1
- package/build/keypair.js +2 -2
- package/build/keypair.js.map +1 -1
- package/build/model.d.ts +2 -2
- package/build/model.d.ts.map +1 -1
- package/build/model.js +16 -16
- package/build/model.js.map +1 -1
- package/build/plugins/ed25519.js +3 -3
- package/build/plugins/ed25519.js.map +1 -1
- package/build/plugins/xchacha.js +2 -2
- package/build/plugins/xchacha.js.map +1 -1
- package/build/utils/types.d.ts +16 -0
- package/build/utils/types.d.ts.map +1 -0
- package/build/utils/types.js +2 -0
- package/build/utils/types.js.map +1 -0
- package/build/utils.d.ts +3 -4
- package/build/utils.d.ts.map +1 -1
- package/build/utils.js +26 -22
- package/build/utils.js.map +1 -1
- package/package.json +10 -10
- package/src/auth/types.ts +17 -0
- package/src/auth.ts +51 -44
- package/src/bin.ts +1 -0
- package/src/helper/types.ts +11 -0
- package/src/helper.ts +26 -16
- package/src/index.ts +2 -0
- package/src/keypair.ts +2 -2
- package/src/model.ts +17 -17
- package/src/plugins/ed25519.ts +3 -3
- package/src/plugins/xchacha.ts +2 -2
- package/src/utils/types.ts +15 -0
- package/src/utils.ts +28 -21
- package/tests/auth.spec.ts +5 -5
- package/tests/keys.spec.ts +3 -3
- package/tests/known-answers.spec.ts +68 -0
- package/build/.gitkeep +0 -0
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ ED25519 and XChaCha20 cryptographic key operations: generation, signing, verific
|
|
|
12
12
|
## Installation
|
|
13
13
|
|
|
14
14
|
```bash
|
|
15
|
-
bun add @owlmeans/basic-keys
|
|
15
|
+
bun add @owlmeans/basic-keys@^0.1.18-rc.50
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
## Usage
|
|
@@ -32,19 +32,19 @@ const address = pair.exportAddress() // derive address from public key
|
|
|
32
32
|
Load from an existing public key:
|
|
33
33
|
|
|
34
34
|
```typescript
|
|
35
|
-
import {
|
|
35
|
+
import { keyHelper } from '@owlmeans/basic-keys'
|
|
36
36
|
|
|
37
|
-
const model = fromPubKey('ed25519:ABC123...')
|
|
38
|
-
const isMatch = matchAddress(knownAddress, publicKeyStr)
|
|
37
|
+
const model = keyHelper.fromPubKey('ed25519:ABC123...')
|
|
38
|
+
const isMatch = keyHelper.matchAddress(knownAddress, publicKeyStr)
|
|
39
39
|
```
|
|
40
40
|
|
|
41
41
|
Pack authentication credentials for a request:
|
|
42
42
|
|
|
43
43
|
```typescript
|
|
44
|
-
import {
|
|
44
|
+
import { authCredentialsHelper } from '@owlmeans/basic-keys'
|
|
45
45
|
|
|
46
|
-
const signed = await packAuthCredentials(authObj, extraData, keyPairModel)
|
|
47
|
-
const { isValid, extras } = await unpackAuthCredentials(signed, keyPairModel)
|
|
46
|
+
const signed = await authCredentialsHelper.packAuthCredentials(authObj, extraData, keyPairModel)
|
|
47
|
+
const { isValid, extras } = await authCredentialsHelper.unpackAuthCredentials(signed, keyPairModel)
|
|
48
48
|
```
|
|
49
49
|
|
|
50
50
|
## API
|
|
@@ -53,19 +53,19 @@ const { isValid, extras } = await unpackAuthCredentials(signed, keyPairModel)
|
|
|
53
53
|
|
|
54
54
|
Creates a `KeyPairModel` from an existing `KeyPair` object, encoded private key string, or algorithm type string. Generates a new ED25519 key pair when called with no arguments.
|
|
55
55
|
|
|
56
|
-
### `fromPubKey(pubKey, type?): KeyPairModel`
|
|
56
|
+
### `keyHelper.fromPubKey(pubKey, type?): KeyPairModel`
|
|
57
57
|
|
|
58
58
|
Creates a verify-only `KeyPairModel` from a public key string. Supports `"type:key"` format.
|
|
59
59
|
|
|
60
|
-
### `matchAddress(address, pubKey): boolean`
|
|
60
|
+
### `keyHelper.matchAddress(address, pubKey): boolean`
|
|
61
61
|
|
|
62
62
|
Returns true if `address` was derived from `pubKey`.
|
|
63
63
|
|
|
64
|
-
### `packAuthCredentials(auth, extra, signer): Promise<AuthCredentials>`
|
|
64
|
+
### `authCredentialsHelper.packAuthCredentials(auth, extra, signer): Promise<AuthCredentials>`
|
|
65
65
|
|
|
66
66
|
Signs auth credentials, optionally embedding extra data in the credential field.
|
|
67
67
|
|
|
68
|
-
### `unpackAuthCredentials(auth, verifier?): Promise<UnpackedAuthCredentials>`
|
|
68
|
+
### `authCredentialsHelper.unpackAuthCredentials(auth, verifier?): Promise<UnpackedAuthCredentials>`
|
|
69
69
|
|
|
70
70
|
Extracts and optionally verifies signed auth credentials. Returns `isValid` boolean when a verifier is provided.
|
|
71
71
|
|
|
@@ -89,7 +89,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
|
|
|
89
89
|
your project's skill store (`.agents/skills/`):
|
|
90
90
|
|
|
91
91
|
```sh
|
|
92
|
-
npx @owlmeans/agent-skills
|
|
92
|
+
npx @owlmeans/agent-skills@^0.1.18-rc.52
|
|
93
93
|
```
|
|
94
94
|
|
|
95
95
|
The embedded files are version-matched to this package release. Do not edit them
|
package/agent-meta/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 2,
|
|
3
3
|
"package": "@owlmeans/basic-keys",
|
|
4
|
-
"version": "0.1.18-rc.
|
|
5
|
-
"generatedAt": "2026-
|
|
4
|
+
"version": "0.1.18-rc.50",
|
|
5
|
+
"generatedAt": "2026-10-08T21:27:54.280Z",
|
|
6
6
|
"canonicalRepo": "https://github.com/owlmeans/common",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
@@ -8,7 +8,7 @@ user-invocable: false
|
|
|
8
8
|
# @owlmeans/basic-keys
|
|
9
9
|
|
|
10
10
|
**Layer:** Core
|
|
11
|
-
**Install:** `"@owlmeans/basic-keys": "^0.1.18-rc.
|
|
11
|
+
**Install:** `"@owlmeans/basic-keys": "^0.1.18-rc.50"` in `dependencies`
|
|
12
12
|
|
|
13
13
|
## Key Exports
|
|
14
14
|
|
|
@@ -18,13 +18,18 @@ user-invocable: false
|
|
|
18
18
|
| `KeyPair` | Key pair shape: `{ privateKey, publicKey, address, type }`, keys base64 |
|
|
19
19
|
| `KeyPairModel` | `sign` / `verify` / `encrypt` / `decrypt` / `dcrpt` / `export*` |
|
|
20
20
|
| `KeyType` | `ED25519` (`'ed25519'`, signing) and `XCHACHA` (`'xchacha'`, encryption) |
|
|
21
|
-
| `fromPubKey`, `matchAddress` | Verify-only model from a public key; address check |
|
|
22
|
-
| `auth`
|
|
21
|
+
| `keyHelper.fromPubKey(key, type?)`, `keyHelper.matchAddress(address, pubKey)` | Verify-only model from a public key; address check |
|
|
22
|
+
| `authCredentialsHelper.packAuthCredentials(auth, extra, signer)` | Sign a credential payload into `AuthCredentials.credential` |
|
|
23
|
+
| `authCredentialsHelper.unpackAuthCredentials(auth, verifier?)` | Split that back into `{ unsigned, signature, extras, isValid }` |
|
|
24
|
+
| `plugins` | The key-type registry, keyed by type string |
|
|
23
25
|
|
|
24
26
|
## Subpath Exports
|
|
25
27
|
|
|
26
|
-
- `./plugins` —
|
|
27
|
-
|
|
28
|
+
- `./plugins` — the individual plugins (`ed25519Plugin`, `xChahaPlugin`), the `plugins` registry
|
|
29
|
+
again, and the **`KeyPlugin` type**. `KeyPlugin` is *not* on the root surface: the root re-exports
|
|
30
|
+
only the registry value, so a package implementing a new key type imports the type from
|
|
31
|
+
`@owlmeans/basic-keys/plugins`.
|
|
32
|
+
- `./utils` — `keyUtils`: `assertType`, `prepareKey`, `prepareData`, `toAddress`
|
|
28
33
|
|
|
29
34
|
## Usage
|
|
30
35
|
|
|
@@ -53,14 +58,31 @@ Plain `Error` with a `basic.keys:<code>` message — this package does **not** u
|
|
|
53
58
|
|
|
54
59
|
| Code | Raised when |
|
|
55
60
|
|------|-------------|
|
|
56
|
-
| `basic.keys:
|
|
57
|
-
| `basic.keys:
|
|
61
|
+
| `basic.keys:unknown-type` | the key type is absent or has no plugin (see the guard order below) |
|
|
62
|
+
| `basic.keys:missing-pk` | `sign` on a model built from a `KeyPair` **object** whose `privateKey` is null or undefined |
|
|
58
63
|
| `basic.keys:sign-data-type` | data is neither string, object, nor `Uint8Array` |
|
|
59
64
|
| `basic.keys:decrypt-not-utf8` | plaintext is not valid UTF-8 (see below) |
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
65
|
+
| `ed25519:encryption-support` | `encrypt` or `decrypt` on an ed25519 model |
|
|
66
|
+
| `xchacha:signing` / `xchacha:verification` | `sign` or `verify` on an xchacha model |
|
|
67
|
+
|
|
68
|
+
Not every failure comes back as one of these, so do not match on a code where the underlying
|
|
69
|
+
library throws first:
|
|
70
|
+
|
|
71
|
+
- Signing with a **verify-only** model does not raise `basic.keys:missing-pk`.
|
|
72
|
+
`keyHelper.fromPubKey` stores `privateKey: ''`, which passes the null guard, and `@noble/curves`
|
|
73
|
+
rejects it as `private key of length 32 expected, got 0`.
|
|
74
|
+
- A string input that is neither a key type nor valid base64 fails in the decoder
|
|
75
|
+
(`Found a character that cannot be part of a valid base64 string`), never with a `basic.keys:`
|
|
76
|
+
code.
|
|
77
|
+
- The type check is not the first thing every method does. `export`, `exportPublic` and
|
|
78
|
+
`exportAddress` run it before anything else, but `sign`, `verify` and `encrypt` convert the payload
|
|
79
|
+
first — on a model whose type has no plugin, `sign(42)` throws `basic.keys:sign-data-type` while
|
|
80
|
+
`sign('ok')` throws `basic.keys:unknown-type` — and `decrypt`/`dcrpt` base64-decode the input
|
|
81
|
+
first, so a malformed ciphertext fails in the decoder.
|
|
82
|
+
|
|
83
|
+
## `@scure/base` — strict `utf8`
|
|
84
|
+
|
|
85
|
+
This package depends on `@scure/base` `^2.3.0`, whose `utf8` coder is strict: `encode` runs
|
|
64
86
|
`TextDecoder('utf-8', { ignoreBOM: true, fatal: true })` and throws on invalid bytes instead of
|
|
65
87
|
substituting `U+FFFD`, and `decode` rejects non-well-formed strings. `decrypt` therefore wraps its
|
|
66
88
|
`utf8.encode` call and rethrows as `basic.keys:decrypt-not-utf8`. Use `dcrpt` when the plaintext is
|
|
@@ -72,7 +94,15 @@ In practice a wrong key fails earlier: xchacha20-poly1305 is authenticated, so i
|
|
|
72
94
|
Callers that tolerate undecryptable values must catch — e.g. `@owlmeans/mongo` and
|
|
73
95
|
`@owlmeans/postgres` use `key.decrypt(value).catch(() => value)` for their encrypted-field paths.
|
|
74
96
|
|
|
97
|
+
## Signed credentials
|
|
98
|
+
|
|
99
|
+
`authCredentialsHelper.packAuthCredentials` canonicalizes the unsigned credentials plus your
|
|
100
|
+
extras, signs them, and returns `AuthCredentials` whose `credential` holds the signature (alone, or
|
|
101
|
+
folded into the extras). `authCredentialsHelper.unpackAuthCredentials` reverses it and — given a
|
|
102
|
+
verifier — reports `isValid`. Either side accepts a `KeyPairModel` or a bare sign/verify function,
|
|
103
|
+
so a caller that holds only a remote signer works the same way.
|
|
104
|
+
|
|
75
105
|
## Depends On
|
|
76
106
|
|
|
77
|
-
- `@owlmeans/auth` —
|
|
78
|
-
- `@noble/curves`, `@noble/ciphers`, `@noble/hashes`, `@scure/base
|
|
107
|
+
- `@owlmeans/auth` — `AuthCredentials`, the shape the auth helpers pack and unpack
|
|
108
|
+
- `@noble/curves`, `@noble/ciphers`, `@noble/hashes`, `@scure/base`, `canonicalize`
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AuthCredentials } from '@owlmeans/auth';
|
|
2
|
+
import type { KeyPairModel, PayloadSigner, PayloadVerifier, UnpackedAuthCredentials, UnsignedAuthCredentials } from '../types.js';
|
|
3
|
+
/** Signed authentication credentials: the signature packed into `credential` with any extras. */
|
|
4
|
+
export interface AuthCredentialsHelper {
|
|
5
|
+
/** Sign `auth` (plus canonicalized `extra`) and pack the signature into `credential`. */
|
|
6
|
+
packAuthCredentials: <T extends {} | undefined>(auth: UnsignedAuthCredentials, extra: T, signer: KeyPairModel | PayloadSigner) => Promise<AuthCredentials>;
|
|
7
|
+
/** Take packed credentials apart and, given a verifier, check the signature. */
|
|
8
|
+
unpackAuthCredentials: <T extends {} | undefined>(auth: AuthCredentials, verifier?: KeyPairModel | PayloadVerifier) => Promise<UnpackedAuthCredentials<T>>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/auth/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAEjI,iGAAiG;AACjG,MAAM,WAAW,qBAAqB;IACpC,yFAAyF;IACzF,mBAAmB,EAAE,CAAC,CAAC,SAAS,EAAE,GAAG,SAAS,EAC5C,IAAI,EAAE,uBAAuB,EAC7B,KAAK,EAAE,CAAC,EACR,MAAM,EAAE,YAAY,GAAG,aAAa,KACjC,OAAO,CAAC,eAAe,CAAC,CAAA;IAC7B,gFAAgF;IAChF,qBAAqB,EAAE,CAAC,CAAC,SAAS,EAAE,GAAG,SAAS,EAC9C,IAAI,EAAE,eAAe,EACrB,QAAQ,CAAC,EAAE,YAAY,GAAG,eAAe,KACtC,OAAO,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAA;CACzC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/auth/types.ts"],"names":[],"mappings":""}
|
package/build/auth.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const unpackAuthCredentials: <T extends {} | undefined>(auth: AuthCredentials, verifier?: KeyPairModel | PayloadVerifier) => Promise<UnpackedAuthCredentials<T>>;
|
|
1
|
+
import type { AuthCredentialsHelper } from './auth/types.js';
|
|
2
|
+
export declare const createAuthCredentialsHelper: () => AuthCredentialsHelper;
|
|
3
|
+
export declare const authCredentialsHelper: AuthCredentialsHelper;
|
|
5
4
|
//# sourceMappingURL=auth.d.ts.map
|
package/build/auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAE5D,eAAO,MAAM,2BAA2B,QAAO,qBA2D9C,CAAA;AAED,eAAO,MAAM,qBAAqB,uBAAgC,CAAA"}
|
package/build/auth.js
CHANGED
|
@@ -1,45 +1,49 @@
|
|
|
1
1
|
import canonicalize from 'canonicalize';
|
|
2
|
-
export const
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const signature = await signer(unsigned);
|
|
12
|
-
return {
|
|
13
|
-
...auth,
|
|
14
|
-
credential: extra == null ? signature : canonicalize({ ...extra, signature }),
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
export const unpackAuthCredentials = async (auth, verifier) => {
|
|
18
|
-
let signature = '';
|
|
19
|
-
let extras;
|
|
20
|
-
try {
|
|
21
|
-
extras = JSON.parse(auth.credential);
|
|
22
|
-
if (typeof extras === 'object' && extras != null && "signature" in extras) {
|
|
23
|
-
signature = extras.signature;
|
|
24
|
-
delete extras.signature;
|
|
2
|
+
export const createAuthCredentialsHelper = () => {
|
|
3
|
+
const packAuthCredentials = async (auth, extra, signer) => {
|
|
4
|
+
const unsigned = {
|
|
5
|
+
...auth,
|
|
6
|
+
...(extra == null ? {} : { credential: canonicalize(extra) })
|
|
7
|
+
};
|
|
8
|
+
if (typeof signer !== 'function') {
|
|
9
|
+
const _signer = signer;
|
|
10
|
+
signer = async (payload) => await _signer.sign(payload);
|
|
25
11
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const unsigned = {
|
|
32
|
-
...auth,
|
|
33
|
-
...(extras == null ? {} : { credential: canonicalize(extras) })
|
|
12
|
+
const signature = await signer(unsigned);
|
|
13
|
+
return {
|
|
14
|
+
...auth,
|
|
15
|
+
credential: extra == null ? signature : canonicalize({ ...extra, signature }),
|
|
16
|
+
};
|
|
34
17
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
18
|
+
const unpackAuthCredentials = async (auth, verifier) => {
|
|
19
|
+
let signature = '';
|
|
20
|
+
let extras;
|
|
21
|
+
try {
|
|
22
|
+
extras = JSON.parse(auth.credential);
|
|
23
|
+
if (typeof extras === 'object' && extras != null && "signature" in extras) {
|
|
24
|
+
signature = extras.signature;
|
|
25
|
+
delete extras.signature;
|
|
26
|
+
}
|
|
40
27
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
28
|
+
catch {
|
|
29
|
+
signature = auth.credential;
|
|
30
|
+
extras = undefined;
|
|
31
|
+
}
|
|
32
|
+
const unsigned = {
|
|
33
|
+
...auth,
|
|
34
|
+
...(extras == null ? {} : { credential: canonicalize(extras) })
|
|
35
|
+
};
|
|
36
|
+
let isValid = undefined;
|
|
37
|
+
if (verifier != null) {
|
|
38
|
+
if (typeof verifier !== 'function') {
|
|
39
|
+
const _verifier = verifier;
|
|
40
|
+
verifier = async (payload, signature) => await _verifier.verify(payload, signature);
|
|
41
|
+
}
|
|
42
|
+
isValid = await verifier(unsigned, signature);
|
|
43
|
+
}
|
|
44
|
+
return { unsigned, signature, isValid, extras };
|
|
45
|
+
};
|
|
46
|
+
return { packAuthCredentials, unpackAuthCredentials };
|
|
44
47
|
};
|
|
48
|
+
export const authCredentialsHelper = createAuthCredentialsHelper();
|
|
45
49
|
//# sourceMappingURL=auth.js.map
|
package/build/auth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAEA,OAAO,YAAY,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAEA,OAAO,YAAY,MAAM,cAAc,CAAA;AAGvC,MAAM,CAAC,MAAM,2BAA2B,GAAG,GAA0B,EAAE;IACrE,MAAM,mBAAmB,GAAG,KAAK,EAC/B,IAA6B,EAC7B,KAAQ,EACR,MAAoC,EACV,EAAE;QAC5B,MAAM,QAAQ,GAA4B;YACxC,GAAG,IAAI;YACP,GAAG,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,YAAY,CAAC,KAAK,CAAW,EAAE,CAAC;SACxE,CAAA;QAED,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;YACjC,MAAM,OAAO,GAAG,MAAM,CAAA;YACtB,MAAM,GAAG,KAAK,EAAC,OAA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KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,CAAC,MAAM,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;YACrF,CAAC;YAED,OAAO,GAAG,MAAM,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;QAC/C,CAAC;QAED,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,CAAA;IACjD,CAAC,CAAA;IAED,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,CAAA;AACvD,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,qBAAqB,GAAG,2BAA2B,EAAE,CAAA"}
|
package/build/bin.d.ts
CHANGED
package/build/bin.js
CHANGED
package/build/bin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAE7C,MAAM,OAAO,GAAG,gBAAgB,EAAE,CAAA;AAElC,OAAO,CAAC,IAAI,CAAC,kBAAkB,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;AAClD,OAAO,CAAC,IAAI,CAAC,iBAAiB,EAAE,OAAO,CAAC,YAAY,EAAE,CAAC,CAAA;AACvD,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE,OAAO,CAAC,aAAa,EAAE,CAAC,CAAA;AAGrD,MAAM,UAAU,GAAG,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;AACpD,OAAO,CAAC,IAAI,CAAC,qBAAqB,EAAE,UAAU,CAAC,MAAM,EAAE,CAAC,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { KeyPairModel } from '../types.js';
|
|
2
|
+
/** Key models built from what a peer publishes: its public key and its address. */
|
|
3
|
+
export interface KeyHelper {
|
|
4
|
+
/**
|
|
5
|
+
* A verify-only key model of a public key, `<type>:<key>` or a bare key (ed25519 by default).
|
|
6
|
+
*/
|
|
7
|
+
fromPubKey: (pubKey: string, type?: string) => KeyPairModel;
|
|
8
|
+
/** Whether an address is the one the public key derives to. */
|
|
9
|
+
matchAddress: (address: string, pubKey: string) => boolean;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/helper/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,mFAAmF;AACnF,MAAM,WAAW,SAAS;IACxB;;OAEG;IACH,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,KAAK,YAAY,CAAA;IAC3D,+DAA+D;IAC/D,YAAY,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAA;CAC3D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/helper/types.ts"],"names":[],"mappings":""}
|
package/build/helper.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { KeyPairModel } from './types.js';
|
|
2
|
+
import type { KeyHelper } from './helper/types.js';
|
|
3
|
+
export declare const createKeyHelper: () => KeyHelper;
|
|
4
|
+
export declare const keyHelper: KeyHelper;
|
|
5
|
+
/** @deprecated compat:factory-refactor — use `keyHelper.fromPubKey(…)` */
|
|
2
6
|
export declare const fromPubKey: (pubKey: string, type?: string) => KeyPairModel;
|
|
3
|
-
export declare const matchAddress: (address: string, pubKey: string) => boolean;
|
|
4
7
|
//# sourceMappingURL=helper.d.ts.map
|
package/build/helper.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAW,YAAY,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAW,YAAY,EAAE,MAAM,YAAY,CAAA;AAEvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAElD,eAAO,MAAM,eAAe,QAAO,SAwBlC,CAAA;AAED,eAAO,MAAM,SAAS,WAAoB,CAAA;AAE1C,0EAA0E;AAC1E,eAAO,MAAM,UAAU,WAAY,MAAM,SAAS,MAAM,KAAG,YAAkD,CAAA"}
|
package/build/helper.js
CHANGED
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
import { KeyType } from './consts.js';
|
|
2
2
|
import { makeKeyPairModel } from './model.js';
|
|
3
3
|
import { plugins } from './plugins/index.js';
|
|
4
|
-
import {
|
|
5
|
-
export const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
pubKey
|
|
10
|
-
|
|
4
|
+
import { keyUtils } from './utils.js';
|
|
5
|
+
export const createKeyHelper = () => {
|
|
6
|
+
const fromPubKey = (pubKey, type) => {
|
|
7
|
+
if (type == null) {
|
|
8
|
+
[type, pubKey] = pubKey.includes(':') ? pubKey.split(':', 2) : [KeyType.ED25519, pubKey];
|
|
9
|
+
if (pubKey == null) {
|
|
10
|
+
pubKey = type;
|
|
11
|
+
type = KeyType.ED25519;
|
|
12
|
+
}
|
|
11
13
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
const keyPair = {
|
|
15
|
+
privateKey: '',
|
|
16
|
+
publicKey: pubKey,
|
|
17
|
+
type,
|
|
18
|
+
address: plugins[type].toAdress(keyUtils.prepareKey(pubKey))
|
|
19
|
+
};
|
|
20
|
+
return makeKeyPairModel(keyPair);
|
|
18
21
|
};
|
|
19
|
-
|
|
22
|
+
const matchAddress = (address, pubKey) => address === fromPubKey(pubKey).exportAddress();
|
|
23
|
+
return { fromPubKey, matchAddress };
|
|
20
24
|
};
|
|
21
|
-
export const
|
|
25
|
+
export const keyHelper = createKeyHelper();
|
|
26
|
+
/** @deprecated compat:factory-refactor — use `keyHelper.fromPubKey(…)` */
|
|
27
|
+
export const fromPubKey = (pubKey, type) => keyHelper.fromPubKey(pubKey, type);
|
|
22
28
|
//# sourceMappingURL=helper.js.map
|
package/build/helper.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAE5C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../src/helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACrC,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAE5C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAGrC,MAAM,CAAC,MAAM,eAAe,GAAG,GAAc,EAAE;IAC7C,MAAM,UAAU,GAAG,CAAC,MAAc,EAAE,IAAa,EAAgB,EAAE;QACjE,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;YACjB,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;YACxF,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;gBACnB,MAAM,GAAG,IAAI,CAAA;gBACb,IAAI,GAAG,OAAO,CAAC,OAAO,CAAA;YACxB,CAAC;QACH,CAAC;QAED,MAAM,OAAO,GAAY;YACvB,UAAU,EAAE,EAAE;YACd,SAAS,EAAE,MAAM;YACjB,IAAI;YACJ,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;SAC7D,CAAA;QAED,OAAO,gBAAgB,CAAC,OAAO,CAAC,CAAA;IAClC,CAAC,CAAA;IAED,MAAM,YAAY,GAAG,CAAC,OAAe,EAAE,MAAc,EAAW,EAAE,CAChE,OAAO,KAAK,UAAU,CAAC,MAAM,CAAC,CAAC,aAAa,EAAE,CAAA;IAEhD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,CAAA;AACrC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,eAAe,EAAE,CAAA;AAE1C,0EAA0E;AAC1E,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,MAAc,EAAE,IAAa,EAAgB,EAAE,CAAC,SAAS,CAAC,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA"}
|
package/build/index.d.ts
CHANGED
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,YAAY,CAAA;AAC/B,mBAAmB,mBAAmB,CAAA;AACtC,mBAAmB,iBAAiB,CAAA;AAEpC,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,oBAAoB,CAAA"}
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,oBAAoB,CAAA"}
|
package/build/keypair.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { base64 } from '@scure/base';
|
|
2
2
|
import { KeyType } from './consts.js';
|
|
3
3
|
import { plugins } from './plugins/index.js';
|
|
4
|
-
import {
|
|
4
|
+
import { keyUtils } from './utils.js';
|
|
5
5
|
export const inputToKeyPair = (input) => {
|
|
6
6
|
let type = KeyType.ED25519;
|
|
7
7
|
let keyPair = null;
|
|
@@ -29,7 +29,7 @@ export const inputToKeyPair = (input) => {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
if (keyPair == null) {
|
|
32
|
-
assertType(type);
|
|
32
|
+
keyUtils.assertType(type);
|
|
33
33
|
if (primaryKey == null) {
|
|
34
34
|
primaryKey = plugins[type].random();
|
|
35
35
|
}
|
package/build/keypair.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keypair.js","sourceRoot":"","sources":["../src/keypair.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAC5C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,CAAC;IACH,CAAC;IACD,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;QACpB,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;QACzB,IAAI,UAAU,IAAI,IAAI,EAAE,CAAC;YACvB,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAA;QACrC,CAAC;QACD,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAA;QACpD,OAAO,GAAG;YACR,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC;YACrC,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC;YACnC,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC;YAC1C,IAAI;SACL,CAAA;IACH,CAAC;IAED,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA"}
|
package/build/model.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const makeKeyPairModel:
|
|
1
|
+
import type { KeyPair, KeyPairModel } from './types.js';
|
|
2
|
+
export declare const makeKeyPairModel: (input?: KeyPair | string) => KeyPairModel;
|
|
3
3
|
//# sourceMappingURL=model.d.ts.map
|
package/build/model.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAMvD,eAAO,MAAM,gBAAgB,WAAY,OAAO,GAAG,MAAM,KAAG,YAmH3D,CAAA"}
|
package/build/model.js
CHANGED
|
@@ -1,59 +1,59 @@
|
|
|
1
1
|
import { plugins } from './plugins/index.js';
|
|
2
2
|
import { base64urlnopad, utf8 } from '@scure/base';
|
|
3
|
-
import {
|
|
3
|
+
import { keyUtils } from './utils.js';
|
|
4
4
|
import { inputToKeyPair } from './keypair.js';
|
|
5
|
-
export const makeKeyPairModel = input => {
|
|
5
|
+
export const makeKeyPairModel = (input) => {
|
|
6
6
|
const keyPair = inputToKeyPair(input);
|
|
7
7
|
const _model = {
|
|
8
8
|
keyPair,
|
|
9
9
|
sign: async (data) => {
|
|
10
|
-
data = prepareData(data);
|
|
11
|
-
assertType(_model.keyPair?.type);
|
|
10
|
+
data = keyUtils.prepareData(data);
|
|
11
|
+
keyUtils.assertType(_model.keyPair?.type);
|
|
12
12
|
if (_model.keyPair == null) {
|
|
13
13
|
throw new Error('basic.keys:missing-keypair');
|
|
14
14
|
}
|
|
15
15
|
if (_model.keyPair.privateKey == null) {
|
|
16
16
|
throw new Error('basic.keys:missing-pk');
|
|
17
17
|
}
|
|
18
|
-
return base64urlnopad.encode(plugins[_model.keyPair.type].sign(data, prepareKey(_model.keyPair.privateKey)));
|
|
18
|
+
return base64urlnopad.encode(plugins[_model.keyPair.type].sign(data, keyUtils.prepareKey(_model.keyPair.privateKey)));
|
|
19
19
|
},
|
|
20
20
|
verify: async (data, signature) => {
|
|
21
|
-
data = prepareData(data);
|
|
22
|
-
assertType(_model.keyPair?.type);
|
|
21
|
+
data = keyUtils.prepareData(data);
|
|
22
|
+
keyUtils.assertType(_model.keyPair?.type);
|
|
23
23
|
const sig = base64urlnopad.decode(signature);
|
|
24
24
|
if (_model.keyPair == null) {
|
|
25
25
|
throw new Error('basic.keys:missing-keypair');
|
|
26
26
|
}
|
|
27
|
-
return plugins[_model.keyPair.type].verify(data, sig, prepareKey(_model.keyPair.publicKey));
|
|
27
|
+
return plugins[_model.keyPair.type].verify(data, sig, keyUtils.prepareKey(_model.keyPair.publicKey));
|
|
28
28
|
},
|
|
29
29
|
export: () => {
|
|
30
|
-
assertType(_model.keyPair?.type);
|
|
30
|
+
keyUtils.assertType(_model.keyPair?.type);
|
|
31
31
|
if (_model.keyPair == null) {
|
|
32
32
|
throw new Error('basic.keys:missing-keypair');
|
|
33
33
|
}
|
|
34
34
|
return `${_model.keyPair.type}:${_model.keyPair.privateKey}`;
|
|
35
35
|
},
|
|
36
36
|
exportPublic: () => {
|
|
37
|
-
assertType(_model.keyPair?.type);
|
|
37
|
+
keyUtils.assertType(_model.keyPair?.type);
|
|
38
38
|
if (_model.keyPair == null) {
|
|
39
39
|
throw new Error('basic.keys:missing-keypair');
|
|
40
40
|
}
|
|
41
41
|
return `${_model.keyPair.type}:${_model.keyPair.publicKey}`;
|
|
42
42
|
},
|
|
43
43
|
exportAddress: () => {
|
|
44
|
-
assertType(_model.keyPair?.type);
|
|
44
|
+
keyUtils.assertType(_model.keyPair?.type);
|
|
45
45
|
if (_model.keyPair == null) {
|
|
46
46
|
throw new Error('basic.keys:missing-keypair');
|
|
47
47
|
}
|
|
48
48
|
return `${_model.keyPair.type}:${_model.keyPair.address}`;
|
|
49
49
|
},
|
|
50
50
|
encrypt: async (data) => {
|
|
51
|
-
data = prepareData(data);
|
|
52
|
-
assertType(_model.keyPair?.type);
|
|
51
|
+
data = keyUtils.prepareData(data);
|
|
52
|
+
keyUtils.assertType(_model.keyPair?.type);
|
|
53
53
|
if (_model.keyPair == null) {
|
|
54
54
|
throw new Error('basic.keys:missing-keypair');
|
|
55
55
|
}
|
|
56
|
-
return base64urlnopad.encode(plugins[_model.keyPair.type].encrypt(data, prepareKey(_model.keyPair.publicKey)));
|
|
56
|
+
return base64urlnopad.encode(plugins[_model.keyPair.type].encrypt(data, keyUtils.prepareKey(_model.keyPair.publicKey)));
|
|
57
57
|
},
|
|
58
58
|
decrypt: async (data) => {
|
|
59
59
|
const plain = await _model.dcrpt(data);
|
|
@@ -68,11 +68,11 @@ export const makeKeyPairModel = input => {
|
|
|
68
68
|
},
|
|
69
69
|
dcrpt: async (data) => {
|
|
70
70
|
data = data instanceof Uint8Array ? data : base64urlnopad.decode(data);
|
|
71
|
-
assertType(_model.keyPair?.type);
|
|
71
|
+
keyUtils.assertType(_model.keyPair?.type);
|
|
72
72
|
if (_model.keyPair == null) {
|
|
73
73
|
throw new Error('basic.keys:missing-keypair');
|
|
74
74
|
}
|
|
75
|
-
return plugins[_model.keyPair.type].decrypt(data, prepareKey(_model.keyPair.privateKey));
|
|
75
|
+
return plugins[_model.keyPair.type].decrypt(data, keyUtils.prepareKey(_model.keyPair.privateKey));
|
|
76
76
|
}
|
|
77
77
|
};
|
|
78
78
|
return _model;
|
package/build/model.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.js","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAC5C,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAC5C,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAE7C,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAwB,EAAgB,EAAE;IACzE,MAAM,OAAO,GAAG,cAAc,CAAC,KAAK,CAAC,CAAA;IAErC,MAAM,MAAM,GAAiB;QAC3B,OAAO;QAEP,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;YACnB,IAAI,GAAG,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;YACjC,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;YAEzC,IAAI,MAAM,CAAC,OAAO,IAA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C,CAC9C,CACF,CAAA;QACH,CAAC;QAED,OAAO,EAAE,KAAK,EAAC,IAAI,EAAC,EAAE;YACpB,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;YACtC,IAAI,CAAC;gBACH,sEAAsE;gBACtE,yEAAyE;gBACzE,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;YAC3B,CAAC;YAAC,MAAM,CAAC;gBACP,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAA;YAChD,CAAC;QACH,CAAC;QAED,KAAK,EAAE,KAAK,EAAC,IAAI,EAAC,EAAE;YAClB,IAAI,GAAG,IAAI,YAAY,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,IAAc,CAAC,CAAA;YAChF,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;YAEzC,IAAI,MAAM,CAAC,OAAO,IAAI,IAAI,EAAE,CAAC;gBAC3B,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAA;YAC/C,CAAC;YAED,OAAO,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,CACzC,IAAkB,EAClB,QAAQ,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAC/C,CAAA;QACH,CAAC;KACF,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
|
package/build/plugins/ed25519.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { KeyType } from '../consts.js';
|
|
2
|
-
import { ed25519 } from '@noble/curves/ed25519';
|
|
2
|
+
import { ed25519 } from '@noble/curves/ed25519.js';
|
|
3
3
|
import { base58 } from '@scure/base';
|
|
4
|
-
import { keccak_256 } from '@noble/hashes/sha3';
|
|
4
|
+
import { keccak_256 } from '@noble/hashes/sha3.js';
|
|
5
5
|
export const ed25519Plugin = {
|
|
6
6
|
type: KeyType.ED25519,
|
|
7
|
-
random: () => ed25519.utils.
|
|
7
|
+
random: () => ed25519.utils.randomSecretKey(),
|
|
8
8
|
sign: (data, pk) => ed25519.sign(data, pk),
|
|
9
9
|
verify: (data, signature, pub) => ed25519.verify(signature, data, pub),
|
|
10
10
|
toPublic: pk => ed25519.getPublicKey(pk),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ed25519.js","sourceRoot":"","sources":["../../src/plugins/ed25519.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,OAAO,EAAE,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"ed25519.js","sourceRoot":"","sources":["../../src/plugins/ed25519.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAElD,MAAM,CAAC,MAAM,aAAa,GAAc;IACtC,IAAI,EAAE,OAAO,CAAC,OAAO;IAErB,MAAM,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,eAAe,EAAE;IAE7C,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;IAE1C,MAAM,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,EAAE,GAAG,CAAC;IAEtE,QAAQ,EAAE,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;IAExC,QAAQ,EAAE,GAAG,CAAC,EAAE,CAAC,MA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