mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-16 19:09:18 +08:00
Merge pull request #10614 from PeculiarVentures/master
Update for 2.0.3
This commit is contained in:
74
base64url/base64url.d.ts
vendored
Normal file
74
base64url/base64url.d.ts
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
// Type definitions for base64url v2.0.0
|
||||
// Project: https://github.com/brianloveswords/base64url
|
||||
// Definitions by: Stepan Miroshin <https://github.com/microshine>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
/// <reference path="../node/node.d.ts" />
|
||||
|
||||
/**
|
||||
* For encoding and decoding base64url!
|
||||
* v2.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Encoding type
|
||||
*/
|
||||
declare type Encoding = "ascii" | "utf8" | "utf16le" | "ucs2" | "utf16le" | "base64" | "binary" | "hex"
|
||||
|
||||
interface IBase64Url {
|
||||
/**
|
||||
* Encode input to base64url
|
||||
* @param {string} input Incoming input
|
||||
* @param {Encoding} encoding Default 'utf8'
|
||||
* @return {string}
|
||||
*/
|
||||
(input: string, encoding?: Encoding): string;
|
||||
/**
|
||||
* Encode input to base64url
|
||||
* @param {Buffer} input Incoming value
|
||||
*/
|
||||
(inout: Buffer): string;
|
||||
/**
|
||||
* Encode input to base64url
|
||||
*
|
||||
* @param {string} input Incoming input
|
||||
* @param {Encoding} encoding Default 'utf8'
|
||||
* @returns {string}
|
||||
*/
|
||||
encode(input: string, encoding?: Encoding): string;
|
||||
/**
|
||||
* Encode input to base64url
|
||||
* @param {Buffer} input Incoming value
|
||||
*/
|
||||
encode(input: Buffer): string;
|
||||
/**
|
||||
* Convert a base64url encoded string into a raw string.
|
||||
* @param {string} base64url base64url encoded string
|
||||
* @param {Encoding} encoding Encoding defaults to 'utf8'
|
||||
* @returns {string}
|
||||
*/
|
||||
decode(base64url: string, encoding?: string): string;
|
||||
/**
|
||||
* Convert a base64url encoded string to a base64 encoded string
|
||||
* @param {string | Buffer} base64url base64url encoded value
|
||||
* @returns {string}
|
||||
*/
|
||||
toBase64(base64url: string | Buffer): string;
|
||||
/**
|
||||
* Convert a base64 encoded string to a base64url encoded string
|
||||
* @param {string} base64 encoded string
|
||||
* @returns {string}
|
||||
*/
|
||||
fromBase64(base64: string): string;
|
||||
/**
|
||||
* Convert a base64url encoded string to a Buffer
|
||||
* @param {string} base64url encoded string
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
toBuffer(base64url: string): Buffer;
|
||||
}
|
||||
|
||||
declare module "base64url" {
|
||||
const base64url: IBase64Url;
|
||||
export = base64url;
|
||||
}
|
||||
26
base64url/base64url.test.ts
Normal file
26
base64url/base64url.test.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
/// <reference path="./base64url.d.ts" />
|
||||
|
||||
import * as base64url from "base64url";
|
||||
|
||||
// default
|
||||
let str = base64url("some value");
|
||||
str = base64url("some value", "hex");
|
||||
str = base64url(new Buffer("some value"));
|
||||
|
||||
// encode
|
||||
str = base64url.encode("some value");
|
||||
str = base64url.encode("some value", "hex");
|
||||
str = base64url.encode(new Buffer("some value"));
|
||||
|
||||
// decode
|
||||
str = base64url.decode("ADA=");
|
||||
str = base64url.decode("ADA=", "binary");
|
||||
|
||||
// toBase64
|
||||
str = base64url.toBase64("ADA=");
|
||||
str = base64url.toBase64(new Buffer("ADA=", "base64"));
|
||||
|
||||
// fromBase64
|
||||
str = base64url.fromBase64("ADA=");
|
||||
|
||||
let buf = base64url.toBase64("ADA=");
|
||||
@@ -1,8 +1,6 @@
|
||||
/// <reference path="./graphene-pk11.d.ts" />
|
||||
|
||||
import * as graphene from "graphene-pk11";
|
||||
|
||||
// Example of Hashing from README.MD <https://github.com/PeculiarVentures/graphene#hashing>
|
||||
let Module = graphene.Module;
|
||||
|
||||
let lib = "/usr/local/lib/softhsm/libsofthsm2.so";
|
||||
@@ -13,13 +11,44 @@ mod.initialize();
|
||||
let slot = mod.getSlots(0);
|
||||
if (slot.flags & graphene.SlotFlag.TOKEN_PRESENT) {
|
||||
let session = slot.open();
|
||||
session.login("12345");
|
||||
|
||||
let digest = session.createDigest("sha1");
|
||||
digest.update("simple text 1");
|
||||
digest.update("simple text 2");
|
||||
let hash = digest.final();
|
||||
// generate EC key
|
||||
let keys = session.generateKeyPair(graphene.KeyGenMechanism.ECDSA, {
|
||||
keyType: graphene.KeyType.ECDSA,
|
||||
token: false,
|
||||
derive: true,
|
||||
paramsECDSA: graphene.NamedCurve.getByName("secp192r1").value
|
||||
}, {
|
||||
keyType: graphene.KeyType.ECDSA,
|
||||
token: false,
|
||||
derive: true
|
||||
});
|
||||
|
||||
console.log("Hash SHA1:", hash.toString("hex")); // Hash SHA1: e1dc1e52e9779cd69679b3e0af87d2e288190d34
|
||||
// derive algorithm
|
||||
let alg = {
|
||||
name: "ECDH1_DERIVE",
|
||||
params: new graphene.EcdhParams(
|
||||
graphene.EcKdf.SHA1,
|
||||
null,
|
||||
keys.publicKey.getAttribute({ pointEC: null }).pointEC)
|
||||
};
|
||||
|
||||
// Template for derived key
|
||||
let template = {
|
||||
"class": graphene.ObjectClass.SECRET_KEY,
|
||||
"token": false,
|
||||
"keyType": graphene.KeyType.AES,
|
||||
"valueLen": 256 / 8,
|
||||
"encrypt": true,
|
||||
"decrypt": true
|
||||
};
|
||||
|
||||
// Key derivation
|
||||
let dKey = session.deriveKey(alg, keys.privateKey, template);
|
||||
console.log("Derived key handle:", dKey.handle);
|
||||
|
||||
session.logout();
|
||||
session.close();
|
||||
}
|
||||
else {
|
||||
|
||||
2308
graphene-pk11/graphene-pk11.d.ts
vendored
2308
graphene-pk11/graphene-pk11.d.ts
vendored
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user