-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from VirgilSecurity/v4.0.0-alpha.3
v4.0.0-alpha.3
- Loading branch information
Showing
17 changed files
with
151 additions
and
51 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
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
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
This file was deleted.
Oops, something went wrong.
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
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,71 @@ | ||
export interface IPrivateKey {} | ||
|
||
export interface IPublicKey {} | ||
|
||
export interface IKeyPair { | ||
privateKey: IPrivateKey; | ||
publicKey: IPublicKey; | ||
} | ||
|
||
export interface ICrypto { | ||
generateKeys(keyPairType?: unknown): IKeyPair; | ||
generateKeysFromKeyMaterial(keyMaterial: Uint8Array, keyPairType?: unknown): IKeyPair; | ||
importPrivateKey(rawPrivateKey: Uint8Array): IPrivateKey; | ||
exportPrivateKey(privateKey: IPrivateKey): Uint8Array; | ||
importPublicKey(rawPublicKey: Uint8Array): IPublicKey; | ||
exportPublicKey(publicKey: IPublicKey): Uint8Array; | ||
encrypt(data: Uint8Array, publicKey: IPublicKey | IPublicKey[]): Uint8Array; | ||
decrypt(encryptedData: Uint8Array, privateKey: IPrivateKey): Uint8Array; | ||
calculateHash(data: Uint8Array, algorithm?: unknown): Uint8Array; | ||
extractPublicKey(privateKey: IPrivateKey): IPublicKey; | ||
calculateSignature(data: Uint8Array, privateKey: IPrivateKey): Uint8Array; | ||
verifySignature(data: Uint8Array, signature: Uint8Array, publicKey: IPublicKey): boolean; | ||
signThenEncrypt( | ||
data: Uint8Array, | ||
privateKey: IPrivateKey, | ||
publicKey: IPublicKey | IPublicKey[], | ||
): Uint8Array; | ||
decryptThenVerify( | ||
encryptedData: Uint8Array, | ||
privateKey: IPrivateKey, | ||
publicKey: IPublicKey | IPublicKey[], | ||
): Uint8Array; | ||
getRandomBytes(length: number): Uint8Array; | ||
signThenEncryptDetached( | ||
data: Uint8Array, | ||
privateKey: IPrivateKey, | ||
publicKey: IPublicKey | IPublicKey[], | ||
): { encryptedData: Uint8Array, metadata: Uint8Array }; | ||
decryptThenVerifyDetached( | ||
encryptedData: Uint8Array, | ||
metadata: Uint8Array, | ||
privateKey: IPrivateKey, | ||
publicKey: IPublicKey | IPublicKey[], | ||
): Uint8Array; | ||
} | ||
|
||
export interface IAccessTokenSigner { | ||
getAlgorithm(): string; | ||
generateTokenSignature( | ||
token: Uint8Array, | ||
privateKey: IPrivateKey, | ||
): Uint8Array; | ||
verifyTokenSignature( | ||
token: Uint8Array, | ||
signature: Uint8Array, | ||
publicKey: IPublicKey, | ||
): boolean; | ||
} | ||
|
||
export interface ICardCrypto { | ||
generateSignature(data: Uint8Array, privateKey: IPrivateKey): Uint8Array; | ||
verifySignature(data: Uint8Array, signature: Uint8Array, publicKey: IPublicKey): boolean; | ||
exportPublicKey(publicKey: IPublicKey): Uint8Array; | ||
importPublicKey(rawPublicKey: Uint8Array): IPublicKey; | ||
generateSha512(data: Uint8Array): Uint8Array; | ||
} | ||
|
||
export interface IPrivateKeyExporter { | ||
exportPrivateKey(privateKey: IPrivateKey): Uint8Array; | ||
importPrivateKey(rawPrivateKey: Uint8Array): IPrivateKey; | ||
} |
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,15 @@ | ||
{ | ||
"name": "@virgilsecurity/crypto-types", | ||
"version": "0.1.0", | ||
"description": "Types for Virgil JavaScript libraries", | ||
"typings": "./index.d.ts", | ||
"files": [ | ||
"index.d.ts" | ||
], | ||
"repository": "https://github.com/VirgilSecurity/virgil-crypto-javascript/tree/master/packages/crypto-types", | ||
"author": "Virgil Security Inc. <support@virgilsecurity.com>", | ||
"license": "BSD-3-Clause", | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,34 +1,39 @@ | ||
import { VirgilCrypto, VirgilPrivateKey, VirgilPublicKey } from '@virgilsecurity/base-crypto'; | ||
import { dataToUint8Array } from '@virgilsecurity/data-utils'; | ||
|
||
import { Data } from './types'; | ||
import { IPrivateKey, IPublicKey, ICrypto, ICardCrypto, Data } from './types'; | ||
|
||
export class VirgilCardCrypto { | ||
readonly virgilCrypto: VirgilCrypto; | ||
export class VirgilCardCrypto implements ICardCrypto { | ||
readonly virgilCrypto: ICrypto; | ||
|
||
constructor(virgilCrypto: VirgilCrypto) { | ||
constructor(virgilCrypto: ICrypto) { | ||
if (virgilCrypto == null) { | ||
throw new Error('`virgilCrypto` is required'); | ||
} | ||
this.virgilCrypto = virgilCrypto; | ||
} | ||
|
||
generateSignature(data: Data, privateKey: VirgilPrivateKey) { | ||
return this.virgilCrypto.calculateSignature(data, privateKey); | ||
generateSignature(data: Data, privateKey: IPrivateKey) { | ||
const myData = dataToUint8Array(data, 'utf8'); | ||
return this.virgilCrypto.calculateSignature(myData, privateKey); | ||
} | ||
|
||
verifySignature(data: Data, signature: Data, publicKey: VirgilPublicKey) { | ||
return this.virgilCrypto.verifySignature(data, signature, publicKey); | ||
verifySignature(data: Data, signature: Data, publicKey: IPublicKey) { | ||
const myData = dataToUint8Array(data, 'utf8'); | ||
const mySignature = dataToUint8Array(signature, 'base64'); | ||
return this.virgilCrypto.verifySignature(myData, mySignature, publicKey); | ||
} | ||
|
||
exportPublicKey(publicKey: VirgilPublicKey) { | ||
exportPublicKey(publicKey: IPublicKey) { | ||
return this.virgilCrypto.exportPublicKey(publicKey); | ||
} | ||
|
||
importPublicKey(publicKeyData: Data) { | ||
return this.virgilCrypto.importPublicKey(publicKeyData); | ||
const myPublicKeyData = dataToUint8Array(publicKeyData, 'base64'); | ||
return this.virgilCrypto.importPublicKey(myPublicKeyData); | ||
} | ||
|
||
generateSha512(data: Data) { | ||
return this.virgilCrypto.calculateHash(data, this.virgilCrypto.hashAlgorithm.SHA512); | ||
const myData = dataToUint8Array(data, 'utf8'); | ||
return this.virgilCrypto.calculateHash(myData); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,22 +1,23 @@ | ||
import { VirgilCrypto, VirgilPrivateKey } from '@virgilsecurity/base-crypto'; | ||
import { dataToUint8Array } from '@virgilsecurity/data-utils'; | ||
|
||
import { Data } from './types'; | ||
import { IPrivateKey, ICrypto, IPrivateKeyExporter, Data } from './types'; | ||
|
||
export class VirgilPrivateKeyExporter { | ||
readonly virgilCrypto: VirgilCrypto; | ||
export class VirgilPrivateKeyExporter implements IPrivateKeyExporter { | ||
readonly virgilCrypto: ICrypto; | ||
|
||
constructor(virgilCrypto: VirgilCrypto) { | ||
constructor(virgilCrypto: ICrypto) { | ||
if (virgilCrypto == null) { | ||
throw new Error('`virgilCrypto` is required'); | ||
} | ||
this.virgilCrypto = virgilCrypto; | ||
} | ||
|
||
exportPrivateKey(key: VirgilPrivateKey) { | ||
exportPrivateKey(key: IPrivateKey) { | ||
return this.virgilCrypto.exportPrivateKey(key); | ||
} | ||
|
||
importPrivateKey(keyData: Data) { | ||
return this.virgilCrypto.importPrivateKey(keyData); | ||
const myKeyData = dataToUint8Array(keyData, 'base64'); | ||
return this.virgilCrypto.importPrivateKey(myKeyData); | ||
} | ||
} |
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 |
---|---|---|
@@ -1 +1,8 @@ | ||
export type IPrivateKey = import('@virgilsecurity/crypto-types').IPrivateKey; | ||
export type IPublicKey = import('@virgilsecurity/crypto-types').IPublicKey; | ||
export type ICrypto = import('@virgilsecurity/crypto-types').ICrypto; | ||
export type IAccessTokenSigner = import('@virgilsecurity/crypto-types').IAccessTokenSigner; | ||
export type ICardCrypto = import('@virgilsecurity/crypto-types').ICardCrypto; | ||
export type IPrivateKeyExporter = import('@virgilsecurity/crypto-types').IPrivateKeyExporter; | ||
|
||
export type Data = import('@virgilsecurity/data-utils').Data; |
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