-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7272d97
commit 45a9045
Showing
4 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { AsnIntegerConverter, AsnProp, AsnPropTypes, AsnSerializer, AsnType, AsnTypeTypes } from "@peculiar/asn1-schema"; | ||
import { IJsonConvertible } from "@peculiar/json-schema"; | ||
import { Convert } from "pvtsutils"; | ||
|
||
@AsnType({ type: AsnTypeTypes.Choice }) | ||
export class EdPrivateKey implements IJsonConvertible { | ||
|
||
@AsnProp({ type: AsnPropTypes.OctetString }) | ||
public value = new ArrayBuffer(0); | ||
|
||
public fromJSON(json: any): this { | ||
if (!json.d) { | ||
throw new Error("d: Missing required property"); | ||
} | ||
this.value = Convert.FromBase64Url(json.d); | ||
|
||
return this; | ||
} | ||
public toJSON() { | ||
const jwk: JsonWebKey = { | ||
d: Convert.ToBase64Url(this.value), | ||
}; | ||
|
||
return jwk; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { AsnProp, AsnPropTypes, AsnType, AsnTypeTypes } from "@peculiar/asn1-schema"; | ||
import { IJsonConvertible } from "@peculiar/json-schema"; | ||
import { Convert } from "pvtsutils"; | ||
import { CryptoError } from "../errors"; | ||
|
||
// RFC 8410 | ||
// https://datatracker.ietf.org/doc/html/rfc8410 | ||
// | ||
// PublicKey ::= BIT STRING | ||
|
||
@AsnType({ type: AsnTypeTypes.Choice }) | ||
export class EdPublicKey implements IJsonConvertible { | ||
|
||
@AsnProp({ type: AsnPropTypes.BitString }) | ||
public value = new ArrayBuffer(0); | ||
|
||
constructor(value?: ArrayBuffer) { | ||
if (value) { | ||
this.value = value; | ||
} | ||
} | ||
|
||
public toJSON() { | ||
const json = { | ||
x: Convert.ToBase64Url(this.value), | ||
}; | ||
|
||
return json; | ||
} | ||
|
||
public fromJSON(json: any): this { | ||
if (!("x" in json)) { | ||
throw new Error("x: Missing required property"); | ||
} | ||
|
||
this.value = Convert.FromBase64Url(json.x); | ||
|
||
return this; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { AsnProp, AsnPropTypes } from "@peculiar/asn1-schema"; | ||
import { PrivateKeyInfo } from "./private_key_info"; | ||
|
||
/** | ||
* ```asn | ||
* OneAsymmetricKey ::= SEQUENCE { | ||
* version Version, | ||
* privateKeyAlgorithm PrivateKeyAlgorithmIdentifier, | ||
* privateKey PrivateKey, | ||
* attributes [0] IMPLICIT Attributes OPTIONAL, | ||
* ..., | ||
* [[2: publicKey [1] IMPLICIT PublicKey OPTIONAL ]], | ||
* ... | ||
* } | ||
* | ||
* PrivateKey ::= OCTET STRING | ||
* | ||
* PublicKey ::= BIT STRING | ||
* ``` | ||
*/ | ||
export class OneAsymmetricKey extends PrivateKeyInfo { | ||
|
||
@AsnProp({ context: 1, implicit: true, type: AsnPropTypes.BitString, optional: true }) | ||
public publicKey?: ArrayBuffer; | ||
|
||
} |