From f0990e288ac73d593e982995947567aa2643b828 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lachance Date: Fri, 5 Aug 2016 12:40:35 -0400 Subject: [PATCH 01/41] + Add mapObject in the _ChainOfArrays interface since it works fine on runtime --- underscore/underscore-tests.ts | 11 +++++++++++ underscore/underscore.d.ts | 1 + 2 files changed, 12 insertions(+) diff --git a/underscore/underscore-tests.ts b/underscore/underscore-tests.ts index 26718207d8..951c41bf9f 100644 --- a/underscore/underscore-tests.ts +++ b/underscore/underscore-tests.ts @@ -505,6 +505,17 @@ function chain_tests() { var firstVal: number = _.chain([1, 2, 3]) .first() .value(); + + interface NumberObject { + property: string; + value: number; + } + let numberObjects: NumberObject[] = [{property: 'odd', value: 1}, {property: 'even', value: 2}, {property: 'even', value: 0}]; + let evenNumbers: NumberObject[][] = _.chain(numberObjects) + .groupBy('property') + .mapObject((objects: any) => _.sortBy(objects, (object: NumberObject) => object.value)) + .values() + .value(); } var obj: { [k: string] : number } = { diff --git a/underscore/underscore.d.ts b/underscore/underscore.d.ts index 708d7a34d6..cb5dfaa393 100644 --- a/underscore/underscore.d.ts +++ b/underscore/underscore.d.ts @@ -5924,6 +5924,7 @@ interface _ChainSingle { } interface _ChainOfArrays extends _Chain { flatten(shallow?: boolean): _Chain; + mapObject(fn: _.ListIterator): _ChainOfArrays; } declare var _: UnderscoreStatic; From a6b3f7257a56d0f708ef8d76218c0c9da2ffe37f Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lachance Date: Fri, 5 Aug 2016 13:47:59 -0400 Subject: [PATCH 02/41] * Simplify with a more explicit example --- underscore/underscore-tests.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/underscore/underscore-tests.ts b/underscore/underscore-tests.ts index 951c41bf9f..fd335b7361 100644 --- a/underscore/underscore-tests.ts +++ b/underscore/underscore-tests.ts @@ -506,16 +506,11 @@ function chain_tests() { .first() .value(); - interface NumberObject { - property: string; - value: number; - } - let numberObjects: NumberObject[] = [{property: 'odd', value: 1}, {property: 'even', value: 2}, {property: 'even', value: 0}]; - let evenNumbers: NumberObject[][] = _.chain(numberObjects) + let numberObjects = [{property: 'odd', value: 1}, {property: 'even', value: 2}, {property: 'even', value: 0}]; + let evenAndOddGroupedNumbers = _.chain(numberObjects) .groupBy('property') - .mapObject((objects: any) => _.sortBy(objects, (object: NumberObject) => object.value)) - .values() - .value(); + .mapObject((objects: any) => _.pluck(objects, 'value')) + .value(); // { odd: [1], even: [0, 2] } } var obj: { [k: string] : number } = { From 0d001a04a13ddc7d14c4163fbdb0af44ccda31e0 Mon Sep 17 00:00:00 2001 From: Nicholas Iannone Date: Mon, 8 Aug 2016 10:44:38 -0500 Subject: [PATCH 03/41] Started preliminary work on Twilio Node API typedefs. --- twilio/twilio-tests.ts | 17 ++++ twilio/twilio.d.ts | 213 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 230 insertions(+) create mode 100644 twilio/twilio-tests.ts create mode 100644 twilio/twilio.d.ts diff --git a/twilio/twilio-tests.ts b/twilio/twilio-tests.ts new file mode 100644 index 0000000000..9af07e7c27 --- /dev/null +++ b/twilio/twilio-tests.ts @@ -0,0 +1,17 @@ +/// + +var str: string; + +const client = new twilio.RestClient(str, str); +const account = client.accounts(str); + +account.messages.post({ + body: str, + from: str, + to: str +}); + +account.sms.messages(str).get(function(err, data) { + // Do nothing +}); + diff --git a/twilio/twilio.d.ts b/twilio/twilio.d.ts new file mode 100644 index 0000000000..69331e86ca --- /dev/null +++ b/twilio/twilio.d.ts @@ -0,0 +1,213 @@ +/// +/// + + +/// index.js +export class twilio extends RestClient { + constructor(sid?: string, tkn?: string, options?: ClientOptions); +} + +export namespace twilio { + + // Composite Classes: + //============================== + // RestClient + // PricingClient + // MonitorClient + // TaskRouterClient + // IpMessagingClient + // LookupsClient + // TrunkingClient + + // Classes: + //============================== + // AccessToken + // Capability + // TaskRouterCapability + // TaskRouterWorkerCapability + // TaskRouterWorkspaceCapability + // TaskRouterTaskQueueCapability + // TwimlResponse + // webhook + + // Methods: + //=============================== + // validateRequest + // validateExpressRequest +} + + +/// ??? +declare interface GrantPayload {} + +declare interface Grant { + toPayload(): GrantPayload; +} + +declare interface RequestCallback { (err: any, data: any, response: ): void } + +/// AccessToken.js +declare interface IpMessagingGrantOptions { + serviceSid: string; + endpointId: string; + deploymentRoleSid: string; + pushCredentialSid: string; +} + +declare interface IpMessagingGrantPayload extends GrantPayload { + service_sid: string; + endpoint_id: string; + deployment_role_sid: string; + push_credential_sid: string; +} + +declare class IpMessagingGrant implements Grant { + serviceSid: string; + endpointId: string; + deploymentRoleSid: string; + pushCredentialSid: string; + key: string; + + constructor(options?: IpMessagingGrantOptions); + + toPayload(): IpMessagingGrantPayload; +} + +declare interface ConversationsGrantOptions { + configurationProfileSid: string; +} + +declare interface ConversationsGrantPayload extends GrantPayload { + configuration_profile_sid: string; +} + +declare class ConversationsGrant implements Grant { + configurationProfileSid: string; + + constructor(options?: ConversationsGrantOptions); + + toPayload(): ConversationsGrantPayload; +} + +declare interface AccessTokenOptions { + ttl: number; + identity: string; + nbf: number; +} + +declare class AccessToken { + accountSid: string; + keySid: string; + secret: string; + ttl: number; + identity: string; + nbf: number; + grants: Array; + + static IpMessagingGrant: IpMessagingGrant; + static ConversationGrant: ConversationsGrant; + static DEFAULT_ALGORITHM: string; + static ALGORITHMS: Array; + + constructor(accountSid: string, keySid: string, secret: string, opts?: AccessTokenOptions); + + addGrant(grant: Grant): void; + toJwt(algorithm: string): any; // TODO Find correct typedef +} + +/// Capability.js +declare class Capability { + accountSid: string; + authToken: string; + capabilities: Array; + clientName: string; + outgoingScopeParams: any; + scopeParams: any; + + constructor(sid?: string, tkn?: string); + + allowClientIncoming(clientName: string): Capability; + allowClientOutgoing(appSid: string, params?: any): Capability; + allowEventStream(filters?: any): Capability; + generate(timeout?: number): string; +} + +/// Client.js +declare interface ClientOptions { + host?: string; + apiVersion?: string; + timeout?: number; +} + +declare interface ClientRequestOptions { + url: string; + form?: any; +} + +declare class Client { + accountSid: string; + authToken: string; + host: string; + apiVersion: string; + timeout: number; + + constructor(sid?: string, tkn?: string, host?: string, api_version?: string, timeout?: number); + + getBaseUrl(): string; + request(options: ClientRequestOptions, callback: RequestCallback): Q.Promise; +} + +/// IpMessagingClient.js +declare class IpMessagingClient extends Client { + services: ServiceResource; + credentials: CredentialsResource; + + constructor(sid?: string, tkn?: string, options?: ClientOptions); +} + +/// LookupsClient.js +declare class LookupsClient extends Client { + phoneNumbers: PhoneNumbersResource; + + constructor(sid?: string, tkn?: string, options?: ClientOptions); +} + +/// MonitorClient.js +declare class MonitorClient extends Client implements EventResource, AlertResource { + events: EventResource; + alerts: AlertResource; + + constructor(sid?: string, tkn?: string, options?: ClientOptions); +} + +/// PricingClient.js +declare class PricingClient extends Client { + voice: VoiceResource; + phoneNumbers: PhoneNumbersResource; + messaging: MessagingResource; + + constructor(sid?: string, tkn?: string, options?: ClientOptions); +} + +/// RestClient.js +declare class RestClient extends Client implements AccountResource { + accounts: AccountResource; + + // Messaging shorthand + // TODO Pull in proper method signatures here! + sendSms(); + sendMms(); + sendMessage(); + listSms(); + listMessages(); + getSms(messageSid: string, callback: (/* ??? */) => void): void; + getMessage(messageSid: string, callback: (/* ??? */) => void): void; + + // Calls shorthand + // TODO Pull in proper method signatures here! + makeCall(); + listCalls(); + getCall(callSid: string, callback: (/* ??? */) => void): void; + + request(options: ClientRequestOptions, callback: RequestCallback): Q.Promise; +} \ No newline at end of file From d0b1b909633503f1d061bf78f1c0d08200777ce9 Mon Sep 17 00:00:00 2001 From: Nicholas Iannone Date: Mon, 8 Aug 2016 16:48:38 -0500 Subject: [PATCH 04/41] Fleshed out more of Twilio Node API. --- twilio/twilio.d.ts | 1025 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 887 insertions(+), 138 deletions(-) diff --git a/twilio/twilio.d.ts b/twilio/twilio.d.ts index 69331e86ca..d3a3bda26b 100644 --- a/twilio/twilio.d.ts +++ b/twilio/twilio.d.ts @@ -1,11 +1,15 @@ +/// /// /// +import * as Http from 'http'; /// index.js +/* export class twilio extends RestClient { constructor(sid?: string, tkn?: string, options?: ClientOptions); } +*/ export namespace twilio { @@ -27,187 +31,932 @@ export namespace twilio { // TaskRouterWorkerCapability // TaskRouterWorkspaceCapability // TaskRouterTaskQueueCapability - // TwimlResponse + // TwimlResponse (TODO main export is generator function) // webhook // Methods: //=============================== // validateRequest // validateExpressRequest -} -/// ??? -declare interface GrantPayload {} -declare interface Grant { - toPayload(): GrantPayload; -} + /// ??? + export interface GrantPayload {} -declare interface RequestCallback { (err: any, data: any, response: ): void } + export interface Grant { + toPayload(): GrantPayload; + } -/// AccessToken.js -declare interface IpMessagingGrantOptions { - serviceSid: string; - endpointId: string; - deploymentRoleSid: string; - pushCredentialSid: string; -} + export interface RequestCallback { (err: any, data: any, response: Http.ClientResponse): void; } + export interface BaseRequestCallback { (err: any, data: any): void; } -declare interface IpMessagingGrantPayload extends GrantPayload { - service_sid: string; - endpoint_id: string; - deployment_role_sid: string; - push_credential_sid: string; -} + export interface RestMethod { (args: any | BaseRequestCallback, callback?: RequestCallback): Q.Promise; } -declare class IpMessagingGrant implements Grant { - serviceSid: string; - endpointId: string; - deploymentRoleSid: string; - pushCredentialSid: string; - key: string; + /// AccessToken.js + export interface IpMessagingGrantOptions { + serviceSid: string; + endpointId: string; + deploymentRoleSid: string; + pushCredentialSid: string; + } - constructor(options?: IpMessagingGrantOptions); + export interface IpMessagingGrantPayload extends GrantPayload { + service_sid: string; + endpoint_id: string; + deployment_role_sid: string; + push_credential_sid: string; + } - toPayload(): IpMessagingGrantPayload; -} + export class IpMessagingGrant implements Grant { + serviceSid: string; + endpointId: string; + deploymentRoleSid: string; + pushCredentialSid: string; + key: string; -declare interface ConversationsGrantOptions { - configurationProfileSid: string; -} + constructor(options?: IpMessagingGrantOptions); -declare interface ConversationsGrantPayload extends GrantPayload { - configuration_profile_sid: string; -} + toPayload(): IpMessagingGrantPayload; + } -declare class ConversationsGrant implements Grant { - configurationProfileSid: string; + export interface ConversationsGrantOptions { + configurationProfileSid: string; + } - constructor(options?: ConversationsGrantOptions); + export interface ConversationsGrantPayload extends GrantPayload { + configuration_profile_sid: string; + } - toPayload(): ConversationsGrantPayload; -} + export class ConversationsGrant implements Grant { + configurationProfileSid: string; -declare interface AccessTokenOptions { - ttl: number; - identity: string; - nbf: number; -} + constructor(options?: ConversationsGrantOptions); -declare class AccessToken { - accountSid: string; - keySid: string; - secret: string; - ttl: number; - identity: string; - nbf: number; - grants: Array; + toPayload(): ConversationsGrantPayload; + } - static IpMessagingGrant: IpMessagingGrant; - static ConversationGrant: ConversationsGrant; - static DEFAULT_ALGORITHM: string; - static ALGORITHMS: Array; + export interface AccessTokenOptions { + ttl: number; + identity: string; + nbf: number; + } - constructor(accountSid: string, keySid: string, secret: string, opts?: AccessTokenOptions); + export class AccessToken { + accountSid: string; + keySid: string; + secret: string; + ttl: number; + identity: string; + nbf: number; + grants: Array; - addGrant(grant: Grant): void; - toJwt(algorithm: string): any; // TODO Find correct typedef -} + static IpMessagingGrant: IpMessagingGrant; + static ConversationGrant: ConversationsGrant; + static DEFAULT_ALGORITHM: string; + static ALGORITHMS: Array; -/// Capability.js -declare class Capability { - accountSid: string; - authToken: string; - capabilities: Array; - clientName: string; - outgoingScopeParams: any; - scopeParams: any; + constructor(accountSid: string, keySid: string, secret: string, opts?: AccessTokenOptions); + + addGrant(grant: Grant): void; + toJwt(algorithm: string): any; // TODO Find correct typedef + } + + /// Capability.js + export class Capability { + accountSid: string; + authToken: string; + capabilities: Array; + clientName: string; + outgoingScopeParams: any; + scopeParams: any; + + constructor(sid?: string, tkn?: string); + + allowClientIncoming(clientName: string): Capability; + allowClientOutgoing(appSid: string, params?: any): Capability; + allowEventStream(filters?: any): Capability; + generate(timeout?: number): string; + } + + /// Client.js + export interface ClientOptions { + host?: string; + apiVersion?: string; + timeout?: number; + } + + export interface ClientRequestOptions { + url: string; + form?: any; + } + + export class Client { + accountSid: string; + authToken: string; + host: string; + apiVersion: string; + timeout: number; + + constructor(sid?: string, tkn?: string, host?: string, api_version?: string, timeout?: number); + + getBaseUrl(): string; + request(options: ClientRequestOptions, callback?: RequestCallback): Q.Promise; + } + + /// IpMessagingClient.js + export class IpMessagingClient extends Client { + services: ServiceResource; + credentials: CredentialResource; + + constructor(sid?: string, tkn?: string, options?: ClientOptions); + } + + /// LookupsClient.js + export class LookupsClient extends Client { + phoneNumbers: PhoneNumberResource; + + constructor(sid?: string, tkn?: string, options?: ClientOptions); + } + + /// MonitorClient.js + export class MonitorClient extends Client implements EventResource, AlertResource { + events: EventResource; + alerts: AlertResource; + + constructor(sid?: string, tkn?: string, options?: ClientOptions); + } + + /// PricingClient.js + export class PricingClient extends Client { + voice: VoiceResource; + phoneNumbers: PhoneNumberResource; + messaging: MessagingResource; + + constructor(sid?: string, tkn?: string, options?: ClientOptions); + } + + /// RestClient.js + export class RestClient extends Client implements AccountResource { + accounts: AccountResource; + + // Imported from AccountResource + availablePhoneNumbers: AvailablePhoneNumberResource; + outgoingCallerIds: OutgoingCallerIdResource; + incomingPhoneNumbers: IncomingPhoneNumberResource; + messages: MessageResource; + sms: SMSIntermediary; + applications: ApplicationResource; + connectApps: ConnectAppResource; + authorizedConnectApps: AuthorizedConnectAppResource; + calls: CallResource; + conferences: ConferenceResource; + queues: QueueResource; + recordings: RecordingResource; + tokens: TokenResource; + transcriptions: TranscriptionResource; + notifications: NotificationResource; + usage: UsageIntermediary; + sip: SIPIntermediary; + addresses: AddressResource; + keys: KeyResource; + + // Mixed-in Methods + put: RestMethod; + post: RestMethod; + get: RestMethod; + update: RestMethod; + list: RestMethod; + + // Messaging shorthand + // TODO Pull in proper method signatures here! + sendSms(); + sendMms(); + sendMessage(); + listSms(); + listMessages(); + getSms(messageSid: string, callback?: RequestCallback): Q.Promise; + getMessage(messageSid: string, callback?: RequestCallback): Q.Promise; + + // Calls shorthand + // TODO Pull in proper method signatures here! + makeCall(); + listCalls(); + getCall(callSid: string, callback?: RequestCallback): Q.Promise; + + // Overrides Client.request(...) + request(options: ClientRequestOptions, callback?: RequestCallback): Q.Promise; + } + + /// TaskRouterCapability.js + export interface QueryFilter { + // TODO Populate me! + } + + export interface PostFilter { + // TODO Populate me! + } + + export interface Policy { + url: string; + method: string; + query_filter?: QueryFilter; + post_filter?: PostFilter; + allow: boolean; + } + + export class TaskRouterCapability { + accountSid: string; + authToken: string; + policies: Array; + workspaceSid: string; + channelId: string; + + private _baseUrl: string; + private _resourceUrl: string; + + constructor(accountSid: string, authToken: string, workspaceSid: string, channelId: string); + + protected _setupResource(): void; + private _validateJWT(): void; + private _generate(ttl: number, extraAttributes: any): string; + + allowFetchSubresources(): void; + allowUpdates(): void; + allowUpdatesSubresources(): void; + allowDelete(): void; + allowDeleteSubresources(): void; + allowWorkerActivityUpdates(): void; + allowWorkerFetchAttributes(): void; + allowTaskReservationUpdates(): void; + + addPolicy(url: string, method: string, allowed?: boolean, queryFilter?: QueryFilter, postFilter?: PostFilter): void; + allow(url: string, method: string, queryFilter?: QueryFilter, postFilter?: PostFilter): void; + deny(url: string, method: string, queryFilter?: QueryFilter, postFilter?: PostFilter): void; + generate(ttl: number): string; + } + + /// TaskRouterClient.js + export class TaskRouterClient extends Client implements WorkspaceResource { + workspaces: WorkspaceResource; + workspace: WorkspaceResource; + + constructor(sid?: string, tkn?: string, workspaceSid?: string, options?: ClientOptions); + } + + /// TaskRouterTaskQueueCapability.js + export class TaskRouterTaskQueueCapability extends TaskRouterCapability { + constructor(accountSid: string, authToken: string, workspaceSid: string, taskQueueSid: string); + + protected _setupResource(): void; + } + + /// TaskRouterWorkerCapability.js + export class TaskRouterWorkerCapability extends TaskRouterCapability { + reservationsUrl: string; + activityUrl: string; + workerReservationsUrl: string; + + constructor(accountSid: string, authToken: string, workspaceSid: string, workerSid: string); + + protected _setupResource(): void; + + allowActivityUpdates(): void; + allowReservationUpdates(): void; + } + + /// TaskRouterWorkspaceCapability.js + export class TaskRouterWorkspaceCapability extends TaskRouterCapability { + constructor(accountSid: string, authToken: string, workspaceSid: string); + + protected _setupResource(): void; + } + + /// TrunkingClient.js + export class TrunkingClient extends Client { + trunks: TrunkResource; + + constructor(sid?: string, tkn?: string, options?: ClientOptions); + } + + /// TwimlResponse.js + // ???? - Someone else should look at this thing to make sure it's correct + export interface NodeOptions { + name: string; + attributes?: any; + text?: string; + topLevel?: boolean; + legalNodes: Array; + } + + export class Node implements NodeOptions { + name: string; + attributes: any; + text: any; + topLevel: boolean; + legalNodes: Array; + + constructor(config?: NodeOptions); + + toString(): string; + } + + export function TwimlResponse(): Node; + + /// webhook.js + export interface webhookOptions { + validate?: boolean; + includeHelpers?: boolean; + host?: string; + protocol?: string; + } + + export interface WebhookExpressOptions { + // The full URL (with query string) you used to configure the webhook with Twilio - overrides host/protocol options + url?: string; + + // manually specify the host name used by Twilio in a number's webhook config + host?: string; + + // manually specify the protocol used by Twilio in a number's webhook config + protocol?: string; + } + + // For interop with node middleware chains + export interface MiddlewareFunction { (request: Http.ClientRequest, response: Http.ClientResponse, next: MiddlewareFunction): void; } + + export function webhook(options?: string | webhookOptions): MiddlewareFunction; + + export function validateRequest(authToken: string, twilioHeader: string, url: string, params?: any): boolean; + export function validateExpressRequest(request: Express.Request, authToken: string, options?: WebhookExpressOptions): boolean; + + /// resources/Accounts.js + export interface OutgoingCallerIdInstance { + get: RestMethod; + post: RestMethod; + put: RestMethod; + delete: RestMethod; + update: RestMethod; + } + + export interface OutgoingCallerIdResource { + (resourceSid: string): OutgoingCallerIdInstance; + get: RestMethod; + post: RestMethod; + create: RestMethod; + } + + export interface SMSMessageInstance { + get: RestMethod; + } + + export interface SMSMessageResource { + (resourceSid: string): SMSMessageInstance; + get: RestMethod; + post: RestMethod; + create: RestMethod; + } + + export interface SMSShortCodeInstance { + get: RestMethod; + post: RestMethod; + update: RestMethod; + } + + export interface SMSShortCodeResource { + get: RestMethod; + } + + export interface SMSIntermediary { + messages: SMSMessageResource; + shortCodes: SMSShortCodeResource; + } + + export interface ApplicationInstance { + get: RestMethod; + post: RestMethod; + delete: RestMethod; + update: RestMethod; + } + + export interface ApplicationResource { + (resourceSid: string): ApplicationInstance; + get: RestMethod; + post: RestMethod; + create: RestMethod; + } + + export interface ConnectAppInstance { + get: RestMethod; + post: RestMethod; + update: RestMethod; + } + + export interface ConnectAppResource { + (resourceSid: string): ConnectAppInstance; + get: RestMethod; + } + + export interface AuthorizedConnectAppInstance { + get: RestMethod; + } + + export interface AuthorizedConnectAppResource { + (resourceSid: string): AuthorizedConnectAppInstance; + get: RestMethod; + } + + export interface TokenInstance {} + + export interface TokenResource { + (resourceSid: string): TokenInstance; + post: RestMethod; + create: RestMethod; + } + + export interface TranscriptionInstance { + get: RestMethod; + delete: RestMethod; + } + + export interface TranscriptionResource { + (resourceSid: string): TranscriptionInstance; + get: RestMethod; + } + + export interface NotificationInstance { + get: RestMethod; + delete: RestMethod; + } + + export interface NotificationResource { + (resourceSid: string): NotificationInstance; + get: RestMethod; + } + + export interface UsageTriggerInstance { + get: RestMethod; + post: RestMethod; + delete: RestMethod; + update: RestMethod; + } + + export interface UsageTriggerResource { + (resourceSid: string): UsageTriggerInstance; + get: RestMethod; + post: RestMethod; + create: RestMethod; + } + + export interface UsageIntermediary { + records: UsageRecordResource; + triggers: UsageTriggerResource; + } + + export interface SIPIntermediary { + domains: SIPDomainResource; + ipAccessControlLists: SIPIPAccessControlListResource; + credentialLists: SIPCredentialListResource; + } + + export interface KeyInstance { + get: RestMethod; + post: RestMethod; + delete: RestMethod; + update: RestMethod; + } + + export interface KeyResource { + (resourceSid: string): KeyInstance; + get: RestMethod; + post: RestMethod; + create: RestMethod; + } + + export interface AccountResource { + (accountSid: string): AccountResource; + + // Mixed-in resources + availablePhoneNumbers: AvailablePhoneNumberResource; + outgoingCallerIds: OutgoingCallerIdResource; + incomingPhoneNumbers: IncomingPhoneNumberResource; + messages: MessageResource; + sms: SMSIntermediary; + applications: ApplicationResource; + connectApps: ConnectAppResource; + authorizedConnectApps: AuthorizedConnectAppResource; + calls: CallResource; + conferences: ConferenceResource; + queues: QueueResource; + recordings: RecordingResource; + tokens: TokenResource; + transcriptions: TranscriptionResource; + notifications: NotificationResource; + usage: UsageIntermediary; + sip: SIPIntermediary; + addresses: AddressResource; + keys: KeyResource; + + // Mixed-in Methods + put: RestMethod; + post: RestMethod; + get: RestMethod; + update: RestMethod; + list: RestMethod; + } + + /// resources/Addresses.js + export interface DependentPhoneNumberResource { + get: RestMethod; + list: RestMethod; + } + + export interface AddressInstance { + // Mixins + dependentPhoneNumbers: DependentPhoneNumberResource; + + // Rest Methods + get: RestMethod; + post: RestMethod; + delete: RestMethod; + } + + export interface AddressResource { + (resourceSid: string): AddressInstance; + get: RestMethod; + list: RestMethod; + post: RestMethod; + create: RestMethod; + } + + /// resources/AvailablePhoneNumbers.js + export interface AvailablePhoneNumberResourceGroup { + get: RestMethod; + list: RestMethod; + search: RestMethod; + } - constructor(sid?: string, tkn?: string); + export interface AvailablePhoneNumberInstance { + local: AvailablePhoneNumberResourceGroup; + tollFree: AvailablePhoneNumberResourceGroup; + mobile: AvailablePhoneNumberResourceGroup; + } - allowClientIncoming(clientName: string): Capability; - allowClientOutgoing(appSid: string, params?: any): Capability; - allowEventStream(filters?: any): Capability; - generate(timeout?: number): string; -} + export interface AvailablePhoneNumberResource { + (isoCode: string): AvailablePhoneNumberInstance; + } -/// Client.js -declare interface ClientOptions { - host?: string; - apiVersion?: string; - timeout?: number; -} + /// resources/Calls.js + export interface CallRecordingResource { + get: RestMethod; + list: RestMethod; + } -declare interface ClientRequestOptions { - url: string; - form?: any; -} + export interface CallNotificationResource { + get: RestMethod; + list: RestMethod; + } -declare class Client { - accountSid: string; - authToken: string; - host: string; - apiVersion: string; - timeout: number; + export interface CallFeedbackResource { + get: RestMethod; + post: RestMethod; + delete: RestMethod; + create: RestMethod; + } - constructor(sid?: string, tkn?: string, host?: string, api_version?: string, timeout?: number); + export interface CallInstance { + recordings: CallRecordingResource; + notifications: CallNotificationResource; + feedback: CallFeedbackResource; - getBaseUrl(): string; - request(options: ClientRequestOptions, callback: RequestCallback): Q.Promise; -} + get: RestMethod; + post: RestMethod; + delete: RestMethod; + update: RestMethod; + } -/// IpMessagingClient.js -declare class IpMessagingClient extends Client { - services: ServiceResource; - credentials: CredentialsResource; + export interface CallFeedbackSummaryInstance { + get: RestMethod; + delete: RestMethod; + } - constructor(sid?: string, tkn?: string, options?: ClientOptions); -} + export interface CallFeedbackSummaryResource { + (resourceSid: string): CallFeedbackSummaryInstance; + post: RestMethod; + create: RestMethod; + } -/// LookupsClient.js -declare class LookupsClient extends Client { - phoneNumbers: PhoneNumbersResource; + export interface CallResource { + (resourceSid: string): CallInstance; - constructor(sid?: string, tkn?: string, options?: ClientOptions); -} + get: RestMethod; + post: RestMethod; + create: RestMethod; -/// MonitorClient.js -declare class MonitorClient extends Client implements EventResource, AlertResource { - events: EventResource; - alerts: AlertResource; + feedbackSummary: CallFeedbackSummaryResource; + } - constructor(sid?: string, tkn?: string, options?: ClientOptions); -} + /// resources/Conferences.js + export interface ConferenceParticipantInstance { + get: RestMethod; + post: RestMethod; + delete: RestMethod; + update: RestMethod; + kick: RestMethod; + } -/// PricingClient.js -declare class PricingClient extends Client { - voice: VoiceResource; - phoneNumbers: PhoneNumbersResource; - messaging: MessagingResource; + export interface ConferenceParticipantResource { + (resourceSid: string): ConferenceParticipantInstance; - constructor(sid?: string, tkn?: string, options?: ClientOptions); -} + get: RestMethod; + list: RestMethod; + } -/// RestClient.js -declare class RestClient extends Client implements AccountResource { - accounts: AccountResource; + export interface ConferenceInstance { + get: RestMethod; - // Messaging shorthand - // TODO Pull in proper method signatures here! - sendSms(); - sendMms(); - sendMessage(); - listSms(); - listMessages(); - getSms(messageSid: string, callback: (/* ??? */) => void): void; - getMessage(messageSid: string, callback: (/* ??? */) => void): void; + participants: ConferenceParticipantResource; + } - // Calls shorthand - // TODO Pull in proper method signatures here! - makeCall(); - listCalls(); - getCall(callSid: string, callback: (/* ??? */) => void): void; + export interface ConferenceResource { + (resourceSid: string): ConferenceInstance; - request(options: ClientRequestOptions, callback: RequestCallback): Q.Promise; + get: RestMethod; + list: RestMethod; + } + + /// resources/IncomingPhoneNumbers.js + export interface IncomingPhoneNumberResourceGroup { + get: RestMethod; + post: RestMethod; + create: RestMethod; + } + + export interface IncomingPhoneNumberInstance { + get: RestMethod; + post: RestMethod; + put: RestMethod; + delete: RestMethod; + update: RestMethod; + } + + export interface IncomingPhoneNumberResource { + (resourceSid: string): IncomingPhoneNumberInstance; + + get: RestMethod; + post: RestMethod; + create: RestMethod; + + local: IncomingPhoneNumberResourceGroup; + tollFree: IncomingPhoneNumberResourceGroup; + mobile: IncomingPhoneNumberResourceGroup; + } + + /// resources/Messages.js + export interface MessageMediaInstance { + get: RestMethod; + delete: RestMethod; + } + + export interface MessageMediaResource { + (resourceSid: string): MessageMediaInstance; + + get: RestMethod; + list: RestMethod; + } + + export interface MessageInstance { + get: RestMethod; + post: RestMethod; + delete: RestMethod; + + media: MessageMediaResource; + } + + export interface MessageResource { + (resourceSid: string): MessageInstance; + + get: RestMethod; + list: RestMethod; + post: RestMethod; + create: RestMethod; + } + + /// resources/Queues.js + export interface QueueMemberInstance { + get: RestMethod; + post: RestMethod; + update: RestMethod; + } + + export interface QueueMemberResource { + (resourceSid: string): QueueMemberInstance; + + get: RestMethod; + + front: QueueMemberInstance; + } + + export interface QueueInstance { + members: QueueMemberResource; + + get: RestMethod; + post: RestMethod; + delete: RestMethod; + update: RestMethod; + } + + export interface QueueResource { + (resourceSid: string): QueueInstance; + + get: RestMethod; + post: RestMethod; + create: RestMethod; + } + + /// resources/Recordings.js + export interface RecordingTranscriptionResource { + get: RestMethod; + list: RestMethod; + } + + export interface RecordingInstance { + get: RestMethod; + list: RestMethod; + delete: RestMethod; + + transcriptions: RecordingTranscriptionResource; + } + + export interface RecordingResource { + (resourceSid: string): RecordingInstance; + + get: RestMethod; + list: RestMethod; + } + + /// resources/UsageRecords.js + export interface UsageRecordInstance { + get: RestMethod; + } + + export interface UsageRecordRange { + get: RestMethod; + list: RestMethod; + } + + export interface UsageRecordResource { + (resourceSid: string): UsageRecordInstance; + + get: RestMethod; + + daily: UsageRecordRange; + monthly: UsageRecordRange; + yearly: UsageRecordRange; + allTime: UsageRecordRange; + today: UsageRecordRange; + yesterday: UsageRecordRange; + thisMonth: UsageRecordRange; + lastMonth: UsageRecordRange; + } + + /// resources/ip_messaging/Credentials.js + export interface CredentialInstance { + get: RestMethod; + post: RestMethod; + delete: RestMethod; + update: RestMethod; + } + + export interface CredentialResource { + (resourceSid: string): CredentialInstance; + + get: RestMethod; + post: RestMethod; + create: RestMethod; + list: RestMethod; + } + + /// resources/ip_messaging/Services.js + export interface ServiceUserInstance { + get: RestMethod; + post: RestMethod; + delete: RestMethod; + update: RestMethod; + } + + export interface ServiceUserResource { + (resourceSid: string): ServiceUserInstance; + + get: RestMethod; + post: RestMethod; + create: RestMethod; + list: RestMethod; + } + + export interface ServiceRoleInstance { + get: RestMethod; + } + + export interface ServiceRoleResource { + (resourceSid: string): ServiceRoleInstance; + + get: RestMethod; + list: RestMethod; + } + + export interface ServiceChannelMessageInstance { + get: RestMethod; + post: RestMethod; + delete: RestMethod; + update: RestMethod; + } + + export interface ServiceChannelMessageResource { + (resourceSid: string): ServiceChannelMessageInstance; + + get: RestMethod; + post: RestMethod; + create: RestMethod; + list: RestMethod; + } + + export interface ServiceChannelMemberInstance { + get: RestMethod; + post: RestMethod; + delete: RestMethod; + update: RestMethod; + } + + export interface ServiceChannelMemberResource { + (resourceSid: string): ServiceChannelMemberInstance; + + get: RestMethod; + post: RestMethod; + create: RestMethod; + list: RestMethod; + } + + export interface ServiceChannelInstance { + get: RestMethod; + post: RestMethod; + delete: RestMethod; + update: RestMethod; + + messages: ServiceChannelMessageResource; + members: ServiceChannelMemberResource; + } + + export interface ServiceChannelResource { + (resourceSid: string): ServiceChannelInstance; + + get: RestMethod; + post: RestMethod; + create: RestMethod; + list: RestMethod; + } + + export interface ServiceInstance { + get: RestMethod; + post: RestMethod; + delete: RestMethod; + update: RestMethod; + + users: ServiceUserResource; + roles: ServiceRoleResource; + channels: ServiceChannelResource; + } + + export interface ServiceResource { + (resourceSid: string): ServiceInstance; + + get: RestMethod; + post: RestMethod; + create: RestMethod; + list: RestMethod; + } + + /// resources/lookups/PhoneNumbers.js + export interface PhoneNumberInstance { + get: RestMethod; + } + + export interface PhoneNumberResource { + (resourceSid: string): PhoneNumberInstance; + } + + /// resources/monitor/Alerts.js + export interface AlertInstance { + get: RestMethod; + } + + export interface AlertResource { + (resourceSid: string): AlertInstance; + + get: RestMethod; + list: RestMethod; + } + + /// resources/monitor/Events.js + } \ No newline at end of file From b1af25b5d5fb030cbe2be30c26564b8d5998ae84 Mon Sep 17 00:00:00 2001 From: Nicholas Iannone Date: Mon, 8 Aug 2016 17:36:27 -0500 Subject: [PATCH 05/41] Added a few more files. --- twilio/twilio.d.ts | 223 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 220 insertions(+), 3 deletions(-) diff --git a/twilio/twilio.d.ts b/twilio/twilio.d.ts index d3a3bda26b..f901dae3ee 100644 --- a/twilio/twilio.d.ts +++ b/twilio/twilio.d.ts @@ -514,9 +514,9 @@ export namespace twilio { } export interface SIPIntermediary { - domains: SIPDomainResource; - ipAccessControlLists: SIPIPAccessControlListResource; - credentialLists: SIPCredentialListResource; + domains: DomainResource; + ipAccessControlLists: IPAccessControlListResource; + credentialLists: CredentialListResource; } export interface KeyInstance { @@ -958,5 +958,222 @@ export namespace twilio { } /// resources/monitor/Events.js + export interface EventInstance { + get: RestMethod; + } + + export interface EventResource { + (resourceSid: string): EventInstance; + + get: RestMethod; + list: RestMethod; + } + + /// resources/pricing/Messaging.js + export interface CountryInstance { + get: RestMethod; + } + + export interface CountryResource { + (resourceSid: string): CountryInstance; + + get: RestMethod; + list: RestMethod; + } + + export interface MessagingResource { + countries: CountryResource; + } + + /// resources/pricing/PhoneNumbers.js + export interface PhoneNumberResource { + countries: CountryResource; + } + + /// resources/pricing/Voice.js + export interface NumberInstance { + get: RestMethod; + } + + export interface NumberResource { + (resourceSid: string): NumberInstance; + + get: RestMethod; + list: RestMethod; + } + + export interface VoiceResource { + countries: CountryResource; + numbers: NumberResource; + } + + /// resources/sip/CredentialLists.js + export interface CredentialListInstance { + credentials: CredentialResource; + + get: RestMethod; + post: RestMethod; + delete: RestMethod; + update: RestMethod; + } + + export interface CredentialListResource { + (resourceSid: string): CredentialListInstance; + + get: RestMethod; + post: RestMethod; + create: RestMethod; + list: RestMethod; + } + + /// resources/sip/Domains.js + export interface IPAccessControlListMappingInstance { + get: RestMethod; + delete: RestMethod; + } + + export interface IPAccessControlListMappingResource { + (resourceSid: string): IPAccessControlListMappingInstance; + + get: RestMethod; + post: RestMethod; + create: RestMethod; + list: RestMethod; + } + + export interface CredentialListMappingInstance { + get: RestMethod; + delete: RestMethod; + } + + export interface CredentialListMappingResource { + (resourceSid: string): CredentialListMappingInstance; + + get: RestMethod; + post: RestMethod; + create: RestMethod; + list: RestMethod; + } + + export interface DomainInstance { + ipAccessControlListMappings: IPAccessControlListMappingResource; + credentialListMappings: CredentialListMappingResource; + + get: RestMethod; + post: RestMethod; + delete: RestMethod; + update: RestMethod; + } + + export interface DomainResource { + (resourceSid: string): DomainInstance; + + get: RestMethod; + post: RestMethod; + create: RestMethod; + list: RestMethod; + } + + /// resources/sip/IpAccessControlLists.js + export interface IPAddressInstance { + get: RestMethod; + post: RestMethod; + delete: RestMethod; + update: RestMethod; + } + + export interface IPAddressResource { + (resourceSid: string): IPAddressInstance; + + get: RestMethod; + post: RestMethod; + list: RestMethod; + create: RestMethod; + } + + export interface IPAccessControlListInstance { + ipAddresses: IPAddressResource; + + get: RestMethod; + post: RestMethod; + delete: RestMethod; + update: RestMethod; + } + + export interface IPAccessControlListResource { + (resourceSid: string): IPAccessControlListInstance; + + get: RestMethod; + post: RestMethod; + create: RestMethod; + list: RestMethod; + } + + /// resources/task_router/WorkflowBuilder.js + export interface WorkflowRuleTargetOptions { + queue: string; + expression?: string; + priority?: number; + timeout?: number; + } + + export class WorkflowRuleTarget { + queue: string; + expression: string; + priority: number; + timeout: number; + + constructor(options?: WorkflowRuleTargetOptions); + } + + export interface WorkflowRuleOptions { + expression: string; + targets: Array; + // Don't ask me why, but all of these are supported options. + friendly_name?: string; + friendlyName?: string; + filter_friendly_name?: string; + } + + export class WorkflowRule { + friendly_name: string; + expression: string; + targets: Array; + friendlyName: string; // Defined property mapped to friendly_name. + + constructor(options?: WorkflowRuleOptions); + } + + export interface TaskRoutingConfigurationOptions { + filters: Array; + default_filter?: WorkflowRuleOptions; + defaultFilter?: WorkflowRuleOptions; + } + + export class TaskRoutingConfiguration { + filters: Array; + default_filter: WorkflowRuleOptions; + defaultFilter: WorkflowRuleOptions; // Defined property mapped to default_filter. + + constructor(options?: TaskRoutingConfigurationOptions); + } + + export interface WorkflowConfigurationOptions { + task_routing?: TaskRoutingConfigurationOptions; + taskRouting?: TaskRoutingConfigurationOptions; + } + + export class WorkflowConfiguration { + task_routing: TaskRoutingConfiguration; + taskRouting: TaskRoutingConfiguration; // Defined property mapped to task_routing. + + constructor(options?: WorkflowConfigurationOptions); + + static fromJSON(json: string): WorkflowConfiguration; + toJSON(): string; + } + + /// resources/task_router/Workspaces.js + } \ No newline at end of file From 35e7542be42b28c32370d730fb29f3b8658cfb77 Mon Sep 17 00:00:00 2001 From: Nicholas Iannone Date: Mon, 8 Aug 2016 18:45:51 -0500 Subject: [PATCH 06/41] Tweaks to eliminate unnecessary cruft. --- twilio/twilio.d.ts | 246 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 219 insertions(+), 27 deletions(-) diff --git a/twilio/twilio.d.ts b/twilio/twilio.d.ts index f901dae3ee..f2600a2ed8 100644 --- a/twilio/twilio.d.ts +++ b/twilio/twilio.d.ts @@ -39,8 +39,6 @@ export namespace twilio { // validateRequest // validateExpressRequest - - /// ??? export interface GrantPayload {} @@ -180,7 +178,7 @@ export namespace twilio { } /// MonitorClient.js - export class MonitorClient extends Client implements EventResource, AlertResource { + export class MonitorClient extends Client { events: EventResource; alerts: AlertResource; @@ -197,7 +195,9 @@ export namespace twilio { } /// RestClient.js - export class RestClient extends Client implements AccountResource { + export class RestClient extends Client { + constructor(sid?: string, tkn?: string, options?: ClientOptions); + accounts: AccountResource; // Imported from AccountResource @@ -229,19 +229,17 @@ export namespace twilio { list: RestMethod; // Messaging shorthand - // TODO Pull in proper method signatures here! - sendSms(); - sendMms(); - sendMessage(); - listSms(); - listMessages(); + sendSms: RestMethod; + sendMms: RestMethod; + sendMessage: RestMethod; + listSms: RestMethod; + listMessages: RestMethod; getSms(messageSid: string, callback?: RequestCallback): Q.Promise; getMessage(messageSid: string, callback?: RequestCallback): Q.Promise; // Calls shorthand - // TODO Pull in proper method signatures here! - makeCall(); - listCalls(); + makeCall(): RestMethod; + listCalls(): RestMethod; getCall(callSid: string, callback?: RequestCallback): Q.Promise; // Overrides Client.request(...) @@ -249,19 +247,12 @@ export namespace twilio { } /// TaskRouterCapability.js - export interface QueryFilter { - // TODO Populate me! - } - - export interface PostFilter { - // TODO Populate me! - } export interface Policy { url: string; method: string; - query_filter?: QueryFilter; - post_filter?: PostFilter; + query_filter?: any; // Map, where FilterRequirement ::= Map + post_filter?: any; // Map, where FilterRequirement ::= Map allow: boolean; } @@ -290,14 +281,14 @@ export namespace twilio { allowWorkerFetchAttributes(): void; allowTaskReservationUpdates(): void; - addPolicy(url: string, method: string, allowed?: boolean, queryFilter?: QueryFilter, postFilter?: PostFilter): void; - allow(url: string, method: string, queryFilter?: QueryFilter, postFilter?: PostFilter): void; - deny(url: string, method: string, queryFilter?: QueryFilter, postFilter?: PostFilter): void; + addPolicy(url: string, method: string, allowed?: boolean, queryFilter?: any, postFilter?: any): void; + allow(url: string, method: string, queryFilter?: any, postFilter?: any): void; + deny(url: string, method: string, queryFilter?: any, postFilter?: any): void; generate(ttl: number): string; } /// TaskRouterClient.js - export class TaskRouterClient extends Client implements WorkspaceResource { + export class TaskRouterClient extends Client { workspaces: WorkspaceResource; workspace: WorkspaceResource; @@ -1174,6 +1165,207 @@ export namespace twilio { } /// resources/task_router/Workspaces.js - + export interface WorkspaceActivityInstance { + get: RestMethod; + post: RestMethod; + delete: RestMethod; + update: RestMethod; + } + + export interface WorkspaceActivityResource { + (resourceSid: string): WorkspaceActivityInstance; + + get: RestMethod; + post: RestMethod; + list: RestMethod; + create: RestMethod; + } + + export interface WorkspaceEventInstance { + get: RestMethod; + } + + export interface WorkspaceEventResource { + (resourceSid: string): WorkspaceEventInstance; + + get: RestMethod; + list: RestMethod; + } + + export interface WorkspaceTaskReservationInstance { + get: RestMethod; + post: RestMethod; + update: RestMethod; + } + + export interface WorkspaceTaskReservationResource { + (resourceSid: string): WorkspaceTaskReservationInstance; + + get: RestMethod; + list: RestMethod; + } + + export interface WorkspaceTaskInstance { + reservations: WorkspaceTaskReservationResource; + + get: RestMethod; + post: RestMethod; + delete: RestMethod; + update: RestMethod; + } + + export interface WorkspaceTaskResource { + (resourceSid: string): WorkspaceTaskInstance; + + get: RestMethod; + post: RestMethod; + list: RestMethod; + create: RestMethod; + } + + export interface WorkspaceInstanceStatisticResource { + get: RestMethod; + } + + export interface WorkspaceStatisticResource { + get: RestMethod; + list: RestMethod; + } + + export interface WorkspaceTaskQueueInstance { + statistics: WorkspaceInstanceStatisticResource; + + get: RestMethod; + post: RestMethod; + delete: RestMethod; + update: RestMethod; + } + + export interface WorkspaceTaskQueueResource { + (resourceSid: string): WorkspaceTaskQueueInstance; + + statistics: WorkspaceStatisticResource; + + get: RestMethod; + post: RestMethod; + list: RestMethod; + create: RestMethod; + } + + export interface WorkspaceWorkerReservationInstance { + get: RestMethod; + post: RestMethod; + update: RestMethod; + } + + export interface WorkspaceWorkerReservationResource { + (resourceSid: string): WorkspaceWorkerReservationInstance; + + get: RestMethod; + list: RestMethod; + } + + export interface WorkspaceWorkerInstance { + statistics: WorkspaceInstanceStatisticResource; + reservations: WorkspaceWorkerReservationResource; + + get: RestMethod; + post: RestMethod; + delete: RestMethod; + update: RestMethod; + } + + export interface WorkspaceWorkerResource { + (resourceSid: string): WorkspaceWorkerInstance; + + statistics: WorkspaceStatisticResource; + + get: RestMethod; + post: RestMethod; + list: RestMethod; + create: RestMethod; + } + + export interface WorkspaceWorkflowInstance { + statistics: WorkspaceInstanceStatisticResource; + + get: RestMethod; + post: RestMethod; + delete: RestMethod; + update: RestMethod; + } + + export interface WorkspaceWorkflowResource { + (resourceSid: string): WorkspaceWorkflowInstance; + + statistics: WorkspaceStatisticResource; + + get: RestMethod; + post: RestMethod; + list: RestMethod; + create: RestMethod; + } + + export interface WorkspaceInstance { + activities: WorkspaceActivityResource; + events: WorkspaceEventResource; + tasks: WorkspaceTaskResource; + taskQueues: WorkspaceTaskQueueResource; + workers: WorkspaceWorkerResource; + workflows: WorkspaceWorkflowResource; + + statistics: WorkspaceInstanceStatisticResource; + + get: RestMethod; + post: RestMethod; + delete: RestMethod; + update: RestMethod; + } + + export interface WorkspaceResource { + (resourceSid: string): WorkspaceInstance; + + get: RestMethod; + post: RestMethod; + create: RestMethod; + } + + /// resources/trunking/Trunks.js + export interface OriginationURLInstance { + get: RestMethod; + post: RestMethod; + delete: RestMethod; + update: RestMethod; + } + + export interface OriginationURLResource { + (resourceSid: string): OriginationURLInstance; + + get: RestMethod; + post: RestMethod; + create: RestMethod; + list: RestMethod; + } + + export interface TrunkInstance { + ipAccessControlLists: IPAccessControlListResource; + credentialLists: CredentialListResource; + phoneNumbers: PhoneNumberResource; + originationUrls: OriginationURLResource; + + get: RestMethod; + post: RestMethod; + delete: RestMethod; + update: RestMethod; + } + + export interface TrunkResource { + (resourceSid: string): TrunkInstance; + + get: RestMethod; + post: RestMethod; + create: RestMethod; + list: RestMethod; + } } \ No newline at end of file From 0d0133104dff056cbba9a3677efbdd130175b3ab Mon Sep 17 00:00:00 2001 From: Nicholas Iannone Date: Mon, 8 Aug 2016 19:04:30 -0500 Subject: [PATCH 07/41] Tweaks to try and get this working. --- twilio/twilio-tests.ts | 2 ++ twilio/twilio.d.ts | 22 ++++++++++------------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/twilio/twilio-tests.ts b/twilio/twilio-tests.ts index 9af07e7c27..f73fcc231b 100644 --- a/twilio/twilio-tests.ts +++ b/twilio/twilio-tests.ts @@ -1,5 +1,7 @@ /// +import twilio = require('twilio'); + var str: string; const client = new twilio.RestClient(str, str); diff --git a/twilio/twilio.d.ts b/twilio/twilio.d.ts index f2600a2ed8..e99e4c508f 100644 --- a/twilio/twilio.d.ts +++ b/twilio/twilio.d.ts @@ -1,17 +1,15 @@ +// Type definitions for twilio +// Project: https://github.com/twilio/twilio-node +// Definitions by: nickiannone +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + /// /// /// import * as Http from 'http'; -/// index.js -/* -export class twilio extends RestClient { - constructor(sid?: string, tkn?: string, options?: ClientOptions); -} -*/ - -export namespace twilio { +declare module twilio { // Composite Classes: //============================== @@ -352,7 +350,7 @@ export namespace twilio { toString(): string; } - export function TwimlResponse(): Node; + function TwimlResponse(): Node; /// webhook.js export interface webhookOptions { @@ -376,10 +374,10 @@ export namespace twilio { // For interop with node middleware chains export interface MiddlewareFunction { (request: Http.ClientRequest, response: Http.ClientResponse, next: MiddlewareFunction): void; } - export function webhook(options?: string | webhookOptions): MiddlewareFunction; + function webhook(options?: string | webhookOptions): MiddlewareFunction; - export function validateRequest(authToken: string, twilioHeader: string, url: string, params?: any): boolean; - export function validateExpressRequest(request: Express.Request, authToken: string, options?: WebhookExpressOptions): boolean; + function validateRequest(authToken: string, twilioHeader: string, url: string, params?: any): boolean; + function validateExpressRequest(request: Express.Request, authToken: string, options?: WebhookExpressOptions): boolean; /// resources/Accounts.js export interface OutgoingCallerIdInstance { From 215e13547ef0c5185b54c8c4f0f0310f2965479e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlado=20Te=C5=A1anovi=C4=87?= Date: Tue, 9 Aug 2016 11:26:43 +0200 Subject: [PATCH 08/41] adding jsonschema --- jsonschema/jsonschema.d.ts | 114 +++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 jsonschema/jsonschema.d.ts diff --git a/jsonschema/jsonschema.d.ts b/jsonschema/jsonschema.d.ts new file mode 100644 index 0000000000..2d52fb978e --- /dev/null +++ b/jsonschema/jsonschema.d.ts @@ -0,0 +1,114 @@ +// Type definitions for jsonschema +// Project: https://github.com/tdegrunt/jsonschema +// Definitions by: Vlado Tešanovic https://github.com/vladotesanovic +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +declare module "jsonschema" { + + export interface IJSONSchemaResult { + errors: Array; + instance: any; + arguments: Array<{}>; + propertyPath: string; + name: string; + schema: {}; + throwError: any; + disableFormat: boolean; + } + + export interface IJSONSchemaValidationError { + message: string; + property: string; + stack: string; + schema: {}; + name: string; + instance: any; + argument: {}; + } + + export interface IJSONSchemaOptions { + propertyName?: string; + base?: string; + } + + /** + * How to; + * + * const v: Validator = new Validator(); + * + * const schema: {} = { + * "type": "object", + * "properties": { + * "key": { + * "type": "string", + * "required": true + * }, + * "value": { + * "type": "string", + * "required": true + * } + * } + * }; + * + * const validationResults: { errors: Array } = + * v.validate({ key: "Name", value: "A10" }, {"type": "string"}); + * + */ + export class Validator { + + /** + * Creates a new Validator object + * @name Validator + * @constructor + */ + new(): this; + + /** + * Validates instance against the provided schema + * @param instance + * @param schema + * @param [options] + * @param [ctx] + * @return {Array} + */ + validate(instance: any, schema: {}, options?: IJSONSchemaOptions, ctx?: {}): IJSONSchemaResult; + + /** + * Adds a schema with a certain urn to the Validator instance. + * @param schema + * @param urn + * @return {Object} + */ + addSchema(schema: {}, urn: string): {}; + + /** + * Add Sub schema to existing one + * @param baseuri + * @param schema + */ + addSubSchema(baseuri: string, schema: {}): {} + + /** + * Sets all the schemas of the Validator instance. + * @param schemas + */ + setSchemas (schemas: Array<{}>): void; + + /** + * Returns the schema of a certain urn + * @param urn + */ + getSchema(urn: string): {}; + + /** + * Validates an instance against the schema (the actual work horse) + * @param instance + * @param schema + * @param options + * @param ctx + * @private + * @return {IJSONSchemaResult} + */ + validateSchema(instance: any, schema: {}, options?: {}, ctx?: {}): IJSONSchemaResult + } +} + From bc8fffa7503af4aefe9886f0757a9b50c6fab498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlado=20Te=C5=A1anovi=C4=87?= Date: Tue, 9 Aug 2016 11:36:57 +0200 Subject: [PATCH 09/41] Tests added --- jsonschema/jsonschema-tests.ts | 6 ++++++ jsonschema/jsonschema.d.ts | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 jsonschema/jsonschema-tests.ts diff --git a/jsonschema/jsonschema-tests.ts b/jsonschema/jsonschema-tests.ts new file mode 100644 index 0000000000..e8acc29886 --- /dev/null +++ b/jsonschema/jsonschema-tests.ts @@ -0,0 +1,6 @@ +/// +import { Validator, IJSONSchemaValidationError } from "jsonschema"; + +const v: Validator = new Validator(); + +const validationResults: { errors: Array } = v.validate("Smith", {"type": "string"}); diff --git a/jsonschema/jsonschema.d.ts b/jsonschema/jsonschema.d.ts index 2d52fb978e..9e32dbfded 100644 --- a/jsonschema/jsonschema.d.ts +++ b/jsonschema/jsonschema.d.ts @@ -1,6 +1,6 @@ // Type definitions for jsonschema // Project: https://github.com/tdegrunt/jsonschema -// Definitions by: Vlado Tešanovic https://github.com/vladotesanovic +// Definitions by: Vlado Tešanovic // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare module "jsonschema" { From 920cfea632211109539d81900d99b22e398db3f2 Mon Sep 17 00:00:00 2001 From: Nicholas Iannone Date: Tue, 9 Aug 2016 10:35:47 -0500 Subject: [PATCH 10/41] Fixed importing and added examples from twilio-node as tests. --- twilio/twilio-tests.ts | 234 +++++++++++++++++++++++++++++++++++++++-- twilio/twilio.d.ts | 43 +++++++- 2 files changed, 263 insertions(+), 14 deletions(-) diff --git a/twilio/twilio-tests.ts b/twilio/twilio-tests.ts index f73fcc231b..20e60242aa 100644 --- a/twilio/twilio-tests.ts +++ b/twilio/twilio-tests.ts @@ -1,19 +1,233 @@ -/// +import { twilio } from './twilio'; -import twilio = require('twilio'); +// Examples taken from https://twilio.github.io/twilio-node/ (v2.1.0) var str: string; -const client = new twilio.RestClient(str, str); -const account = client.accounts(str); +// Create a client: +var client = require('twilio')('ACCOUNT_SID', 'AUTH_TOKEN'); -account.messages.post({ - body: str, - from: str, - to: str +//Get a list of calls made by this account +// GET /2010-04-01/Accounts/ACCOUNT_SID/Calls +// alias for get is "list", if you prefer +client.calls.get(function(err, response) { + response.calls.forEach(function(call) { + console.log('Received call from: ' + call.from); + console.log('Call duration (in seconds): ' + call.duration); + }); }); -account.sms.messages(str).get(function(err, data) { - // Do nothing +//Get a list of calls made by this account, from this phone number +// GET /2010-04-01/Accounts/ACCOUNT_SID/Calls?From=+16513334455 +client.calls.get({ + from:'+16513334455' +}, function(err, response) { + response.calls.forEach(function(call) { + console.log('Received call from: ' + call.from); + console.log('This call\'s unique ID is: ' + call.sid); + }); }); +//Get data for a specific call +// GET /2010-04-01/Accounts/ACCOUNT_SID/Calls/abc123... +client.calls('abc123...').get(function(err, call) { + console.log('This call\'s unique ID is: ' + call.sid); + console.log('This call was created at: ' + call.dateCreated); +}); + +//Get data for a specific call, for a specific account +// GET /2010-04-01/Accounts/AC.../Calls/abc123... +client.accounts('AC...').calls('abc123...').get(function(err, response) { + response.calls.forEach(function(call) { + console.log('Received call from: ' + call.from); + console.log('This call\'s unique ID is: ' + call.sid); + }); +}); + +// Create (send) an SMS message +// POST /2010-04-01/Accounts/ACCOUNT_SID/SMS/Messages +// "create" and "update" aliases are in place where appropriate on PUT and POST requests +client.sms.messages.post({ + to:'+16515559999', + from:'+14503334455', + body:'word to your mother.' +}, function(err, text) { + console.log('You sent: '+ text.body); + console.log('Current status of this text message is: '+ text.status); +}); + +// Delete a TwiML application +// DELETE /2010-04-01/Accounts/ACCOUNT_SID/Applications/APP... +client.applications('APP...').delete(function(err, response, nodeResponse) { + //DELETE requests do not return data - if there was no error, it worked. + err ? console.log('There was an error') : console.log('it worked!'); +}); + +var client = require('twilio')('ACCOUNT_SID', 'AUTH_TOKEN'), + SOME_SUBACCOUNT_SID = 'AC...'; + +//Send a text message, associated with the given subaccount +client.accounts(SOME_SUBACCOUNT_SID).sms.messages.create({ + to:'+16512223333', + from:'+14505556677', + body:'word to your subaccount mother.' +}, function(err, text) { + console.log('You sent: '+ text.body); + console.log('Current status of this text message is: '+ text.status); +}); + +//This REST call using the master/default account for the client... +client.makeCall({ + to:'+16512223333', + from:'+14505556677', + url:'http://example.com/someTwiml.php' +}, function(err, call) { + console.log('This call\'s unique ID is: ' + call.sid); + console.log('This call was created at: ' + call.dateCreated); +}); + +//...is the same as... +client.accounts(str).calls.create({ + to:'+16512223333', + from:'+14505556677', + url:'http://example.com/someTwiml.php' +}, function(err, call) { + console.log('This call\'s unique ID is: ' + call.sid); + console.log('This call was created at: ' + call.dateCreated); +}); + +var restClient = new twilio.RestClient('ACCOUNT_SID', 'AUTH_TOKEN'); + +// A simple example of making a phone call using promises +var promise = restClient.makeCall({ + to:'+16515556667777', // a number to call + from:'+16518889999', // a Twilio number you own + url:'https://demo.twilio.com/welcome/voice' // A URL containing TwiML instructions for the call +}); + +// You can assign functions to be called, at any time, after the request to +// Twilio has been completed. The first function is called when the request +// succeeds, the second if there was an error. +promise.then(function(call) { + console.log('Call success! Call SID: '+call.sid); +}, function(error) { + console.error('Call failed! Reason: '+error.message); +}); + +// Let's look at an example where we're making multiple requests to Twilio, like +// buying a new phone number. This is where promises can become very useful: + +// First, search for available phone numbers +restClient.availablePhoneNumbers('US').local.get({ + areaCode:'651' +}).then(function(searchResults) { + + // handle the case where there are no numbers found + if (searchResults.availablePhoneNumbers.length < 1) { + throw { message:'No numbers found with that area code' }; + } + + // Okay, so there are some available numbers. Now, let's buy the first one + // in the list. Return the promise created by the next call to Twilio: + return restClient.incomingPhoneNumbers.create({ + phoneNumber:searchResults.availablePhoneNumbers[0].phoneNumber, + voiceUrl:'https://demo.twilio.com/welcome/voice', + smsUrl:'https://demo.twilio.com/welcome/sms/reply' + }); + +}).then(function(number) { + + // We bought the number! Everything worked! + console.log('Your new number: '+number.phoneNumber); + +}).fail(function(error) { + + // This callback will be invoked on any error returned in the + // process. + console.log('Number purchase failed! Reason: '+error.message); + +}).fin(function() { + + // You can use this optional callback like a "finally" block + // It will always execute last. Perform any cleanup necessary here. + +}); + +client.request({ + url:'/Accounts', + method:'GET' +}, function (error, responseData) { + //work with response data +}); + +/// TwiML +var resp = new twilio.TwimlResponse(); + +resp.say('Welcome to Twilio!'); +resp.say('Please let us know if we can help during your development.', { + voice:'woman', + language:'en-gb' +}); + +console.log(resp.toString()); + +resp.say('Welcome to Twilio!') + .pause({ length:3 }) + .say('Please let us know if we can help during your development.', { + voice:'woman', + language:'en-gb' + }) + .play('http://www.example.com/some_sound.mp3'); + +resp.say('Welcome to Acme Customer Service!') + .gather({ + action:'http://www.example.com/callFinished.php', + finishOnKey:'*' + }, function() { + this.say('Press 1 for customer service') + .say('Press 2 for British customer service', { language:'en-gb' }); + }); + +resp.say('Welcome to Acme Customer Service!') + .gather({ + action:'http://www.example.com/callFinished.php', + finishOnKey:'*' + }, function(node) { //note the use of the "node" variable in the anonymous function + + //Now you can use this reference as well, if using "this" wrankles you + node.say('Press 1 for customer service') + .say('Press 2 for British customer service', { language:'en-gb' }); + + }); + +resp.say('Your conference call is starting.', + { + voice:'woman', + language:'en-gb' + }) + .dial({ + action:'http://example.com/something.php' + }, function(node) { + node.conference('waitingRoom', { + beep:'false' + }); + }); + +/// Capabilities +var capability = new twilio.Capability(str, str); +capability.allowClientIncoming('jenny'); +var token = capability.generate(); + +capability.allowClientOutgoing('AP123'); +var token = capability.generate(); + +capability.allowClientOutgoing('AP123'); +var token = capability.generate(120); + +/// Utilities +twilio.validateRequest(token, str, 'http://example.herokuapp.com', { query: 'val' }); +twilio.validateExpressRequest({}, 'YOUR_TWILIO_AUTH_TOKEN'); +twilio.validateExpressRequest({}, 'YOUR_TWILIO_AUTH_TOKEN', {}); +twilio.webhook({ validate: false }); + + diff --git a/twilio/twilio.d.ts b/twilio/twilio.d.ts index e99e4c508f..cc74cecef5 100644 --- a/twilio/twilio.d.ts +++ b/twilio/twilio.d.ts @@ -9,7 +9,11 @@ import * as Http from 'http'; -declare module twilio { +export interface twilio { + (sid?: string, tkn?: string, options?: twilio.ClientOptions): twilio.RestClient; +} + +export module twilio { // Composite Classes: //============================== @@ -236,8 +240,8 @@ declare module twilio { getMessage(messageSid: string, callback?: RequestCallback): Q.Promise; // Calls shorthand - makeCall(): RestMethod; - listCalls(): RestMethod; + makeCall: RestMethod; + listCalls: RestMethod; getCall(callSid: string, callback?: RequestCallback): Q.Promise; // Overrides Client.request(...) @@ -338,6 +342,10 @@ declare module twilio { legalNodes: Array; } + export interface TwimlMethod { (arg1: any | string | TwimlCallback, arg2?: any | string | TwimlCallback): Node } + + export interface TwimlCallback { (node?: Node): void; } + export class Node implements NodeOptions { name: string; attributes: any; @@ -347,10 +355,37 @@ declare module twilio { constructor(config?: NodeOptions); + // TwiML Verbs/Nouns: + gather: TwimlMethod; + say: TwimlMethod; + play: TwimlMethod; + pause: TwimlMethod; + + dial: TwimlMethod; + number: TwimlMethod; + client: TwimlMethod; + conference: TwimlMethod; + queue: TwimlMethod; + sip: TwimlMethod; + + message: TwimlMethod; + media: TwimlMethod; + body: TwimlMethod; + + enqueue: TwimlMethod; + task: TwimlMethod; + + record: TwimlMethod; + sms: TwimlMethod; + hangup: TwimlMethod; + redirect: TwimlMethod; + reject: TwimlMethod; + leave: TwimlMethod; + toString(): string; } - function TwimlResponse(): Node; + export class TwimlResponse extends Node {} /// webhook.js export interface webhookOptions { From 95c58d3e815fd2dba4d1cf6804fd68f7a4c404f3 Mon Sep 17 00:00:00 2001 From: Nicholas Iannone Date: Tue, 9 Aug 2016 10:52:08 -0500 Subject: [PATCH 11/41] Forgot a few export statements. --- twilio/twilio.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/twilio/twilio.d.ts b/twilio/twilio.d.ts index cc74cecef5..035710cd1b 100644 --- a/twilio/twilio.d.ts +++ b/twilio/twilio.d.ts @@ -409,10 +409,10 @@ export module twilio { // For interop with node middleware chains export interface MiddlewareFunction { (request: Http.ClientRequest, response: Http.ClientResponse, next: MiddlewareFunction): void; } - function webhook(options?: string | webhookOptions): MiddlewareFunction; + export function webhook(options?: string | webhookOptions): MiddlewareFunction; - function validateRequest(authToken: string, twilioHeader: string, url: string, params?: any): boolean; - function validateExpressRequest(request: Express.Request, authToken: string, options?: WebhookExpressOptions): boolean; + export function validateRequest(authToken: string, twilioHeader: string, url: string, params?: any): boolean; + export function validateExpressRequest(request: Express.Request, authToken: string, options?: WebhookExpressOptions): boolean; /// resources/Accounts.js export interface OutgoingCallerIdInstance { From 4fadd40471a5c20fbdf72bf526b1d7466c7cd2da Mon Sep 17 00:00:00 2001 From: Nicholas Iannone Date: Tue, 9 Aug 2016 10:55:35 -0500 Subject: [PATCH 12/41] Added imports. --- twilio/twilio.d.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/twilio/twilio.d.ts b/twilio/twilio.d.ts index 035710cd1b..8de55d6f83 100644 --- a/twilio/twilio.d.ts +++ b/twilio/twilio.d.ts @@ -7,8 +7,11 @@ /// /// +import * as express from 'express'; import * as Http from 'http'; +import q = require('q'); + export interface twilio { (sid?: string, tkn?: string, options?: twilio.ClientOptions): twilio.RestClient; } From ebe80b9f21e6229c73ac40d93b8bfef90b17afee Mon Sep 17 00:00:00 2001 From: Nicholas Iannone Date: Tue, 9 Aug 2016 11:22:17 -0500 Subject: [PATCH 13/41] Fixed Q import (hopefully?) and cleaned up implicit types in test --- twilio/twilio-tests.ts | 45 +++++++++++++++++++++--------------------- twilio/twilio.d.ts | 3 ++- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/twilio/twilio-tests.ts b/twilio/twilio-tests.ts index 20e60242aa..0c9013ede7 100644 --- a/twilio/twilio-tests.ts +++ b/twilio/twilio-tests.ts @@ -5,13 +5,13 @@ import { twilio } from './twilio'; var str: string; // Create a client: -var client = require('twilio')('ACCOUNT_SID', 'AUTH_TOKEN'); +var client: twilio.RestClient = (require('twilio') as twilio)('ACCOUNT_SID', 'AUTH_TOKEN'); //Get a list of calls made by this account // GET /2010-04-01/Accounts/ACCOUNT_SID/Calls // alias for get is "list", if you prefer -client.calls.get(function(err, response) { - response.calls.forEach(function(call) { +client.calls.get(function(err: any, response: any) { + response.calls.forEach(function(call: any) { console.log('Received call from: ' + call.from); console.log('Call duration (in seconds): ' + call.duration); }); @@ -21,8 +21,8 @@ client.calls.get(function(err, response) { // GET /2010-04-01/Accounts/ACCOUNT_SID/Calls?From=+16513334455 client.calls.get({ from:'+16513334455' -}, function(err, response) { - response.calls.forEach(function(call) { +}, function(err: any, response: any) { + response.calls.forEach(function(call: any) { console.log('Received call from: ' + call.from); console.log('This call\'s unique ID is: ' + call.sid); }); @@ -30,15 +30,15 @@ client.calls.get({ //Get data for a specific call // GET /2010-04-01/Accounts/ACCOUNT_SID/Calls/abc123... -client.calls('abc123...').get(function(err, call) { +client.calls('abc123...').get(function(err: any, call: any) { console.log('This call\'s unique ID is: ' + call.sid); console.log('This call was created at: ' + call.dateCreated); }); //Get data for a specific call, for a specific account // GET /2010-04-01/Accounts/AC.../Calls/abc123... -client.accounts('AC...').calls('abc123...').get(function(err, response) { - response.calls.forEach(function(call) { +client.accounts('AC...').calls('abc123...').get(function(err: any, response: any) { + response.calls.forEach(function(call: any) { console.log('Received call from: ' + call.from); console.log('This call\'s unique ID is: ' + call.sid); }); @@ -51,27 +51,26 @@ client.sms.messages.post({ to:'+16515559999', from:'+14503334455', body:'word to your mother.' -}, function(err, text) { +}, function(err: any, text: any) { console.log('You sent: '+ text.body); console.log('Current status of this text message is: '+ text.status); }); // Delete a TwiML application // DELETE /2010-04-01/Accounts/ACCOUNT_SID/Applications/APP... -client.applications('APP...').delete(function(err, response, nodeResponse) { +client.applications('APP...').delete(function(err: any, response: any, nodeResponse: any) { //DELETE requests do not return data - if there was no error, it worked. err ? console.log('There was an error') : console.log('it worked!'); }); -var client = require('twilio')('ACCOUNT_SID', 'AUTH_TOKEN'), - SOME_SUBACCOUNT_SID = 'AC...'; +var SOME_SUBACCOUNT_SID = 'AC...'; //Send a text message, associated with the given subaccount client.accounts(SOME_SUBACCOUNT_SID).sms.messages.create({ to:'+16512223333', from:'+14505556677', body:'word to your subaccount mother.' -}, function(err, text) { +}, function(err: any, text: any) { console.log('You sent: '+ text.body); console.log('Current status of this text message is: '+ text.status); }); @@ -81,7 +80,7 @@ client.makeCall({ to:'+16512223333', from:'+14505556677', url:'http://example.com/someTwiml.php' -}, function(err, call) { +}, function(err: any, call: any) { console.log('This call\'s unique ID is: ' + call.sid); console.log('This call was created at: ' + call.dateCreated); }); @@ -91,7 +90,7 @@ client.accounts(str).calls.create({ to:'+16512223333', from:'+14505556677', url:'http://example.com/someTwiml.php' -}, function(err, call) { +}, function(err: any, call: any) { console.log('This call\'s unique ID is: ' + call.sid); console.log('This call was created at: ' + call.dateCreated); }); @@ -108,9 +107,9 @@ var promise = restClient.makeCall({ // You can assign functions to be called, at any time, after the request to // Twilio has been completed. The first function is called when the request // succeeds, the second if there was an error. -promise.then(function(call) { +promise.then(function(call: any) { console.log('Call success! Call SID: '+call.sid); -}, function(error) { +}, function(error: any) { console.error('Call failed! Reason: '+error.message); }); @@ -120,7 +119,7 @@ promise.then(function(call) { // First, search for available phone numbers restClient.availablePhoneNumbers('US').local.get({ areaCode:'651' -}).then(function(searchResults) { +}).then(function(searchResults: any) { // handle the case where there are no numbers found if (searchResults.availablePhoneNumbers.length < 1) { @@ -135,12 +134,12 @@ restClient.availablePhoneNumbers('US').local.get({ smsUrl:'https://demo.twilio.com/welcome/sms/reply' }); -}).then(function(number) { +}).then(function(number: any) { // We bought the number! Everything worked! console.log('Your new number: '+number.phoneNumber); -}).fail(function(error) { +}).fail(function(error: any) { // This callback will be invoked on any error returned in the // process. @@ -156,7 +155,7 @@ restClient.availablePhoneNumbers('US').local.get({ client.request({ url:'/Accounts', method:'GET' -}, function (error, responseData) { +}, function (error: any, responseData: any) { //work with response data }); @@ -192,7 +191,7 @@ resp.say('Welcome to Acme Customer Service!') .gather({ action:'http://www.example.com/callFinished.php', finishOnKey:'*' - }, function(node) { //note the use of the "node" variable in the anonymous function + }, function(node: twilio.Node) { //note the use of the "node" variable in the anonymous function //Now you can use this reference as well, if using "this" wrankles you node.say('Press 1 for customer service') @@ -207,7 +206,7 @@ resp.say('Your conference call is starting.', }) .dial({ action:'http://example.com/something.php' - }, function(node) { + }, function(node: twilio.Node) { node.conference('waitingRoom', { beep:'false' }); diff --git a/twilio/twilio.d.ts b/twilio/twilio.d.ts index 8de55d6f83..e7b28d7636 100644 --- a/twilio/twilio.d.ts +++ b/twilio/twilio.d.ts @@ -5,7 +5,7 @@ /// /// -/// +/// import * as express from 'express'; import * as Http from 'http'; @@ -151,6 +151,7 @@ export module twilio { export interface ClientRequestOptions { url: string; + method?: string; form?: any; } From 73f02e190b0647ba30353afdf07f6ee9443fbb80 Mon Sep 17 00:00:00 2001 From: rundef Date: Wed, 10 Aug 2016 09:12:15 -0400 Subject: [PATCH 14/41] [sequelize] import lodash dependency --- sequelize/sequelize.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/sequelize/sequelize.d.ts b/sequelize/sequelize.d.ts index 4cf94ce77d..e7433b826c 100644 --- a/sequelize/sequelize.d.ts +++ b/sequelize/sequelize.d.ts @@ -10,6 +10,7 @@ /// declare module "sequelize" { + import * as _ from "lodash"; namespace sequelize { From 2a2017e7485e69c902ae90d115ce377b12f6fc6b Mon Sep 17 00:00:00 2001 From: Kostya Esmukov Date: Wed, 10 Aug 2016 20:00:22 +0300 Subject: [PATCH 15/41] Updated react-i18next typings for the 1.7.0 version --- react-i18next/react-i18next-tests.tsx | 26 ++++++++++++++++++++------ react-i18next/react-i18next.d.ts | 15 ++++++++++++--- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/react-i18next/react-i18next-tests.tsx b/react-i18next/react-i18next-tests.tsx index d9faea8ac2..dd013002d4 100644 --- a/react-i18next/react-i18next-tests.tsx +++ b/react-i18next/react-i18next-tests.tsx @@ -7,7 +7,7 @@ import * as ReactDOM from 'react-dom'; import * as React from 'react'; import * as i18n from 'i18next'; -import { translate, I18nextProvider, Interpolate, InjectedTranslateProps } from 'react-i18next'; +import { translate, I18nextProvider, Interpolate, InjectedTranslateProps, TranslationFunction } from 'react-i18next'; i18n @@ -26,18 +26,19 @@ i18n }); -interface InnerAnotherComponentProps extends InjectedTranslateProps { +interface InnerAnotherComponentProps { + _?: TranslationFunction; } class InnerAnotherComponent extends React.Component { render() { - const { t } = this.props; + const { _ } = this.props; - return

{t('content.text', { /* options t options */ })}

; + return

{_('content.text', { /* options t options */ })}

; } } -const AnotherComponent = translate('view', { wait: true })(InnerAnotherComponent); +const AnotherComponent = translate('view', { wait: true, translateFuncName: '_' })(InnerAnotherComponent); @@ -69,7 +70,20 @@ class TranslatableView extends React.Component {

{t('common:appName')}

- + + {t('nav:link1')} ) diff --git a/react-i18next/react-i18next.d.ts b/react-i18next/react-i18next.d.ts index 0720e6e4ed..8993ab61cb 100644 --- a/react-i18next/react-i18next.d.ts +++ b/react-i18next/react-i18next.d.ts @@ -1,4 +1,4 @@ -// Type definitions for react-i18next 1.6.3 +// Type definitions for react-i18next 1.7.0 // Project: https://github.com/i18next/react-i18next // Definitions by: Kostya Esmukov // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -11,11 +11,16 @@ declare namespace ReactI18next { import React = __React; + export type TranslationFunction = I18next.TranslationFunction; + // Extend your component's Prop interface with this one to get access to `this.props.t` // + // Please note that if you use the `translateFuncName` option, you should create + // your own interface just like this one, but with your name of the translation function. + // // interface MyComponentProps extends ReactI18next.InjectedTranslateProps {} export interface InjectedTranslateProps { - t?: I18next.TranslationFunction; + t?: TranslationFunction; } interface I18nextProviderProps { @@ -35,7 +40,10 @@ declare namespace ReactI18next { regexp?: RegExp; options?: I18next.TranslationOptions; - [regexKey: string]: InterpolateValue | RegExp | I18next.TranslationOptions; + useDangerouslySetInnerHTML?: boolean; + dangerouslySetInnerHTMLPartElement?: string; + + [regexKey: string]: InterpolateValue | RegExp | I18next.TranslationOptions | boolean; } export class Interpolate extends React.Component { } @@ -43,6 +51,7 @@ declare namespace ReactI18next { interface TranslateOptions { withRef?: boolean; wait?: boolean; + translateFuncName?: string; } export function translate(namespaces?: string[] | string, options?: TranslateOptions): (WrappedComponent: C) => C; From 1317f2fdf4be30668fc4b37c0bc4e2a2daa74bb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Werlang?= Date: Wed, 10 Aug 2016 15:31:42 -0300 Subject: [PATCH 16/41] rename drop to tether-drop to adhere to npm registry --- drop/drop-tests.ts => tether-drop/tether-drop-tests.ts | 4 +++- drop/drop.d.ts => tether-drop/tether-drop.d.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) rename drop/drop-tests.ts => tether-drop/tether-drop-tests.ts (93%) rename drop/drop.d.ts => tether-drop/tether-drop.d.ts (98%) diff --git a/drop/drop-tests.ts b/tether-drop/tether-drop-tests.ts similarity index 93% rename from drop/drop-tests.ts rename to tether-drop/tether-drop-tests.ts index 0da04e9445..f67f746a7c 100644 --- a/drop/drop-tests.ts +++ b/tether-drop/tether-drop-tests.ts @@ -1,5 +1,7 @@ /// -/// +/// + +import 'tether-drop'; var yellowBox = document.querySelector(".yellow"); var greenBox = document.querySelector(".green"); diff --git a/drop/drop.d.ts b/tether-drop/tether-drop.d.ts similarity index 98% rename from drop/drop.d.ts rename to tether-drop/tether-drop.d.ts index 87ae4425b9..19c48ec7a1 100644 --- a/drop/drop.d.ts +++ b/tether-drop/tether-drop.d.ts @@ -56,6 +56,6 @@ declare namespace Drop { } } -declare module "drop" { +declare module "tether-drop" { export = Drop; } From 493d44982e5a935e29c79ac933761001211c9ef8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn?= Date: Wed, 10 Aug 2016 21:18:28 +0200 Subject: [PATCH 17/41] Add default export to angular-ui-router. --- angular-ui-router/angular-ui-router-tests.ts | 9 +++++---- angular-ui-router/angular-ui-router.d.ts | 10 ++-------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/angular-ui-router/angular-ui-router-tests.ts b/angular-ui-router/angular-ui-router-tests.ts index 9c5db1754a..a588faa448 100644 --- a/angular-ui-router/angular-ui-router-tests.ts +++ b/angular-ui-router/angular-ui-router-tests.ts @@ -1,6 +1,7 @@ /// -var myApp = angular.module('testModule'); +import uiRouterModule from "angular-ui-router"; +var myApp = angular.module("testModule", [uiRouterModule]); interface MyAppScope extends ng.IScope { items: string[]; @@ -141,7 +142,7 @@ class UrlLocatorTestService implements IUrlLocatorTestService { private $state: ng.ui.IStateService ) { $rootScope.$on("$locationChangeSuccess", (event: ng.IAngularEvent) => this.onLocationChangeSuccess(event)); - $rootScope.$on('$stateNotFound', (event: ng.IAngularEvent, unfoundState: ng.ui.IUnfoundState, fromState: ng.ui.IState, fromParams: {}) => + $rootScope.$on('$stateNotFound', (event: ng.IAngularEvent, unfoundState: ng.ui.IUnfoundState, fromState: ng.ui.IState, fromParams: {}) => this.onStateNotFound(event, unfoundState, fromState, fromParams)); } @@ -164,14 +165,14 @@ class UrlLocatorTestService implements IUrlLocatorTestService { }); } } - + private onStateNotFound(event: ng.IAngularEvent, unfoundState: ng.ui.IUnfoundState, fromState: ng.ui.IState, fromParams: {}) { var unfoundTo: string = unfoundState.to; var unfoundToParams: {} = unfoundState.toParams; - var unfoundOptions: ng.ui.IStateOptions = unfoundState.options + var unfoundOptions: ng.ui.IStateOptions = unfoundState.options } private stateServiceTest() { diff --git a/angular-ui-router/angular-ui-router.d.ts b/angular-ui-router/angular-ui-router.d.ts index 0f0ac8caa3..7e4f097c8c 100644 --- a/angular-ui-router/angular-ui-router.d.ts +++ b/angular-ui-router/angular-ui-router.d.ts @@ -7,13 +7,7 @@ // Support for AMD require and CommonJS declare module 'angular-ui-router' { - // Since angular-ui-router adds providers for a bunch of - // injectable dependencies, it doesn't really return any - // actual data except the plain string 'ui.router'. - // - // As such, I don't think anybody will ever use the actual - // default value of the module. So I've only included the - // the types. (@xogeny) + export default "ui.router"; export type IState = angular.ui.IState; export type IStateProvider = angular.ui.IStateProvider; export type IUrlMatcher = angular.ui.IUrlMatcher; @@ -109,7 +103,7 @@ declare namespace angular.ui { toParams: {}, options: IStateOptions } - + interface IStateProvider extends angular.IServiceProvider { state(name:string, config:IState): IStateProvider; state(config:IState): IStateProvider; From 3fa40795278939a0cb5937a25b5cd0c743ec1d0a Mon Sep 17 00:00:00 2001 From: Emm Date: Wed, 10 Aug 2016 21:06:52 +0200 Subject: [PATCH 18/41] Add useNullOrDefault config option to knex.js. --- knex/knex-tests.ts | 6 ++++++ knex/knex.d.ts | 1 + 2 files changed, 7 insertions(+) diff --git a/knex/knex-tests.ts b/knex/knex-tests.ts index 04ba8409ee..f4bbf01b42 100644 --- a/knex/knex-tests.ts +++ b/knex/knex-tests.ts @@ -78,6 +78,12 @@ var knex = Knex({ client: 'pg' }); +// useNullAsDefault +var knex = Knex({ + client: 'sqlite', + useNullAsDefault: true, +}); + knex('books').insert({title: 'Test'}).returning('*').toString(); // Migrations diff --git a/knex/knex.d.ts b/knex/knex.d.ts index a8501f2e51..2cb8280ea1 100644 --- a/knex/knex.d.ts +++ b/knex/knex.d.ts @@ -454,6 +454,7 @@ declare module "knex" { pool?: PoolConfig; migrations?: MigratorConfig; acquireConnectionTimeout?: number; + useNullAsDefault?: boolean; } interface ConnectionConfig { From e0e0f509d58c23cb230b9c6f6b353decde463ce8 Mon Sep 17 00:00:00 2001 From: Emm Date: Wed, 10 Aug 2016 21:09:52 +0200 Subject: [PATCH 19/41] Add search path config option to knex.js. --- knex/knex-tests.ts | 6 ++++++ knex/knex.d.ts | 1 + 2 files changed, 7 insertions(+) diff --git a/knex/knex-tests.ts b/knex/knex-tests.ts index f4bbf01b42..3a00c32551 100644 --- a/knex/knex-tests.ts +++ b/knex/knex-tests.ts @@ -78,6 +78,12 @@ var knex = Knex({ client: 'pg' }); +// searchPath +var knex = Knex({ + client: 'pg', + searchPath: 'public', +}); + // useNullAsDefault var knex = Knex({ client: 'sqlite', diff --git a/knex/knex.d.ts b/knex/knex.d.ts index 2cb8280ea1..64d530ed49 100644 --- a/knex/knex.d.ts +++ b/knex/knex.d.ts @@ -455,6 +455,7 @@ declare module "knex" { migrations?: MigratorConfig; acquireConnectionTimeout?: number; useNullAsDefault?: boolean; + searchPath?: string; } interface ConnectionConfig { From 11271655921d31fc8edecd17343c2bd2c11080e1 Mon Sep 17 00:00:00 2001 From: Yeiniel Suarez Sosa Date: Wed, 10 Aug 2016 15:09:28 -0500 Subject: [PATCH 20/41] Fixed return type for Client.stream() of cassandra-driver. --- cassandra-driver/cassandra-driver.d.ts | 36 +++++++++++++------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/cassandra-driver/cassandra-driver.d.ts b/cassandra-driver/cassandra-driver.d.ts index ac68985c31..9a4184b62e 100644 --- a/cassandra-driver/cassandra-driver.d.ts +++ b/cassandra-driver/cassandra-driver.d.ts @@ -16,10 +16,10 @@ declare module "cassandra-driver" { namespace policies { namespace addressResolution { - var EC2MultiRegionTranslator: EC2MultiRegionTranslatorStatic; + var EC2MultiRegionTranslator: EC2MultiRegionTranslatorStatic; interface AddressTranslator { - translate(address: string, port: number, callback: Callback): void; + translate(address: string, port: number, callback: Callback): void; } interface EC2MultiRegionTranslatorStatic { @@ -141,7 +141,7 @@ declare module "cassandra-driver" { var Tuple: TupleStatic; var Uuid: UuidStatic; - enum consistencies { + enum consistencies { any = 0, one, two, @@ -154,7 +154,7 @@ declare module "cassandra-driver" { localSerial, localOne } - + enum dataTypes { custom = 0, ascii, @@ -204,7 +204,7 @@ declare module "cassandra-driver" { fromString(value: string): BigDecimal; fromNumber(value: number): BigDecimal; } - + interface BigDecimal { equals(other: BigDecimal): boolean; inspect(): string; @@ -239,7 +239,7 @@ declare module "cassandra-driver" { interface IntegerStatic { new(bits: Array, sign: number): Integer; - + fromInt(value: number): Integer; fromNumber(value: number): Integer; fromBits(bits: Array): Integer; @@ -295,7 +295,7 @@ declare module "cassandra-driver" { fromString(value: string): LocalDate; fromBuffer(buffer: Buffer): LocalDate; } - + interface LocalDate { _value: number; year: number; @@ -384,7 +384,7 @@ declare module "cassandra-driver" { interface TimeUuidStatic { new (value?: Date, ticks?: number, nodeId?: string|Buffer, clockId?: string|Buffer): TimeUuid; - + fromDate(date: Date, ticks?: number, nodeId?: string|Buffer, clockId?: string|Buffer): TimeUuid; fromString(value: string): TimeUuid; min(date: Date, ticks?: number): TimeUuid; @@ -408,7 +408,7 @@ declare module "cassandra-driver" { interface Tuple { elements: Array; length: number; - + get(index: number): any; toString(): string; toJSON(): string; @@ -513,7 +513,7 @@ declare module "cassandra-driver" { execute(query: string, params?: any, options?: QueryOptions, callback?: ResultCallback): void; getReplicas(keyspace: string, token: Buffer): Array; // TODO: Should this be a more explicit return? shutdown(callback?: Callback): void; - stream(query: string, params?: any, options?: QueryOptions, callback?: Callback): void; + stream(query: string, params?: any, options?: QueryOptions, callback?: Callback): NodeJS.ReadableStream; } interface HostStatic { @@ -549,7 +549,7 @@ declare module "cassandra-driver" { } interface EncoderStatic { - new(protocolVersion: number, options: ClientOptions) : Encoder; + new(protocolVersion: number, options: ClientOptions) : Encoder; } interface Encoder { @@ -590,29 +590,29 @@ declare module "cassandra-driver" { } class ArgumentError extends DriverError { - constructor(message: string); + constructor(message: string); } class AuthenticationError extends DriverError { - constructor(message: string); + constructor(message: string); } class DriverInternalError extends DriverError { - constructor(message: string); + constructor(message: string); } class NoHostAvailableError extends DriverError { - constructor(innerErrors: any, message?: string); + constructor(innerErrors: any, message?: string); } class NotSupportedError extends DriverError { - constructor(message: string); + constructor(message: string); } class OperationTimedOutError extends DriverError {} class ResponseError extends DriverError { - constructor(code: number, message: string); + constructor(code: number, message: string); } } @@ -688,7 +688,7 @@ declare module "cassandra-driver" { interface IndexStatic { new (name: string, target: string, kind: IndexType, options: Object): Index; - + fromRows(indexRows: Array): Array; fromColumnRows(columnRows: Array, columnsByName: { [key:string]: ColumnInfo }): Array; } From 09a869c9aff51cd88250ad09b2a1b7b3cdb034d0 Mon Sep 17 00:00:00 2001 From: Jed Borovik Date: Wed, 10 Aug 2016 19:22:56 -0400 Subject: [PATCH 21/41] Change react-modal from export default to export = --- react-modal/react-modal-tests.tsx | 4 ++-- react-modal/react-modal.d.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/react-modal/react-modal-tests.tsx b/react-modal/react-modal-tests.tsx index 9a9814930d..40fc2a637e 100644 --- a/react-modal/react-modal-tests.tsx +++ b/react-modal/react-modal-tests.tsx @@ -2,7 +2,7 @@ /// import * as React from "react"; -import ReactModal from 'react-modal'; +import * as ReactModal from 'react-modal'; class ExampleOfUsingReactModal extends React.Component<{}, {}> { render() { @@ -46,4 +46,4 @@ class ExampleOfUsingReactModal extends React.Component<{}, {}> { ); } -}; \ No newline at end of file +}; diff --git a/react-modal/react-modal.d.ts b/react-modal/react-modal.d.ts index 2f2d0403d2..2aac95eacb 100644 --- a/react-modal/react-modal.d.ts +++ b/react-modal/react-modal.d.ts @@ -24,5 +24,5 @@ declare module "react-modal" { shouldCloseOnOverlayClick?: boolean } let ReactModal: __React.ClassicComponentClass; - export default ReactModal; + export = ReactModal; } From ff84f05542264c0ffbbcbdb90e9555269d9fcc47 Mon Sep 17 00:00:00 2001 From: Seth Westphal Date: Wed, 10 Aug 2016 19:58:41 -0500 Subject: [PATCH 22/41] Fix ExpressionAttributeNames. --- aws-sdk/aws-sdk.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws-sdk/aws-sdk.d.ts b/aws-sdk/aws-sdk.d.ts index cadb392863..cb35f34e97 100644 --- a/aws-sdk/aws-sdk.d.ts +++ b/aws-sdk/aws-sdk.d.ts @@ -329,7 +329,7 @@ declare module "aws-sdk" { interface _DDBDC_Generic { TableName: string; - ExpressionAttributeNames?: string[]; + ExpressionAttributeNames?: { [someKey: string]: string }; ReturnConsumedCapacity?: "INDEXES" | "TOTAL" | "NONE"; } From 0bc3512b989c065e94baf2df9771392bb79f0cfb Mon Sep 17 00:00:00 2001 From: Leonard Lausen Date: Thu, 11 Aug 2016 14:59:46 +1000 Subject: [PATCH 23/41] Add leaflet-geocoder-mapzen type declarations and tests for the basic usage of leaflet-geocoder-mapzen. Does not include the advanced usage patterns: https://github.com/mapzen/leaflet-geocoder/#advanced-usage --- .../leaflet-geocoder-mapzen-tests.ts | 10 + .../leaflet-geocoder-mapzen.d.ts | 177 ++++++++++++++++++ 2 files changed, 187 insertions(+) create mode 100644 leaflet-geocoder-mapzen/leaflet-geocoder-mapzen-tests.ts create mode 100644 leaflet-geocoder-mapzen/leaflet-geocoder-mapzen.d.ts diff --git a/leaflet-geocoder-mapzen/leaflet-geocoder-mapzen-tests.ts b/leaflet-geocoder-mapzen/leaflet-geocoder-mapzen-tests.ts new file mode 100644 index 0000000000..c6519ab371 --- /dev/null +++ b/leaflet-geocoder-mapzen/leaflet-geocoder-mapzen-tests.ts @@ -0,0 +1,10 @@ +/// +/// + +var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', + osmAttrib = '© OpenStreetMap contributors', + osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}), + map = new L.Map('map', {layers: [osm], center: new L.LatLng(-37.7772, 175.2756), zoom: 15 }); + +// Add geocoding plugin +L.control.geocoder('search-MKZrG6M').addTo(map); diff --git a/leaflet-geocoder-mapzen/leaflet-geocoder-mapzen.d.ts b/leaflet-geocoder-mapzen/leaflet-geocoder-mapzen.d.ts new file mode 100644 index 0000000000..8809472e43 --- /dev/null +++ b/leaflet-geocoder-mapzen/leaflet-geocoder-mapzen.d.ts @@ -0,0 +1,177 @@ +// Type definitions for leaflet-geocoder-mapzen v1.6.3 +// Project: https://github.com/mapzen/leaflet-geocoder +// Definitions by: Leonard Lausen +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + + +/// + +declare namespace L { + namespace Control { + export interface GeocoderStatic extends ClassStatic { + /** + * Creates a geocoder control. + */ + new (options?: GeocoderOptions): Geocoder; + } + + export interface Geocoder extends L.Control { + } + + export interface GeocoderOptions { + /** + * Host endpoint for a Pelias-compatible search API. + * + * Default value: 'https://search.mapzen.com/v1'. + */ + url?: string; + + /** + * If true, search is bounded by the current map view. + * You may also provide a custom bounding box in form of a LatLngBounds object. + * Note: bounds is not supported by autocomplete. + * + * Default value: false. + */ + bounds?: LatLngBounds | boolean; + + /** + * If true, search and autocomplete prioritizes results near the center + * of the current view. + * You may also provide a custom LatLng value + * (in any of the accepted Leaflet formats) to act as the center bias. + * + * Default value: 'true'. + */ + focus?: LatLng | boolean; + + /** + * Filters results by layers (documentation). + * If left blank, results will come from all available layers. + * + * Default value: null. + */ + layers?: string | any[] ; + + /** + * An object of key-value pairs which will be serialized + * into query parameters that will be passed to the API. + * This allows custom queries that are not already supported + * by the convenience options listed above. + * For a full list of supported parameters, + * please read the Mapzen Search documentation. + * + * IMPORTANT: some parameters only work with the /search endpoint, + * and do not apply to /autocomplete requests! + * All supplied parameters are passed through; + * this library doesn't know which are valid parameters and which are not. + * In the event that other options conflict with parameters passed through params, + * the params option takes precedence. + * + * Default value: null. + */ + params?: Object; + + /** + * The position of the control (one of the map corners). + * Can be 'topleft', 'topright', 'bottomleft', or 'bottomright'. + * + * Default value: 'topleft'. + */ + position?: PositionString; + + /** + * Attribution text to include. + * Set to blank or null to disable. + * + * Default value: 'Geocoding by Mapzen' + */ + attribution?: string; + + /** + * Placeholder text to display in the search input box. + * Set to blank or null to disable. + * + * Default value: 'Search' + */ + placeholder?: string; + + /** + * Tooltip text to display on the search icon. Set to blank or null to disable. + * + * Default value: 'Search' + */ + title?: string; + + /** + * If true, highlighting a search result pans the map to that location. + * + * Default value: true + */ + panToPoint?: boolean; + + /** + * If true, an icon is used to indicate a polygonal result, + * matching any non-"venue" or non-"address" layer type. + * If false, no icon is displayed. + * For custom icons, pass a string containing a path to the image. + * + * Default value: true + */ + polygonIcon?: boolean | string; + + /** + * If true, search results drops Leaflet's default blue markers onto the map. + * You may customize this marker's appearance and + * behavior using Leaflet marker options. + * + * Default value: true + */ + markers?: MarkerOptions | boolean; + + /** + * If true, the input box will expand to take up the full width of the map container. + * If an integer breakpoint is provided, + * the full width applies only if the map container width is below this breakpoint. + * + * Default value: 650 + */ + fullWidth?: number | boolean; + + /** + * If true, the search input is always expanded. + * It does not collapse into a button-only state. + * + * Default value: false + */ + expanded?: boolean; + + /** + * If true, suggested results are fetched on each keystroke. + * If false, this is disabled and users must obtain results + * by pressing the Enter key after typing in their query. + * + * Default value: true + */ + autocomplete?: boolean; + + /** + * If true, selected results will make a request to the service /place endpoint. + * If false, this is disabled. + * The geocoder does not handle responses to /place, + * you will need to do handle it yourself in the results event listener (see below). + * + * Default value: false + */ + place?: boolean; + } + } + + export namespace control { + + /** + * Creates a geocoder control. + */ + export function geocoder(api_key: string, options?: Control.GeocoderOptions): L.Control.Geocoder; + } +} From 247c4be0b7939a5558f9ff485f9a8abe6085b9d0 Mon Sep 17 00:00:00 2001 From: Oliver Joseph Ash Date: Thu, 11 Aug 2016 09:54:15 +0100 Subject: [PATCH 24/41] superagent typings: make buffer parameter optional --- superagent/superagent.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superagent/superagent.d.ts b/superagent/superagent.d.ts index f7ab4c88c9..1d89adeb6b 100644 --- a/superagent/superagent.d.ts +++ b/superagent/superagent.d.ts @@ -85,7 +85,7 @@ declare module "superagent" { accept(type: string): this; attach(field: string, file: string, filename?: string): this; auth(user: string, name: string): this; - buffer(val: boolean): this; + buffer(val?: boolean): this; clearTimeout(): this; end(callback?: CallbackHandler): this; field(name: string, val: string): this; From 1dd3713216e9a9d2a9917294e167d61bdec531a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C4=81rlis=20Ga=C5=86=C4=A3is?= Date: Thu, 11 Aug 2016 14:10:56 +0300 Subject: [PATCH 25/41] Added `opts` parameter to sheet_to_json method. --- xlsx/xlsx.d.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/xlsx/xlsx.d.ts b/xlsx/xlsx.d.ts index b761387681..766be99457 100644 --- a/xlsx/xlsx.d.ts +++ b/xlsx/xlsx.d.ts @@ -128,7 +128,11 @@ declare module 'xlsx' { } export interface IUtils { - sheet_to_json(worksheet:IWorkSheet):T[]; + sheet_to_json(worksheet:IWorkSheet, opts?: { + raw?: boolean; + range?: any; + header?: "A"|number|string[]; + }):T[]; sheet_to_csv(worksheet:IWorkSheet):any; sheet_to_formulae(worksheet:IWorkSheet):any; } From d16e4caf673c5b60f033fd5a4b0797de7924d56a Mon Sep 17 00:00:00 2001 From: viskin Date: Thu, 11 Aug 2016 14:40:11 +0300 Subject: [PATCH 26/41] added marker-animate-unobtrusive library --- .../marker-animate-unobtrusive-amd-tests.ts | 5 ++ .../marker-animate-unobtrusive-tests.ts | 50 +++++++++++++ .../marker-animate-unobtrusive.d.ts | 72 +++++++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 marker-animate-unobtrusive/marker-animate-unobtrusive-amd-tests.ts create mode 100644 marker-animate-unobtrusive/marker-animate-unobtrusive-tests.ts create mode 100644 marker-animate-unobtrusive/marker-animate-unobtrusive.d.ts diff --git a/marker-animate-unobtrusive/marker-animate-unobtrusive-amd-tests.ts b/marker-animate-unobtrusive/marker-animate-unobtrusive-amd-tests.ts new file mode 100644 index 0000000000..f86619fc90 --- /dev/null +++ b/marker-animate-unobtrusive/marker-animate-unobtrusive-amd-tests.ts @@ -0,0 +1,5 @@ +import SlidingMarker = require('SlidingMarker'); +import MarkerWithGhost = require('MarkerWithGhost'); + +SlidingMarker.initializeGlobally(); +MarkerWithGhost.initializeGlobally(); diff --git a/marker-animate-unobtrusive/marker-animate-unobtrusive-tests.ts b/marker-animate-unobtrusive/marker-animate-unobtrusive-tests.ts new file mode 100644 index 0000000000..73ad4da4b5 --- /dev/null +++ b/marker-animate-unobtrusive/marker-animate-unobtrusive-tests.ts @@ -0,0 +1,50 @@ +/// +/// + +function test_init() { + SlidingMarker.initializeGlobally(); + MarkerWithGhost.initializeGlobally(); +} + +function test_options() { + var options: SlidingMarkerOptions = { + position: new google.maps.LatLng(0, 0), + easing: "easeInOutSine", + duration: 1000, + animateFunctionAdapter: (marker, destPoint, easing, duration) => {} + }; + var m = new SlidingMarker(options); + var g = new MarkerWithGhost(options); +} + +function test_sliding_marker() { + let googleMarker: google.maps.Marker; + let p: google.maps.LatLng; + let d: number; + let e:jQuery.easing.IEasingType; + + var m = new SlidingMarker(); + googleMarker = m; + + p = m.getPosition(); + m.setDuration(d); + d = m.getDuration(); + m.setEasing(e); + e = m.getEasing(); + p = m.getAnimationPosition(); + m.setPositionNotAnimated(p); +} + +function test_marker_with_ghost() { + let p: google.maps.LatLng; + let d: number; + let e:jQuery.easing.IEasingType; + let slidingMarker: SlidingMarker; + + var g = new MarkerWithGhost(); + slidingMarker = g; + + g.setGhostPosition(p); + p = g.getGhostPosition(); + p = g.getGhostAnimationPosition(); +} diff --git a/marker-animate-unobtrusive/marker-animate-unobtrusive.d.ts b/marker-animate-unobtrusive/marker-animate-unobtrusive.d.ts new file mode 100644 index 0000000000..515791052b --- /dev/null +++ b/marker-animate-unobtrusive/marker-animate-unobtrusive.d.ts @@ -0,0 +1,72 @@ +// Type definitions for marker-animate-unobtrusive 0.2.8 +// Project: https://github.com/terikon/marker-animate-unobtrusive +// Definitions by: Roman Viskin +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare namespace jQuery.easing { + type IEasingType = + 'swing' | + 'easeInQuad' | + 'easeOutQuad' | + 'easeInOutQuad' | + 'easeInCubic' | + 'easeOutCubic' | + 'easeInOutCubic' | + 'easeInQuart' | + 'easeOutQuart' | + 'easeInOutQuart' | + 'easeInQuint' | + 'easeOutQuint' | + 'easeInOutQuint' | + 'easeInSine' | + 'easeOutSine' | + 'easeInOutSine' | + 'easeInExpo' | + 'easeOutExpo' | + 'easeInOutExpo' | + 'easeInCirc' | + 'easeOutCirc' | + 'easeInOutCirc' | + 'easeInElastic' | + 'easeOutElastic' | + 'easeInOutElastic' | + 'easeInBack' | + 'easeOutBack' | + 'easeInOutBack' | + 'easeInBounce' | + 'easeOutBounce' | + 'easeInOutBounce'; +} + +interface SlidingMarkerOptions extends google.maps.MarkerOptions { + easing?: jQuery.easing.IEasingType, + duration?: number, + animateFunctionAdapter?: (marker: google.maps.Marker, destPoint: google.maps.LatLng, easing: 'linear' | jQuery.easing.IEasingType, duration: number) => void +} + +declare class SlidingMarker extends google.maps.Marker { + static initializeGlobally(): void; + constructor(opts?: SlidingMarkerOptions); + setDuration(duration: number); + getDuration(): number; + setEasing(easing: jQuery.easing.IEasingType); + getEasing(): jQuery.easing.IEasingType; + getAnimationPosition(): google.maps.LatLng; + setPositionNotAnimated(position: google.maps.LatLng | google.maps.LatLngLiteral): void; +} + +declare class MarkerWithGhost extends SlidingMarker { + setGhostPosition(ghostPosition: google.maps.LatLng | google.maps.LatLngLiteral); + getGhostPosition(): google.maps.LatLng; + getGhostAnimationPosition(): google.maps.LatLng; +} + +declare module "SlidingMarker" { + export = SlidingMarker; +} + +declare module "MarkerWithGhost" { + export = MarkerWithGhost; +} From 0479daf2d17921abfbc9dd080d5e90565b4a57f5 Mon Sep 17 00:00:00 2001 From: viskin Date: Thu, 11 Aug 2016 14:45:01 +0300 Subject: [PATCH 27/41] fixed implicit "any" --- marker-animate-unobtrusive/marker-animate-unobtrusive.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/marker-animate-unobtrusive/marker-animate-unobtrusive.d.ts b/marker-animate-unobtrusive/marker-animate-unobtrusive.d.ts index 515791052b..61a4a680df 100644 --- a/marker-animate-unobtrusive/marker-animate-unobtrusive.d.ts +++ b/marker-animate-unobtrusive/marker-animate-unobtrusive.d.ts @@ -49,16 +49,16 @@ interface SlidingMarkerOptions extends google.maps.MarkerOptions { declare class SlidingMarker extends google.maps.Marker { static initializeGlobally(): void; constructor(opts?: SlidingMarkerOptions); - setDuration(duration: number); + setDuration(duration: number): void; getDuration(): number; - setEasing(easing: jQuery.easing.IEasingType); + setEasing(easing: jQuery.easing.IEasingType): void; getEasing(): jQuery.easing.IEasingType; getAnimationPosition(): google.maps.LatLng; setPositionNotAnimated(position: google.maps.LatLng | google.maps.LatLngLiteral): void; } declare class MarkerWithGhost extends SlidingMarker { - setGhostPosition(ghostPosition: google.maps.LatLng | google.maps.LatLngLiteral); + setGhostPosition(ghostPosition: google.maps.LatLng | google.maps.LatLngLiteral): void; getGhostPosition(): google.maps.LatLng; getGhostAnimationPosition(): google.maps.LatLng; } From 54a597604443b54609baf2bf006ba0733e7539e4 Mon Sep 17 00:00:00 2001 From: viskin Date: Thu, 11 Aug 2016 14:53:11 +0300 Subject: [PATCH 28/41] Fixed missing references in test --- .../marker-animate-unobtrusive-amd-tests.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/marker-animate-unobtrusive/marker-animate-unobtrusive-amd-tests.ts b/marker-animate-unobtrusive/marker-animate-unobtrusive-amd-tests.ts index f86619fc90..544c95af5a 100644 --- a/marker-animate-unobtrusive/marker-animate-unobtrusive-amd-tests.ts +++ b/marker-animate-unobtrusive/marker-animate-unobtrusive-amd-tests.ts @@ -1,3 +1,6 @@ +/// +/// + import SlidingMarker = require('SlidingMarker'); import MarkerWithGhost = require('MarkerWithGhost'); From 147f25f0b684675ca9b3cdecc9be0b3ace3e9187 Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Sun, 7 Aug 2016 22:50:15 +0200 Subject: [PATCH 29/41] Update to Electron 1.3.3 --- github-electron/github-electron-main-tests.ts | 12 ++ github-electron/github-electron.d.ts | 111 ++++++++++++++++-- 2 files changed, 111 insertions(+), 12 deletions(-) diff --git a/github-electron/github-electron-main-tests.ts b/github-electron/github-electron-main-tests.ts index 0392702e6a..bebf0b99c8 100644 --- a/github-electron/github-electron-main-tests.ts +++ b/github-electron/github-electron-main-tests.ts @@ -985,3 +985,15 @@ app.on('ready', function () { console.log(webContents.getAllWebContents()); console.log(webContents.getFocusedWebContents()); + +var win = new BrowserWindow({ + webPreferences: { + offscreen: true + } +}); + +win.webContents.on('paint', (event, dirty, image) => { + console.log(dirty, image.getBitmap()); +}); + +win.loadURL('http://github.com'); diff --git a/github-electron/github-electron.d.ts b/github-electron/github-electron.d.ts index 0961eb03cf..7b246966ab 100644 --- a/github-electron/github-electron.d.ts +++ b/github-electron/github-electron.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Electron v1.3.2 +// Type definitions for Electron v1.3.3 // Project: http://electron.atom.io/ // Definitions by: jedmao , rhysd , Milan Burda // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -299,13 +299,13 @@ declare namespace Electron { * Note: This is only implemented on macOS and Windows. * On macOS, you can only register protocols that have been added to your app's info.plist. */ - setAsDefaultProtocolClient(protocol: string): void; + setAsDefaultProtocolClient(protocol: string): boolean; /** * Removes the current executable as the default handler for a protocol (aka URI scheme). * * Note: This is only implemented on macOS and Windows. */ - removeAsDefaultProtocolClient(protocol: string): void; + removeAsDefaultProtocolClient(protocol: string): boolean; /** * @returns Whether the current executable is the default handler for a protocol (aka URI scheme). * @@ -317,7 +317,7 @@ declare namespace Electron { * * Note: This API is only available on Windows. */ - setUserTasks(tasks: Task[]): void; + setUserTasks(tasks: Task[]): boolean; /** * This method makes your application a Single Instance Application instead of allowing * multiple instances of your app to run, this will ensure that only a single instance @@ -349,6 +349,8 @@ declare namespace Electron { getCurrentActivityType(): string; /** * Changes the Application User Model ID to id. + * + * Note: This is only implemented on Windows. */ setAppUserModelId(id: string): void; /** @@ -807,6 +809,10 @@ declare namespace Electron { * @returns Whether the window is focused. */ isFocused(): boolean; + /** + * @returns Whether the window is destroyed. + */ + isDestroyed(): boolean; /** * Shows and gives focus to the window. */ @@ -877,6 +883,14 @@ declare namespace Electron { * @returns The window's width, height, x and y values. */ getBounds(): Rectangle; + /** + * Resizes and moves the window's client area (e.g. the web page) to width, height, x, y. + */ + setContentBounds(options: Rectangle, animate?: boolean): void; + /** + * @returns The window's client area (e.g. the web page) width, height, x and y values. + */ + getContentBounds(): Rectangle; /** * Resizes the window to width and height. */ @@ -1101,7 +1115,13 @@ declare namespace Electron { * @param progress Valid range is [0, 1.0]. If < 0, the progress bar is removed. * If greater than 0, it becomes indeterminate. */ - setProgressBar(progress: number): void; + setProgressBar(progress: number, options?: { + /** + * Mode for the progress bar. + * Note: This is only implemented on Windows. + */ + mode: 'none' | 'normal' | 'indeterminate' | 'error' | 'paused' + }): void; /** * Sets a 16px overlay onto the current Taskbar icon, usually used to convey * some sort of application status or to passively notify the user. @@ -1136,7 +1156,12 @@ declare namespace Electron { * * Note: This API is available only on Windows. */ - setThumbnailClip(region: Rectangle): void; + setThumbnailClip(region: Rectangle): boolean; + /** + * Sets the toolTip that is displayed when hovering over the window thumbnail in the taskbar. + * Note: This API is available only on Windows. + */ + setThumbnailToolTip(toolTip: string): boolean; /** * Same as webContents.showDefinitionForSelection(). * Note: This API is available only on macOS. @@ -1379,9 +1404,14 @@ declare namespace Electron { defaultEncoding?: string; /** * Whether to throttle animations and timers when the page becomes background. - * Default: true + * Default: true. */ backgroundThrottling?: boolean; + /** + * Whether to enable offscreen rendering for the browser window. + * Default: false. + */ + offscreen?: boolean; } interface BrowserWindowOptions { @@ -2266,8 +2296,8 @@ declare namespace Electron { } type MenuItemType = 'normal' | 'separator' | 'submenu' | 'checkbox' | 'radio'; - type MenuItemRole = 'undo' | 'redo' | 'cut' | 'copy' | 'paste' | 'pasteandmatchstyle' | 'selectall' | 'delete' | 'minimize' | 'close' | 'quit' | 'togglefullscreen'; - type MenuItemRoleMac = 'about' | 'hide' | 'hideothers' | 'unhide' | 'front' | 'zoom' | 'window' | 'help' | 'services'; + type MenuItemRole = 'undo' | 'redo' | 'cut' | 'copy' | 'paste' | 'pasteandmatchstyle' | 'selectall' | 'delete' | 'minimize' | 'close' | 'quit' | 'togglefullscreen' | 'resetzoom' | 'zoomin' | 'zoomout'; + type MenuItemRoleMac = 'about' | 'hide' | 'hideothers' | 'unhide' | 'startspeaking' | 'stopspeaking' | 'front' | 'zoom' | 'window' | 'help' | 'services'; interface MenuItemOptions { /** @@ -2458,9 +2488,17 @@ declare namespace Electron { */ toJPEG(quality: number): Buffer; /** - * @returns Buffer that contains the image's raw pixel data. + * @returns Buffer that contains a copy of the image's raw bitmap pixel data. */ toBitmap(): Buffer; + /** + * @returns Buffer that contains the image's raw bitmap pixel data. + * + * The difference between getBitmap() and toBitmap() is, getBitmap() does not copy the bitmap data, + * so you have to use the returned Buffer immediately in current event loop tick, + * otherwise the data might be changed or destroyed. + */ + getBitmap(): Buffer; /** * @returns string The data URL of the image. */ @@ -3336,6 +3374,26 @@ declare namespace Electron { * Note: This is only implemented on macOS. */ isDarkMode(): boolean; + /** + * @returns If the Swipe between pages setting is on. + * + * Note: This is only implemented on macOS. + */ + isSwipeTrackingFromScrollEventsEnabled(): boolean; + /** + * Posts event as native notifications of macOS. + * The userInfo contains the user information dictionary sent along with the notification. + * + * Note: This is only implemented on macOS. + */ + postNotification(event: string, userInfo: Object): void; + /** + * Posts event as native notifications of macOS. + * The userInfo contains the user information dictionary sent along with the notification. + * + * Note: This is only implemented on macOS. + */ + postLocalNotification(event: string, userInfo: Object): void; /** * Subscribes to native notifications of macOS, callback will be called when the corresponding event happens. * The id of the subscriber is returned, which can be used to unsubscribe the event. @@ -3722,9 +3780,9 @@ declare namespace Electron { */ on(event: 'select-bluetooth-device', listener: (event: Event, deviceList: BluetoothDevice[], callback: (deviceId: string) => void) => void): this; /** - * Emitted when a page's view is repainted. + * Emitted when a new frame is generated. Only the dirty area is passed in the buffer. */ - on(event: 'view-painted', listener: Function): this; + on(event: 'paint', listener: (event: Event, dirtyRect: Rectangle, image: NativeImage) => void): this; on(event: string, listener: Function): this; /** * Loads the url in the window. @@ -4023,6 +4081,31 @@ declare namespace Electron { * Note: This API is available only on macOS. */ showDefinitionForSelection(): void; + /** + * @returns Whether offscreen rendering is enabled. + */ + isOffscreen(): boolean; + /** + * If offscreen rendering is enabled and not painting, start painting. + */ + startPainting(): void; + /** + * If offscreen rendering is enabled and painting, stop painting. + */ + stopPainting(): void; + /** + * If offscreen rendering is enabled returns whether it is currently painting. + */ + isPainting(): boolean; + /** + * If offscreen rendering is enabled sets the frame rate to the specified number. + * Only values between 1 and 60 are accepted. + */ + setFrameRate(fps: number): void; + /** + * If offscreen rendering is enabled returns the current frame rate. + */ + getFrameRate(): number; /** * Sets the item as dragging item for current drag-drop operation. */ @@ -4679,6 +4762,10 @@ declare namespace Electron { * @returns The title of guest page. */ getTitle(): string; + /** + * @returns Whether the web page is destroyed. + */ + isDestroyed(): boolean; /** * @returns Whether guest page is still loading resources. */ From 8a2c4d2aceadb8f2545c3464ef447efad428f6ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlado=20Te=C5=A1anovi=C4=87?= Date: Thu, 11 Aug 2016 15:58:47 +0200 Subject: [PATCH 30/41] removed private function --- jsonschema/jsonschema.d.ts | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/jsonschema/jsonschema.d.ts b/jsonschema/jsonschema.d.ts index 9e32dbfded..1c2f0f915e 100644 --- a/jsonschema/jsonschema.d.ts +++ b/jsonschema/jsonschema.d.ts @@ -98,17 +98,6 @@ declare module "jsonschema" { * @param urn */ getSchema(urn: string): {}; - - /** - * Validates an instance against the schema (the actual work horse) - * @param instance - * @param schema - * @param options - * @param ctx - * @private - * @return {IJSONSchemaResult} - */ - validateSchema(instance: any, schema: {}, options?: {}, ctx?: {}): IJSONSchemaResult } } From e611d74ee8345ddf400cd7fe353e9ff7991bf31a Mon Sep 17 00:00:00 2001 From: rbanderton Date: Thu, 11 Aug 2016 09:40:20 -0500 Subject: [PATCH 31/41] Added point.r function option Per https://github.com/c3js/c3/issues/179 supplying a function to `point.r` is supported. --- c3/c3.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c3/c3.d.ts b/c3/c3.d.ts index f5159090d2..2838ba2675 100644 --- a/c3/c3.d.ts +++ b/c3/c3.d.ts @@ -747,7 +747,7 @@ declare namespace c3 { /** * The radius size of each point. */ - r?: number; + r?: number | ((d: any) => number); focus?: { expand: { From 935e0c7a782959f990479f7bc2ded1259a1fcbde Mon Sep 17 00:00:00 2001 From: "Remo H. Jansen" Date: Thu, 11 Aug 2016 18:34:05 +0100 Subject: [PATCH 32/41] Create inversify-inject-decorators.d.ts --- .../inversify-inject-decorators.d.ts | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 inversify-inject-decorators/inversify-inject-decorators.d.ts diff --git a/inversify-inject-decorators/inversify-inject-decorators.d.ts b/inversify-inject-decorators/inversify-inject-decorators.d.ts new file mode 100644 index 0000000000..da567815e9 --- /dev/null +++ b/inversify-inject-decorators/inversify-inject-decorators.d.ts @@ -0,0 +1,32 @@ +// Type definitions for inversify-inject-decorators 1.0.0-beta.1 +// Project: https://github.com/inversify/inversify-inject-decorators +// Definitions by: inversify +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare namespace inversifyInjectDecorators { + + interface InjectDecorators { + + lazyInject: (serviceIdentifier: (string|Symbol|inversify.interfaces.Newable)) => + (proto: any, key: string) => void; + + lazyInjectNamed: (serviceIdentifier: (string|Symbol|inversify.interfaces.Newable), named: string) => + (proto: any, key: string) => void; + + lazyInjectTagged: (serviceIdentifier: (string|Symbol|inversify.interfaces.Newable), key: string, value: any) => + (proto: any, propertyName: string) => void; + + lazyMultiInject: (serviceIdentifier: (string|Symbol|inversify.interfaces.Newable)) => + (proto: any, key: string) => void; + + } + + export default function getDecorators(kernel: inversify.interfaces.Kernel): InjectDecorators; + +} + +declare module "inversify-inject-decorators" { + export = inversifyInjectDecorators; +} From 4ee6064b2a017bff9d522e30c4b33b9f02d9fa8c Mon Sep 17 00:00:00 2001 From: "Remo H. Jansen" Date: Thu, 11 Aug 2016 18:34:56 +0100 Subject: [PATCH 33/41] Create inversify-inject-decorators-tests.ts --- .../inversify-inject-decorators-tests.ts | 214 ++++++++++++++++++ 1 file changed, 214 insertions(+) create mode 100644 inversify-inject-decorators/inversify-inject-decorators-tests.ts diff --git a/inversify-inject-decorators/inversify-inject-decorators-tests.ts b/inversify-inject-decorators/inversify-inject-decorators-tests.ts new file mode 100644 index 0000000000..468bbaf763 --- /dev/null +++ b/inversify-inject-decorators/inversify-inject-decorators-tests.ts @@ -0,0 +1,214 @@ +/// +/// + +import getDecorators from "inversify-inject-decorators"; +import { Kernel, injectable, tagged, named } from "inversify"; + +module lazyInject { + + let kernel = new Kernel(); + let { lazyInject } = getDecorators(kernel); + let TYPES = { Weapon: "Weapon" }; + + interface Weapon { + name: string; + durability: number; + use(): void; + } + + @injectable() + class Sword implements Weapon { + public name: string; + public durability: number; + public constructor() { + this.durability = 100; + this.name = "Sword"; + } + public use() { + this.durability = this.durability - 10; + } + } + + class Warrior { + @lazyInject(TYPES.Weapon) + public weapon: Weapon; + } + + kernel.bind(TYPES.Weapon).to(Sword); + + let warrior = new Warrior(); + console.log(warrior.weapon instanceof Sword); // true + +} + +module lazyInjectNamed { + + let kernel = new Kernel(); + let { lazyInjectNamed } = getDecorators(kernel); + let TYPES = { Weapon: "Weapon" }; + + interface Weapon { + name: string; + durability: number; + use(): void; + } + + @injectable() + class Sword implements Weapon { + public name: string; + public durability: number; + public constructor() { + this.durability = 100; + this.name = "Sword"; + } + public use() { + this.durability = this.durability - 10; + } + } + + @injectable() + class Shuriken implements Weapon { + public name: string; + public durability: number; + public constructor() { + this.durability = 100; + this.name = "Shuriken"; + } + public use() { + this.durability = this.durability - 10; + } + } + + class Warrior { + + @lazyInjectNamed(TYPES.Weapon, "not-throwwable") + @named("not-throwwable") + public primaryWeapon: Weapon; + + @lazyInjectNamed(TYPES.Weapon, "throwwable") + @named("throwwable") + public secondaryWeapon: Weapon; + + } + + kernel.bind(TYPES.Weapon).to(Sword).whenTargetNamed("not-throwwable"); + kernel.bind(TYPES.Weapon).to(Shuriken).whenTargetNamed("throwwable"); + + let warrior = new Warrior(); + console.log(warrior.primaryWeapon instanceof Sword); // true + console.log(warrior.primaryWeapon instanceof Shuriken); // true + +} + +module lazyInjectTagged { + + let kernel = new Kernel(); + let { lazyInjectTagged } = getDecorators(kernel); + let TYPES = { Weapon: "Weapon" }; + + interface Weapon { + name: string; + durability: number; + use(): void; + } + + @injectable() + class Sword implements Weapon { + public name: string; + public durability: number; + public constructor() { + this.durability = 100; + this.name = "Sword"; + } + public use() { + this.durability = this.durability - 10; + } + } + + @injectable() + class Shuriken implements Weapon { + public name: string; + public durability: number; + public constructor() { + this.durability = 100; + this.name = "Shuriken"; + } + public use() { + this.durability = this.durability - 10; + } + } + + class Warrior { + + @lazyInjectTagged(TYPES.Weapon, "throwwable", false) + @tagged("throwwable", false) + public primaryWeapon: Weapon; + + @lazyInjectTagged(TYPES.Weapon, "throwwable", true) + @tagged("throwwable", true) + public secondaryWeapon: Weapon; + + } + + kernel.bind(TYPES.Weapon).to(Sword).whenTargetTagged("throwwable", false); + kernel.bind(TYPES.Weapon).to(Shuriken).whenTargetTagged("throwwable", true); + + let warrior = new Warrior(); + console.log(warrior.primaryWeapon instanceof Sword); // true + console.log(warrior.primaryWeapon instanceof Shuriken); // true + +} + +module lazyMultiInject { + + let kernel = new Kernel(); + let { lazyMultiInject } = getDecorators(kernel); + let TYPES = { Weapon: "Weapon" }; + + interface Weapon { + name: string; + durability: number; + use(): void; + } + + @injectable() + class Sword implements Weapon { + public name: string; + public durability: number; + public constructor() { + this.durability = 100; + this.name = "Sword"; + } + public use() { + this.durability = this.durability - 10; + } + } + + @injectable() + class Shuriken implements Weapon { + public name: string; + public durability: number; + public constructor() { + this.durability = 100; + this.name = "Shuriken"; + } + public use() { + this.durability = this.durability - 10; + } + } + + class Warrior { + + @lazyMultiInject(TYPES.Weapon) + public weapons: Weapon[]; + + } + + kernel.bind(TYPES.Weapon).to(Sword); + kernel.bind(TYPES.Weapon).to(Shuriken); + + let warrior = new Warrior(); + console.log(warrior.weapons[0] instanceof Sword); // true + console.log(warrior.weapons[1] instanceof Shuriken); // true + +} From c27a53475311ffc7fa463f4124c7f11237a0997b Mon Sep 17 00:00:00 2001 From: "Remo H. Jansen" Date: Thu, 11 Aug 2016 18:47:12 +0100 Subject: [PATCH 34/41] Update inversify-inject-decorators.d.ts --- inversify-inject-decorators/inversify-inject-decorators.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inversify-inject-decorators/inversify-inject-decorators.d.ts b/inversify-inject-decorators/inversify-inject-decorators.d.ts index da567815e9..032ed40cdd 100644 --- a/inversify-inject-decorators/inversify-inject-decorators.d.ts +++ b/inversify-inject-decorators/inversify-inject-decorators.d.ts @@ -23,10 +23,10 @@ declare namespace inversifyInjectDecorators { } - export default function getDecorators(kernel: inversify.interfaces.Kernel): InjectDecorators; + export function getDecorators(kernel: inversify.interfaces.Kernel): InjectDecorators; } declare module "inversify-inject-decorators" { - export = inversifyInjectDecorators; + export default inversifyInjectDecorators.getDecorators; } From 8e3619521cbc2833679ee0cd7196b10d91a95666 Mon Sep 17 00:00:00 2001 From: Hagai Cohen Date: Thu, 11 Aug 2016 19:20:48 +0300 Subject: [PATCH 35/41] Fixed XLSX typings --- xlsx/xlsx.d.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/xlsx/xlsx.d.ts b/xlsx/xlsx.d.ts index 766be99457..68f89b545a 100644 --- a/xlsx/xlsx.d.ts +++ b/xlsx/xlsx.d.ts @@ -7,6 +7,7 @@ declare module 'xlsx' { export function readFile(filename:string, opts?:IParsingOptions):IWorkBook; export function read(data:any, opts?:IParsingOptions):IWorkBook; + export function write(data:any, opts?:IParsingOptions): any; export var utils:IUtils; export interface IProperties { @@ -41,6 +42,7 @@ declare module 'xlsx' { bookSheets?:boolean; bookVBA?:boolean; password?:string; + bookType?:string; /** * Possible options: 'binary', 'base64', 'buffer', 'file' @@ -127,14 +129,21 @@ declare module 'xlsx' { s?: string; } + export interface ICell { + c: number; + r: number; + } + export interface IUtils { sheet_to_json(worksheet:IWorkSheet, opts?: { raw?: boolean; range?: any; header?: "A"|number|string[]; }):T[]; - sheet_to_csv(worksheet:IWorkSheet):any; - sheet_to_formulae(worksheet:IWorkSheet):any; + sheet_to_csv(worksheet: IWorkSheet):any; + sheet_to_formulae(worksheet: IWorkSheet):any; + encode_cell(cell: ICell): any; + encode_range(s: ICell, e: ICell): any; } } From 479d12f779a8486edd58d451d7ca2a8728baf3dc Mon Sep 17 00:00:00 2001 From: Nicholas Iannone Date: Thu, 11 Aug 2016 14:56:46 -0500 Subject: [PATCH 36/41] Cleaned up resource interfaces. --- twilio/twilio.d.ts | 863 +++++++++------------------------------------ 1 file changed, 165 insertions(+), 698 deletions(-) diff --git a/twilio/twilio.d.ts b/twilio/twilio.d.ts index e7b28d7636..0b4de0c36d 100644 --- a/twilio/twilio.d.ts +++ b/twilio/twilio.d.ts @@ -44,7 +44,7 @@ export module twilio { // validateRequest // validateExpressRequest - /// ??? + /// Random stuff export interface GrantPayload {} export interface Grant { @@ -56,6 +56,39 @@ export module twilio { export interface RestMethod { (args: any | BaseRequestCallback, callback?: RequestCallback): Q.Promise; } + /// Resource stock interfaces + export interface BaseMappedResource { + (resourceSid: string): T; + } + + export interface Resource { + get: RestMethod; + } + + export interface DeletableResource extends Resource { + delete: RestMethod; + } + + export interface ListableResource extends Resource { + list: RestMethod; + } + + export interface MappedResource extends Resource, BaseMappedResource {} + + export interface PostableResource extends Resource { + post: RestMethod; + } + + export interface InstanceResource extends PostableResource, DeletableResource { + update: RestMethod; + } + + export interface CreatableMappedResource extends MappedResource, PostableResource { + create: RestMethod; + } + + export interface ListMappedResource extends CreatableMappedResource, ListableResource {} + /// AccessToken.js export interface IpMessagingGrantOptions { serviceSid: string; @@ -193,9 +226,9 @@ export module twilio { /// PricingClient.js export class PricingClient extends Client { - voice: VoiceResource; - phoneNumbers: PhoneNumberResource; - messaging: MessagingResource; + voice: PricingVoiceResource; + phoneNumbers: PricingPhoneNumberResource; + messaging: PricingMessagingResource; constructor(sid?: string, tkn?: string, options?: ClientOptions); } @@ -419,122 +452,49 @@ export module twilio { export function validateExpressRequest(request: Express.Request, authToken: string, options?: WebhookExpressOptions): boolean; /// resources/Accounts.js - export interface OutgoingCallerIdInstance { - get: RestMethod; - post: RestMethod; + export interface OutgoingCallerIdInstance extends InstanceResource { put: RestMethod; - delete: RestMethod; + } + export type OutgoingCallerIdResource = CreatableMappedResource; + + export type SMSMessageInstance = Resource; + export type SMSMessageResource = CreatableMappedResource; + + export interface SMSShortCodeInstance extends PostableResource { update: RestMethod; } - - export interface OutgoingCallerIdResource { - (resourceSid: string): OutgoingCallerIdInstance; - get: RestMethod; - post: RestMethod; - create: RestMethod; - } - - export interface SMSMessageInstance { - get: RestMethod; - } - - export interface SMSMessageResource { - (resourceSid: string): SMSMessageInstance; - get: RestMethod; - post: RestMethod; - create: RestMethod; - } - - export interface SMSShortCodeInstance { - get: RestMethod; - post: RestMethod; - update: RestMethod; - } - - export interface SMSShortCodeResource { - get: RestMethod; - } + export type SMSShortCodeResource = MappedResource; export interface SMSIntermediary { messages: SMSMessageResource; shortCodes: SMSShortCodeResource; } - export interface ApplicationInstance { - get: RestMethod; - post: RestMethod; - delete: RestMethod; + export type ApplicationInstance = InstanceResource; + export type ApplicationResource = CreatableMappedResource; + + export interface ConnectAppInstance extends PostableResource { update: RestMethod; } + export type ConnectAppResource = MappedResource; - export interface ApplicationResource { - (resourceSid: string): ApplicationInstance; - get: RestMethod; - post: RestMethod; - create: RestMethod; - } - - export interface ConnectAppInstance { - get: RestMethod; - post: RestMethod; - update: RestMethod; - } - - export interface ConnectAppResource { - (resourceSid: string): ConnectAppInstance; - get: RestMethod; - } - - export interface AuthorizedConnectAppInstance { - get: RestMethod; - } - - export interface AuthorizedConnectAppResource { - (resourceSid: string): AuthorizedConnectAppInstance; - get: RestMethod; - } + export type AuthorizedConnectAppInstance = Resource; + export type AuthorizedConnectAppResource = MappedResource; export interface TokenInstance {} - - export interface TokenResource { - (resourceSid: string): TokenInstance; + export interface TokenResource extends BaseMappedResource { post: RestMethod; create: RestMethod; } - export interface TranscriptionInstance { - get: RestMethod; - delete: RestMethod; - } + export type TranscriptionInstance = DeletableResource; + export type TranscriptionResource = MappedResource; - export interface TranscriptionResource { - (resourceSid: string): TranscriptionInstance; - get: RestMethod; - } + export type NotificationInstance = DeletableResource; + export type NotificationResource = MappedResource; - export interface NotificationInstance { - get: RestMethod; - delete: RestMethod; - } - - export interface NotificationResource { - (resourceSid: string): NotificationInstance; - get: RestMethod; - } - - export interface UsageTriggerInstance { - get: RestMethod; - post: RestMethod; - delete: RestMethod; - update: RestMethod; - } - - export interface UsageTriggerResource { - (resourceSid: string): UsageTriggerInstance; - get: RestMethod; - post: RestMethod; - create: RestMethod; - } + export type UsageTriggerInstance = InstanceResource; + export type UsageTriggerResource = CreatableMappedResource; export interface UsageIntermediary { records: UsageRecordResource; @@ -547,22 +507,12 @@ export module twilio { credentialLists: CredentialListResource; } - export interface KeyInstance { - get: RestMethod; - post: RestMethod; - delete: RestMethod; + export type KeyInstance = InstanceResource; + export type KeyResource = CreatableMappedResource; + + export interface AccountInstance extends PostableResource { update: RestMethod; - } - - export interface KeyResource { - (resourceSid: string): KeyInstance; - get: RestMethod; - post: RestMethod; - create: RestMethod; - } - - export interface AccountResource { - (accountSid: string): AccountResource; + put: RestMethod; // Mixed-in resources availablePhoneNumbers: AvailablePhoneNumberResource; @@ -584,260 +534,108 @@ export module twilio { sip: SIPIntermediary; addresses: AddressResource; keys: KeyResource; - - // Mixed-in Methods - put: RestMethod; - post: RestMethod; - get: RestMethod; - update: RestMethod; - list: RestMethod; } + export interface AccountResource extends AccountInstance, ListMappedResource {} + /// resources/Addresses.js - export interface DependentPhoneNumberResource { - get: RestMethod; - list: RestMethod; - } + export type DependentPhoneNumberResource = ListableResource; - export interface AddressInstance { + export interface AddressInstance extends PostableResource, DeletableResource { // Mixins dependentPhoneNumbers: DependentPhoneNumberResource; - - // Rest Methods - get: RestMethod; - post: RestMethod; - delete: RestMethod; - } - - export interface AddressResource { - (resourceSid: string): AddressInstance; - get: RestMethod; - list: RestMethod; - post: RestMethod; - create: RestMethod; } + export type AddressResource = ListMappedResource; /// resources/AvailablePhoneNumbers.js - export interface AvailablePhoneNumberResourceGroup { - get: RestMethod; - list: RestMethod; + export interface AvailablePhoneNumberResourceGroup extends ListableResource { search: RestMethod; } - export interface AvailablePhoneNumberInstance { local: AvailablePhoneNumberResourceGroup; tollFree: AvailablePhoneNumberResourceGroup; mobile: AvailablePhoneNumberResourceGroup; } - - export interface AvailablePhoneNumberResource { - (isoCode: string): AvailablePhoneNumberInstance; - } + export type AvailablePhoneNumberResource = BaseMappedResource; /// resources/Calls.js - export interface CallRecordingResource { - get: RestMethod; - list: RestMethod; - } - - export interface CallNotificationResource { - get: RestMethod; - list: RestMethod; - } - - export interface CallFeedbackResource { - get: RestMethod; - post: RestMethod; - delete: RestMethod; + export type CallRecordingResource = ListableResource; + export type CallNotificationResource = ListableResource; + export interface CallFeedbackResource extends PostableResource, DeletableResource { create: RestMethod; } - export interface CallInstance { + export interface CallInstance extends InstanceResource { recordings: CallRecordingResource; notifications: CallNotificationResource; feedback: CallFeedbackResource; - - get: RestMethod; - post: RestMethod; - delete: RestMethod; - update: RestMethod; } - export interface CallFeedbackSummaryInstance { - get: RestMethod; - delete: RestMethod; - } - - export interface CallFeedbackSummaryResource { - (resourceSid: string): CallFeedbackSummaryInstance; + export type CallFeedbackSummaryInstance = DeletableResource; + export interface CallFeedbackSummaryResource extends BaseMappedResource { post: RestMethod; create: RestMethod; } - - export interface CallResource { - (resourceSid: string): CallInstance; - - get: RestMethod; - post: RestMethod; - create: RestMethod; - + export interface CallResource extends CreatableMappedResource { feedbackSummary: CallFeedbackSummaryResource; } /// resources/Conferences.js - export interface ConferenceParticipantInstance { - get: RestMethod; - post: RestMethod; - delete: RestMethod; - update: RestMethod; + export interface ConferenceParticipantInstance extends InstanceResource { kick: RestMethod; } - - export interface ConferenceParticipantResource { - (resourceSid: string): ConferenceParticipantInstance; - - get: RestMethod; - list: RestMethod; - } - - export interface ConferenceInstance { - get: RestMethod; - + export interface ConferenceParticipantResource extends MappedResource, ListableResource {} + export interface ConferenceInstance extends Resource { participants: ConferenceParticipantResource; } - - export interface ConferenceResource { - (resourceSid: string): ConferenceInstance; - - get: RestMethod; - list: RestMethod; - } + export interface ConferenceResource extends MappedResource, ListableResource {} /// resources/IncomingPhoneNumbers.js - export interface IncomingPhoneNumberResourceGroup { - get: RestMethod; - post: RestMethod; + export interface IncomingPhoneNumberResourceGroup extends PostableResource { create: RestMethod; } - - export interface IncomingPhoneNumberInstance { - get: RestMethod; - post: RestMethod; + export interface IncomingPhoneNumberInstance extends InstanceResource { put: RestMethod; - delete: RestMethod; - update: RestMethod; } - - export interface IncomingPhoneNumberResource { - (resourceSid: string): IncomingPhoneNumberInstance; - - get: RestMethod; - post: RestMethod; - create: RestMethod; - + export interface IncomingPhoneNumberResource extends CreatableMappedResource { local: IncomingPhoneNumberResourceGroup; tollFree: IncomingPhoneNumberResourceGroup; mobile: IncomingPhoneNumberResourceGroup; } /// resources/Messages.js - export interface MessageMediaInstance { - get: RestMethod; - delete: RestMethod; - } - - export interface MessageMediaResource { - (resourceSid: string): MessageMediaInstance; - - get: RestMethod; - list: RestMethod; - } - - export interface MessageInstance { - get: RestMethod; - post: RestMethod; - delete: RestMethod; - + export type MessageMediaInstance = DeletableResource; + export interface MessageMediaResource extends MappedResource, ListableResource {} + export interface MessageInstance extends PostableResource, DeletableResource { media: MessageMediaResource; } - - export interface MessageResource { - (resourceSid: string): MessageInstance; - - get: RestMethod; - list: RestMethod; - post: RestMethod; - create: RestMethod; - } + export type MessageResource = ListMappedResource; /// resources/Queues.js - export interface QueueMemberInstance { - get: RestMethod; - post: RestMethod; + export interface QueueMemberInstance extends PostableResource { update: RestMethod; } - - export interface QueueMemberResource { - (resourceSid: string): QueueMemberInstance; - - get: RestMethod; - + export interface QueueMemberResource extends MappedResource { front: QueueMemberInstance; } - export interface QueueInstance { + export interface QueueInstance extends InstanceResource { members: QueueMemberResource; - - get: RestMethod; - post: RestMethod; - delete: RestMethod; - update: RestMethod; - } - - export interface QueueResource { - (resourceSid: string): QueueInstance; - - get: RestMethod; - post: RestMethod; - create: RestMethod; } + export type QueueResource = CreatableMappedResource; /// resources/Recordings.js - export interface RecordingTranscriptionResource { - get: RestMethod; - list: RestMethod; - } - - export interface RecordingInstance { - get: RestMethod; - list: RestMethod; - delete: RestMethod; - + export type RecordingTranscriptionResource = ListableResource; + export interface RecordingInstance extends ListableResource, DeletableResource { transcriptions: RecordingTranscriptionResource; } - - export interface RecordingResource { - (resourceSid: string): RecordingInstance; - - get: RestMethod; - list: RestMethod; - } + export interface RecordingResource extends MappedResource, ListableResource {} /// resources/UsageRecords.js - export interface UsageRecordInstance { - get: RestMethod; - } - - export interface UsageRecordRange { - get: RestMethod; - list: RestMethod; - } - - export interface UsageRecordResource { - (resourceSid: string): UsageRecordInstance; - - get: RestMethod; + export type UsageRecordInstance = Resource; + export type UsageRecordRange = ListableResource; + export interface UsageRecordResource extends MappedResource { daily: UsageRecordRange; monthly: UsageRecordRange; yearly: UsageRecordRange; @@ -849,293 +647,95 @@ export module twilio { } /// resources/ip_messaging/Credentials.js - export interface CredentialInstance { - get: RestMethod; - post: RestMethod; - delete: RestMethod; - update: RestMethod; - } - - export interface CredentialResource { - (resourceSid: string): CredentialInstance; - - get: RestMethod; - post: RestMethod; - create: RestMethod; - list: RestMethod; - } + export type CredentialInstance = InstanceResource; + export type CredentialResource = ListMappedResource; /// resources/ip_messaging/Services.js - export interface ServiceUserInstance { - get: RestMethod; - post: RestMethod; - delete: RestMethod; - update: RestMethod; - } + export type ServiceUserInstance = InstanceResource; + export type ServiceUserResource = ListMappedResource; + export type ServiceRoleInstance = Resource; + export interface ServiceRoleResource extends MappedResource, ListableResource {} - export interface ServiceUserResource { - (resourceSid: string): ServiceUserInstance; + export type ServiceChannelMessageInstance = InstanceResource; + export type ServiceChannelMessageResource = ListMappedResource; - get: RestMethod; - post: RestMethod; - create: RestMethod; - list: RestMethod; - } - - export interface ServiceRoleInstance { - get: RestMethod; - } - - export interface ServiceRoleResource { - (resourceSid: string): ServiceRoleInstance; - - get: RestMethod; - list: RestMethod; - } - - export interface ServiceChannelMessageInstance { - get: RestMethod; - post: RestMethod; - delete: RestMethod; - update: RestMethod; - } - - export interface ServiceChannelMessageResource { - (resourceSid: string): ServiceChannelMessageInstance; - - get: RestMethod; - post: RestMethod; - create: RestMethod; - list: RestMethod; - } - - export interface ServiceChannelMemberInstance { - get: RestMethod; - post: RestMethod; - delete: RestMethod; - update: RestMethod; - } - - export interface ServiceChannelMemberResource { - (resourceSid: string): ServiceChannelMemberInstance; - - get: RestMethod; - post: RestMethod; - create: RestMethod; - list: RestMethod; - } - - export interface ServiceChannelInstance { - get: RestMethod; - post: RestMethod; - delete: RestMethod; - update: RestMethod; + export type ServiceChannelMemberInstance = InstanceResource; + export type ServiceChannelMemberResource = ListMappedResource; + export interface ServiceChannelInstance extends InstanceResource { messages: ServiceChannelMessageResource; members: ServiceChannelMemberResource; } + export type ServiceChannelResource = ListMappedResource; - export interface ServiceChannelResource { - (resourceSid: string): ServiceChannelInstance; - - get: RestMethod; - post: RestMethod; - create: RestMethod; - list: RestMethod; - } - - export interface ServiceInstance { - get: RestMethod; - post: RestMethod; - delete: RestMethod; - update: RestMethod; - + export interface ServiceInstance extends InstanceResource { users: ServiceUserResource; roles: ServiceRoleResource; channels: ServiceChannelResource; } - - export interface ServiceResource { - (resourceSid: string): ServiceInstance; - - get: RestMethod; - post: RestMethod; - create: RestMethod; - list: RestMethod; - } + export type ServiceResource = ListMappedResource; /// resources/lookups/PhoneNumbers.js - export interface PhoneNumberInstance { - get: RestMethod; - } - - export interface PhoneNumberResource { - (resourceSid: string): PhoneNumberInstance; - } + export type PhoneNumberInstance = Resource; + export type PhoneNumberResource = BaseMappedResource; /// resources/monitor/Alerts.js - export interface AlertInstance { - get: RestMethod; - } - - export interface AlertResource { - (resourceSid: string): AlertInstance; - - get: RestMethod; - list: RestMethod; - } + export type AlertInstance = Resource; + export interface AlertResource extends MappedResource, ListableResource {} /// resources/monitor/Events.js - export interface EventInstance { - get: RestMethod; - } - - export interface EventResource { - (resourceSid: string): EventInstance; - - get: RestMethod; - list: RestMethod; - } + export type EventInstance = Resource; + export interface EventResource extends MappedResource, ListableResource {} /// resources/pricing/Messaging.js - export interface CountryInstance { - get: RestMethod; - } + export type CountryInstance = Resource; + export interface CountryResource extends MappedResource, ListableResource {} - export interface CountryResource { - (resourceSid: string): CountryInstance; - - get: RestMethod; - list: RestMethod; - } - - export interface MessagingResource { + export interface PricingMessagingResource { countries: CountryResource; } /// resources/pricing/PhoneNumbers.js - export interface PhoneNumberResource { + export interface PricingPhoneNumberResource { countries: CountryResource; } /// resources/pricing/Voice.js - export interface NumberInstance { - get: RestMethod; - } + export type NumberInstance = Resource; + export interface NumberResource extends MappedResource, ListableResource {} - export interface NumberResource { - (resourceSid: string): NumberInstance; - - get: RestMethod; - list: RestMethod; - } - - export interface VoiceResource { + export interface PricingVoiceResource { countries: CountryResource; numbers: NumberResource; } /// resources/sip/CredentialLists.js - export interface CredentialListInstance { + export interface CredentialListInstance extends InstanceResource { credentials: CredentialResource; - - get: RestMethod; - post: RestMethod; - delete: RestMethod; - update: RestMethod; - } - - export interface CredentialListResource { - (resourceSid: string): CredentialListInstance; - - get: RestMethod; - post: RestMethod; - create: RestMethod; - list: RestMethod; } + export type CredentialListResource = ListMappedResource; /// resources/sip/Domains.js - export interface IPAccessControlListMappingInstance { - get: RestMethod; - delete: RestMethod; - } + export type IPAccessControlListMappingInstance = DeletableResource; + export type IPAccessControlListMappingResource = ListMappedResource; - export interface IPAccessControlListMappingResource { - (resourceSid: string): IPAccessControlListMappingInstance; + export type CredentialListMappingInstance = DeletableResource; + export type CredentialListMappingResource = ListMappedResource; - get: RestMethod; - post: RestMethod; - create: RestMethod; - list: RestMethod; - } - - export interface CredentialListMappingInstance { - get: RestMethod; - delete: RestMethod; - } - - export interface CredentialListMappingResource { - (resourceSid: string): CredentialListMappingInstance; - - get: RestMethod; - post: RestMethod; - create: RestMethod; - list: RestMethod; - } - - export interface DomainInstance { + export interface DomainInstance extends InstanceResource { ipAccessControlListMappings: IPAccessControlListMappingResource; credentialListMappings: CredentialListMappingResource; - - get: RestMethod; - post: RestMethod; - delete: RestMethod; - update: RestMethod; - } - - export interface DomainResource { - (resourceSid: string): DomainInstance; - - get: RestMethod; - post: RestMethod; - create: RestMethod; - list: RestMethod; } + export type DomainResource = ListMappedResource; /// resources/sip/IpAccessControlLists.js - export interface IPAddressInstance { - get: RestMethod; - post: RestMethod; - delete: RestMethod; - update: RestMethod; - } + export type IPAddressInstance = InstanceResource; + export type IPAddressResource = ListMappedResource; - export interface IPAddressResource { - (resourceSid: string): IPAddressInstance; - - get: RestMethod; - post: RestMethod; - list: RestMethod; - create: RestMethod; - } - - export interface IPAccessControlListInstance { + export interface IPAccessControlListInstance extends InstanceResource { ipAddresses: IPAddressResource; - - get: RestMethod; - post: RestMethod; - delete: RestMethod; - update: RestMethod; - } - - export interface IPAccessControlListResource { - (resourceSid: string): IPAccessControlListInstance; - - get: RestMethod; - post: RestMethod; - create: RestMethod; - list: RestMethod; } + export type IPAccessControlListResource = ListMappedResource; /// resources/task_router/WorkflowBuilder.js export interface WorkflowRuleTargetOptions { @@ -1202,148 +802,53 @@ export module twilio { } /// resources/task_router/Workspaces.js - export interface WorkspaceActivityInstance { - get: RestMethod; - post: RestMethod; - delete: RestMethod; + export type WorkspaceActivityInstance = InstanceResource; + export type WorkspaceActivityResource = ListMappedResource; + + export type WorkspaceEventInstance = Resource; + export interface WorkspaceEventResource extends MappedResource, ListableResource {} + + export interface WorkspaceTaskReservationInstance extends PostableResource { update: RestMethod; } + export interface WorkspaceTaskReservationResource extends MappedResource, ListableResource {} - export interface WorkspaceActivityResource { - (resourceSid: string): WorkspaceActivityInstance; - - get: RestMethod; - post: RestMethod; - list: RestMethod; - create: RestMethod; - } - - export interface WorkspaceEventInstance { - get: RestMethod; - } - - export interface WorkspaceEventResource { - (resourceSid: string): WorkspaceEventInstance; - - get: RestMethod; - list: RestMethod; - } - - export interface WorkspaceTaskReservationInstance { - get: RestMethod; - post: RestMethod; - update: RestMethod; - } - - export interface WorkspaceTaskReservationResource { - (resourceSid: string): WorkspaceTaskReservationInstance; - - get: RestMethod; - list: RestMethod; - } - - export interface WorkspaceTaskInstance { + export interface WorkspaceTaskInstance extends InstanceResource { reservations: WorkspaceTaskReservationResource; - - get: RestMethod; - post: RestMethod; - delete: RestMethod; - update: RestMethod; } + export type WorkspaceTaskResource = ListMappedResource; - export interface WorkspaceTaskResource { - (resourceSid: string): WorkspaceTaskInstance; + export type WorkspaceInstanceStatisticResource = Resource; + export type WorkspaceStatisticResource = ListableResource; - get: RestMethod; - post: RestMethod; - list: RestMethod; - create: RestMethod; - } - - export interface WorkspaceInstanceStatisticResource { - get: RestMethod; - } - - export interface WorkspaceStatisticResource { - get: RestMethod; - list: RestMethod; - } - - export interface WorkspaceTaskQueueInstance { + export interface WorkspaceTaskQueueInstance extends InstanceResource { statistics: WorkspaceInstanceStatisticResource; - - get: RestMethod; - post: RestMethod; - delete: RestMethod; - update: RestMethod; } - - export interface WorkspaceTaskQueueResource { - (resourceSid: string): WorkspaceTaskQueueInstance; - + export interface WorkspaceTaskQueueResource extends ListMappedResource { statistics: WorkspaceStatisticResource; - - get: RestMethod; - post: RestMethod; - list: RestMethod; - create: RestMethod; } - export interface WorkspaceWorkerReservationInstance { - get: RestMethod; - post: RestMethod; + export interface WorkspaceWorkerReservationInstance extends PostableResource { update: RestMethod; } + export interface WorkspaceWorkerReservationResource extends MappedResource, ListableResource {} - export interface WorkspaceWorkerReservationResource { - (resourceSid: string): WorkspaceWorkerReservationInstance; - - get: RestMethod; - list: RestMethod; - } - - export interface WorkspaceWorkerInstance { + export interface WorkspaceWorkerInstance extends InstanceResource { statistics: WorkspaceInstanceStatisticResource; reservations: WorkspaceWorkerReservationResource; - - get: RestMethod; - post: RestMethod; - delete: RestMethod; - update: RestMethod; } - - export interface WorkspaceWorkerResource { - (resourceSid: string): WorkspaceWorkerInstance; - + export interface WorkspaceWorkerResource extends ListMappedResource { statistics: WorkspaceStatisticResource; - - get: RestMethod; - post: RestMethod; - list: RestMethod; - create: RestMethod; } - export interface WorkspaceWorkflowInstance { + export interface WorkspaceWorkflowInstance extends InstanceResource { statistics: WorkspaceInstanceStatisticResource; - - get: RestMethod; - post: RestMethod; - delete: RestMethod; - update: RestMethod; } - - export interface WorkspaceWorkflowResource { - (resourceSid: string): WorkspaceWorkflowInstance; - + export interface WorkspaceWorkflowResource extends ListMappedResource { statistics: WorkspaceStatisticResource; - - get: RestMethod; - post: RestMethod; - list: RestMethod; - create: RestMethod; } - export interface WorkspaceInstance { + export interface WorkspaceInstance extends InstanceResource { activities: WorkspaceActivityResource; events: WorkspaceEventResource; tasks: WorkspaceTaskResource; @@ -1352,57 +857,19 @@ export module twilio { workflows: WorkspaceWorkflowResource; statistics: WorkspaceInstanceStatisticResource; - - get: RestMethod; - post: RestMethod; - delete: RestMethod; - update: RestMethod; - } - - export interface WorkspaceResource { - (resourceSid: string): WorkspaceInstance; - - get: RestMethod; - post: RestMethod; - create: RestMethod; } + export type WorkspaceResource = CreatableMappedResource; /// resources/trunking/Trunks.js - export interface OriginationURLInstance { - get: RestMethod; - post: RestMethod; - delete: RestMethod; - update: RestMethod; - } + export type OriginationURLInstance = InstanceResource; + export type OriginationURLResource = ListMappedResource; - export interface OriginationURLResource { - (resourceSid: string): OriginationURLInstance; - - get: RestMethod; - post: RestMethod; - create: RestMethod; - list: RestMethod; - } - - export interface TrunkInstance { + export interface TrunkInstance extends InstanceResource { ipAccessControlLists: IPAccessControlListResource; credentialLists: CredentialListResource; phoneNumbers: PhoneNumberResource; originationUrls: OriginationURLResource; - - get: RestMethod; - post: RestMethod; - delete: RestMethod; - update: RestMethod; - } - - export interface TrunkResource { - (resourceSid: string): TrunkInstance; - - get: RestMethod; - post: RestMethod; - create: RestMethod; - list: RestMethod; } + export type TrunkResource = ListMappedResource; } \ No newline at end of file From b860065390ce0fd739fcc662db0f9446b6a035b3 Mon Sep 17 00:00:00 2001 From: Nicholas Iannone Date: Thu, 11 Aug 2016 15:09:20 -0500 Subject: [PATCH 37/41] Swapped type definition for interface definition for backwards compatibility. --- twilio/twilio.d.ts | 130 ++++++++++++++++++++++----------------------- 1 file changed, 65 insertions(+), 65 deletions(-) diff --git a/twilio/twilio.d.ts b/twilio/twilio.d.ts index 0b4de0c36d..93630f0da2 100644 --- a/twilio/twilio.d.ts +++ b/twilio/twilio.d.ts @@ -455,31 +455,31 @@ export module twilio { export interface OutgoingCallerIdInstance extends InstanceResource { put: RestMethod; } - export type OutgoingCallerIdResource = CreatableMappedResource; + export interface OutgoingCallerIdResource extends CreatableMappedResource {} - export type SMSMessageInstance = Resource; - export type SMSMessageResource = CreatableMappedResource; + export interface SMSMessageInstance extends Resource {} + export interface SMSMessageResource extends CreatableMappedResource {} export interface SMSShortCodeInstance extends PostableResource { update: RestMethod; } - export type SMSShortCodeResource = MappedResource; + export interface SMSShortCodeResource extends MappedResource {} export interface SMSIntermediary { messages: SMSMessageResource; shortCodes: SMSShortCodeResource; } - export type ApplicationInstance = InstanceResource; - export type ApplicationResource = CreatableMappedResource; + export interface ApplicationInstance extends InstanceResource {} + export interface ApplicationResource extends CreatableMappedResource {} export interface ConnectAppInstance extends PostableResource { update: RestMethod; } - export type ConnectAppResource = MappedResource; + export interface ConnectAppResource extends MappedResource {} - export type AuthorizedConnectAppInstance = Resource; - export type AuthorizedConnectAppResource = MappedResource; + export interface AuthorizedConnectAppInstance extends Resource {} + export interface AuthorizedConnectAppResource extends MappedResource {} export interface TokenInstance {} export interface TokenResource extends BaseMappedResource { @@ -487,14 +487,14 @@ export module twilio { create: RestMethod; } - export type TranscriptionInstance = DeletableResource; - export type TranscriptionResource = MappedResource; + export interface TranscriptionInstance extends DeletableResource {} + export interface TranscriptionResource extends MappedResource {} - export type NotificationInstance = DeletableResource; - export type NotificationResource = MappedResource; + export interface NotificationInstance extends DeletableResource {} + export interface NotificationResource extends MappedResource {} - export type UsageTriggerInstance = InstanceResource; - export type UsageTriggerResource = CreatableMappedResource; + export interface UsageTriggerInstance extends InstanceResource {} + export interface UsageTriggerResource extends CreatableMappedResource {} export interface UsageIntermediary { records: UsageRecordResource; @@ -507,8 +507,8 @@ export module twilio { credentialLists: CredentialListResource; } - export type KeyInstance = InstanceResource; - export type KeyResource = CreatableMappedResource; + export interface KeyInstance extends InstanceResource {} + export interface KeyResource extends CreatableMappedResource {} export interface AccountInstance extends PostableResource { update: RestMethod; @@ -539,13 +539,13 @@ export module twilio { export interface AccountResource extends AccountInstance, ListMappedResource {} /// resources/Addresses.js - export type DependentPhoneNumberResource = ListableResource; + export interface DependentPhoneNumberResource extends ListableResource {} export interface AddressInstance extends PostableResource, DeletableResource { // Mixins dependentPhoneNumbers: DependentPhoneNumberResource; } - export type AddressResource = ListMappedResource; + export interface AddressResource extends ListMappedResource {} /// resources/AvailablePhoneNumbers.js export interface AvailablePhoneNumberResourceGroup extends ListableResource { @@ -556,11 +556,11 @@ export module twilio { tollFree: AvailablePhoneNumberResourceGroup; mobile: AvailablePhoneNumberResourceGroup; } - export type AvailablePhoneNumberResource = BaseMappedResource; + export interface AvailablePhoneNumberResource extends BaseMappedResource {} /// resources/Calls.js - export type CallRecordingResource = ListableResource; - export type CallNotificationResource = ListableResource; + export interface CallRecordingResource extends ListableResource {} + export interface CallNotificationResource extends ListableResource {} export interface CallFeedbackResource extends PostableResource, DeletableResource { create: RestMethod; } @@ -571,7 +571,7 @@ export module twilio { feedback: CallFeedbackResource; } - export type CallFeedbackSummaryInstance = DeletableResource; + export interface CallFeedbackSummaryInstance extends DeletableResource {} export interface CallFeedbackSummaryResource extends BaseMappedResource { post: RestMethod; create: RestMethod; @@ -604,12 +604,12 @@ export module twilio { } /// resources/Messages.js - export type MessageMediaInstance = DeletableResource; + export interface MessageMediaInstance extends DeletableResource {} export interface MessageMediaResource extends MappedResource, ListableResource {} export interface MessageInstance extends PostableResource, DeletableResource { media: MessageMediaResource; } - export type MessageResource = ListMappedResource; + export interface MessageResource extends ListMappedResource {} /// resources/Queues.js export interface QueueMemberInstance extends PostableResource { @@ -622,18 +622,18 @@ export module twilio { export interface QueueInstance extends InstanceResource { members: QueueMemberResource; } - export type QueueResource = CreatableMappedResource; + export interface QueueResource extends CreatableMappedResource {} /// resources/Recordings.js - export type RecordingTranscriptionResource = ListableResource; + export interface RecordingTranscriptionResource extends ListableResource {} export interface RecordingInstance extends ListableResource, DeletableResource { transcriptions: RecordingTranscriptionResource; } export interface RecordingResource extends MappedResource, ListableResource {} /// resources/UsageRecords.js - export type UsageRecordInstance = Resource; - export type UsageRecordRange = ListableResource; + export interface UsageRecordInstance extends Resource {} + export interface UsageRecordRange extends ListableResource {} export interface UsageRecordResource extends MappedResource { daily: UsageRecordRange; @@ -647,48 +647,48 @@ export module twilio { } /// resources/ip_messaging/Credentials.js - export type CredentialInstance = InstanceResource; - export type CredentialResource = ListMappedResource; + export interface CredentialInstance extends InstanceResource {} + export interface CredentialResource extends ListMappedResource {} /// resources/ip_messaging/Services.js - export type ServiceUserInstance = InstanceResource; - export type ServiceUserResource = ListMappedResource; - export type ServiceRoleInstance = Resource; + export interface ServiceUserInstance extends InstanceResource {} + export interface ServiceUserResource extends ListMappedResource {} + export interface ServiceRoleInstance extends Resource {} export interface ServiceRoleResource extends MappedResource, ListableResource {} - export type ServiceChannelMessageInstance = InstanceResource; - export type ServiceChannelMessageResource = ListMappedResource; + export interface ServiceChannelMessageInstance extends InstanceResource {} + export interface ServiceChannelMessageResource extends ListMappedResource {} - export type ServiceChannelMemberInstance = InstanceResource; - export type ServiceChannelMemberResource = ListMappedResource; + export interface ServiceChannelMemberInstance extends InstanceResource {} + export interface ServiceChannelMemberResource extends ListMappedResource {} export interface ServiceChannelInstance extends InstanceResource { messages: ServiceChannelMessageResource; members: ServiceChannelMemberResource; } - export type ServiceChannelResource = ListMappedResource; + export interface ServiceChannelResource extends ListMappedResource {} export interface ServiceInstance extends InstanceResource { users: ServiceUserResource; roles: ServiceRoleResource; channels: ServiceChannelResource; } - export type ServiceResource = ListMappedResource; + export interface ServiceResource extends ListMappedResource {} /// resources/lookups/PhoneNumbers.js - export type PhoneNumberInstance = Resource; - export type PhoneNumberResource = BaseMappedResource; + export interface PhoneNumberInstance extends Resource {} + export interface PhoneNumberResource extends BaseMappedResource {} /// resources/monitor/Alerts.js - export type AlertInstance = Resource; + export interface AlertInstance extends Resource {} export interface AlertResource extends MappedResource, ListableResource {} /// resources/monitor/Events.js - export type EventInstance = Resource; + export interface EventInstance extends Resource {} export interface EventResource extends MappedResource, ListableResource {} /// resources/pricing/Messaging.js - export type CountryInstance = Resource; + export interface CountryInstance extends Resource {} export interface CountryResource extends MappedResource, ListableResource {} export interface PricingMessagingResource { @@ -701,7 +701,7 @@ export module twilio { } /// resources/pricing/Voice.js - export type NumberInstance = Resource; + export interface NumberInstance extends Resource {} export interface NumberResource extends MappedResource, ListableResource {} export interface PricingVoiceResource { @@ -713,29 +713,29 @@ export module twilio { export interface CredentialListInstance extends InstanceResource { credentials: CredentialResource; } - export type CredentialListResource = ListMappedResource; + export interface CredentialListResource extends ListMappedResource {} /// resources/sip/Domains.js - export type IPAccessControlListMappingInstance = DeletableResource; - export type IPAccessControlListMappingResource = ListMappedResource; + export interface IPAccessControlListMappingInstance extends DeletableResource {} + export interface IPAccessControlListMappingResource extends ListMappedResource {} - export type CredentialListMappingInstance = DeletableResource; - export type CredentialListMappingResource = ListMappedResource; + export interface CredentialListMappingInstance extends DeletableResource {} + export interface CredentialListMappingResource extends ListMappedResource {} export interface DomainInstance extends InstanceResource { ipAccessControlListMappings: IPAccessControlListMappingResource; credentialListMappings: CredentialListMappingResource; } - export type DomainResource = ListMappedResource; + export interface DomainResource extends ListMappedResource {} /// resources/sip/IpAccessControlLists.js - export type IPAddressInstance = InstanceResource; - export type IPAddressResource = ListMappedResource; + export interface IPAddressInstance extends InstanceResource {} + export interface IPAddressResource extends ListMappedResource {} export interface IPAccessControlListInstance extends InstanceResource { ipAddresses: IPAddressResource; } - export type IPAccessControlListResource = ListMappedResource; + export interface IPAccessControlListResource extends ListMappedResource {} /// resources/task_router/WorkflowBuilder.js export interface WorkflowRuleTargetOptions { @@ -802,10 +802,10 @@ export module twilio { } /// resources/task_router/Workspaces.js - export type WorkspaceActivityInstance = InstanceResource; - export type WorkspaceActivityResource = ListMappedResource; + export interface WorkspaceActivityInstance extends InstanceResource {} + export interface WorkspaceActivityResource extends ListMappedResource {} - export type WorkspaceEventInstance = Resource; + export interface WorkspaceEventInstance extends Resource {} export interface WorkspaceEventResource extends MappedResource, ListableResource {} export interface WorkspaceTaskReservationInstance extends PostableResource { @@ -816,10 +816,10 @@ export module twilio { export interface WorkspaceTaskInstance extends InstanceResource { reservations: WorkspaceTaskReservationResource; } - export type WorkspaceTaskResource = ListMappedResource; + export interface WorkspaceTaskResource extends ListMappedResource {} - export type WorkspaceInstanceStatisticResource = Resource; - export type WorkspaceStatisticResource = ListableResource; + export interface WorkspaceInstanceStatisticResource extends Resource {} + export interface WorkspaceStatisticResource extends ListableResource {} export interface WorkspaceTaskQueueInstance extends InstanceResource { statistics: WorkspaceInstanceStatisticResource; @@ -858,11 +858,11 @@ export module twilio { statistics: WorkspaceInstanceStatisticResource; } - export type WorkspaceResource = CreatableMappedResource; + export interface WorkspaceResource extends CreatableMappedResource {} /// resources/trunking/Trunks.js - export type OriginationURLInstance = InstanceResource; - export type OriginationURLResource = ListMappedResource; + export interface OriginationURLInstance extends InstanceResource {} + export interface OriginationURLResource extends ListMappedResource {} export interface TrunkInstance extends InstanceResource { ipAccessControlLists: IPAccessControlListResource; @@ -870,6 +870,6 @@ export module twilio { phoneNumbers: PhoneNumberResource; originationUrls: OriginationURLResource; } - export type TrunkResource = ListMappedResource; + export interface TrunkResource extends ListMappedResource {} } \ No newline at end of file From da354071c00aba723e72b1b0ce6b948f54f1ccb1 Mon Sep 17 00:00:00 2001 From: Ahmet Kiyak Date: Thu, 11 Aug 2016 23:30:59 +0200 Subject: [PATCH 38/41] Update stripe.d.ts Pass expiration date as single string https://stripe.com/docs/stripe.js#passing-exp-dates --- stripe/stripe.d.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stripe/stripe.d.ts b/stripe/stripe.d.ts index 659c75bf3e..8a03ee3f33 100644 --- a/stripe/stripe.d.ts +++ b/stripe/stripe.d.ts @@ -17,8 +17,9 @@ interface StripeStatic { interface StripeTokenData { number: string; - exp_month: number; - exp_year: number; + exp_month?: number; + exp_year?: number; + exp?: string; cvc?: string; name?: string; address_line1?: string; From c3049e250452c5d00f6c4e58e3f64fd81f646968 Mon Sep 17 00:00:00 2001 From: microshine Date: Fri, 12 Aug 2016 00:41:00 +0300 Subject: [PATCH 39/41] Fix type error --- pkcs11js/pkcs11js.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkcs11js/pkcs11js.d.ts b/pkcs11js/pkcs11js.d.ts index c340ca2112..dcbdb401cb 100644 --- a/pkcs11js/pkcs11js.d.ts +++ b/pkcs11js/pkcs11js.d.ts @@ -210,7 +210,7 @@ declare module "pkcs11js" { * @param {Handle} slot ID of token's slot * @returns {Handle[]} Gets mech. array */ - C_GetMechanismList(slot: Handle): Handle[]; + C_GetMechanismList(slot: Handle): number[]; /** * Obtains information about a particular mechanism possibly supported by a token * @@ -218,7 +218,7 @@ declare module "pkcs11js" { * @param {Handle} mech Type of mechanism * @returns {MechanismInfo} Receives mechanism info */ - C_GetMechanismInfo(slot: Handle, mech: Handle): MechanismInfo; + C_GetMechanismInfo(slot: Handle, mech: number): MechanismInfo; /* Session management */ From 4f5debab4b1d135bd75d5cd2e4c7b8721d42c5cf Mon Sep 17 00:00:00 2001 From: microshine Date: Fri, 12 Aug 2016 00:43:48 +0300 Subject: [PATCH 40/41] Update types --- graphene-pk11/graphene-pk11.d.ts | 3745 +++++++++++++----------------- 1 file changed, 1636 insertions(+), 2109 deletions(-) diff --git a/graphene-pk11/graphene-pk11.d.ts b/graphene-pk11/graphene-pk11.d.ts index 4453a921f1..2ebec894dd 100644 --- a/graphene-pk11/graphene-pk11.d.ts +++ b/graphene-pk11/graphene-pk11.d.ts @@ -1,1230 +1,276 @@ -// Type definitions for graphene-pk11 v2.0.0 +// Type definitions for graphene-pk11 v2.0.2 // Project: https://github.com/PeculiarVentures/graphene // Definitions by: Stepan Miroshin // Definitions: https://github.com/borisyankov/DefinitelyTyped /// +/// /** * A simple layer for interacting with PKCS #11 / PKCS11 / CryptoKI for Node - * v2.0.0 + * v2.0.2 */ -declare module "graphene-pk11" { - type Callback = (err: Error, rv: number) => void; - type CK_PTR = Buffer; +declare module "types/graphene-pk11" { + import * as graphene from "graphene-pk11"; + import * as pkcs11 from "pkcs11js"; - class Pkcs11 { - lib: any; - /** - * load a library with PKCS11 interface - * @param {string} libFile path to PKCS11 library - */ - constructor(libFile: string); - protected callFunction(funcName: string, args: any[]): number; - /** - * C_Initialize initializes the Cryptoki library. - * @param pInitArgs if this is not NULL_PTR, it gets - * cast to CK_C_INITIALIZE_ARGS_PTR - * and dereferenced - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_Initialize(pInitArgs?: CK_PTR): number; - C_Initialize(pInitArgs: CK_PTR, cllback: Callback): void; - /** - * C_Finalize indicates that an application is done with the Cryptoki library. - * @param pReserved reserved. Should be NULL_PTR - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_Finalize(pReserved?: CK_PTR): number; - C_Finalize(pReserved: CK_PTR, callback: Callback): void; - /** - * C_GetInfo returns general information about Cryptoki. - * @param pInfo location that receives information - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_GetInfo(pInfo: CK_PTR): number; - C_GetInfo(pInfo: CK_PTR, callback: Callback): void; - /** - * C_GetSlotList obtains a list of slots in the system. - * @param {boolean} tokenPresent only slots with tokens? - * @param pSlotList receives array of slot IDs - * @param pulCount receives number of slots - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_GetSlotList(tokenPresent: boolean, pSlotList: CK_PTR, pulCount: CK_PTR): number; - C_GetSlotList(tokenPresent: boolean, pSlotList: CK_PTR, pulCount: CK_PTR, callback: Callback): void; - /** - * C_GetSlotInfo obtains information about a particular slot in - * the system. - * @param {number} slotID the ID of the slot - * @param {Buffer} pInfo receives the slot information - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_GetSlotInfo(slotID: number, pInfo: CK_PTR): number; - C_GetSlotInfo(slotID: number, pInfo: CK_PTR, callback: Callback): void; - /** - * C_GetTokenInfo obtains information about a particular token - * in the system. - * @param {number} slotID ID of the token's slot - * @param {Buffer} pInfo receives the token information - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_GetTokenInfo(slotID: number, pInfo: Buffer): number; - C_GetTokenInfo(slotID: number, pInfo: Buffer, callback: Callback): void; - /** - * C_GetMechanismList obtains a list of mechanism types - * supported by a token. - * @param {number} slotID ID of the token's slot - * @param {number} pMechanismList gets mech. array - * @param {number} pulCount gets # of mechs - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_GetMechanismList(slotID: number, pMechanismList: Buffer, pulCount: Buffer): number; - C_GetMechanismList(slotID: number, pMechanismList: Buffer, pulCount: Buffer, callback: Callback): void; - /** C_GetMechanismInfo obtains information about a particular - * mechanism possibly supported by a token. - * @param {number} slotID ID of the token's slot - * @param {number} type type of mechanism - * @param {Buffer} pInfo receives mechanism info - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_GetMechanismInfo(slotID: number, type: number, pInfo: Buffer): number; - C_GetMechanismInfo(slotID: number, type: number, pInfo: Buffer, callback: Callback): void; - /** - * C_InitToken initializes a token. - * @param {number} slotID ID of the token's slot - * @param {Buffer} pPin the SO's initial PIN - * @param {number} ulPinLen length in bytes of the PIN - * @param {number} pLabel 32-byte token label (blank padded) - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_InitToken(slotID: number, pPin: Buffer, ulPinLen: number, pLabel: Buffer): number; - C_InitToken(slotID: number, pPin: Buffer, ulPinLen: number, pLabel: Buffer, callback: Callback): void; - /** - * C_InitPIN initializes the normal user's PIN. - * @param {number} hSession the session's handle - * @param {Buffer} pPin the normal user's PIN - * @param {number} ulPinLen length in bytes of the PIN - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_InitPIN(hSession: number, pPin: Buffer, ulPinLen: number): number; - C_InitPIN(hSession: number, pPin: Buffer, ulPinLen: number, callback: Callback): void; - /** - * C_SetPIN modifies the PIN of the user who is logged in. - * @param {number} hSession the session's handle - * @param {Buffer} pOldPin the old PIN - * @param {number} ulOldLen length of the old PIN - * @param {Buffer} pNewPin the new PIN - * @param {number} ulNewLen length of the new PIN - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_SetPIN(hSession: any, pOldPin: Buffer, ulOldLen: number, pNewPin: Buffer, ulNewLen: number): number; - C_SetPIN(hSession: any, pOldPin: Buffer, ulOldLen: number, pNewPin: Buffer, ulNewLen: number, callback: Callback): void; - /** - * C_OpenSession opens a session between an application and a - * token. - * @param {number} slotID ID of the token's slot - * @param {number} flags from CK_SESSION_INFO - * @param {Buffer} pApplication passed to callback - * @param {Buffer} Notify callback function - * @param {Buffer} phSession gets session handle - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_OpenSession(slotID: number, flags: number, pApplication?: Buffer, notify?: Buffer, phSession?: Buffer): number; - C_OpenSession(slotID: number, flags: number, pApplication: Buffer, notify: Buffer, phSession: Buffer, callback: Callback): void; - /** - * C_CloseSession closes a session between an application and a token. - * @param {number} hSession the session's handle - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_CloseSession(hSession: number): number; - C_CloseSession(hSession: number, callback: Callback): void; - /** - * C_CloseAllSessions closes all sessions with a token. - * @param {number} slotID ID of the token's slot - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_CloseAllSessions(slotID: number): number; - C_CloseAllSessions(slotID: number, callback: Callback): void; - /** - * C_GetSessionInfo obtains information about the session. - * @param {number} hSession the session's handle - * @param {Buffer} pInfo receives session info - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_GetSessionInfo(hSession: number, pInfo: Buffer): number; - C_GetSessionInfo(hSession: number, pInfo: Buffer, callback: Callback): void; - /** - * C_GetOperationState obtains the state of the cryptographic operation in a session. - * @param {number} hSession the session's handle - * @param {Buffer} pOperationState gets state - * @param {Buffer} pulOperationStateLen gets state length - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_GetOperationState(hSession: number, pOperationState: Buffer, pulOperationStateLen: Buffer): number; - C_GetOperationState(hSession: number, pOperationState: Buffer, pulOperationStateLen: Buffer, callback: Callback): void; - /** - * C_SetOperationState restores the state of the cryptographic operation in a session. - * @param {number} hSession the session's handle - * @param {Buffer} pOperationState holds state - * @param {number} ulOperationStateLen holds holds state length - * @param {number} hEncryptionKey en/decryption key - * @param {number} hAuthenticationKey sign/verify key - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_SetOperationState(hSession: number, pOperationState: Buffer, ulOperationStateLen: number, hEncryptionKey: number, hAuthenticationKey: number): number; - C_SetOperationState(hSession: number, pOperationState: Buffer, ulOperationStateLen: number, hEncryptionKey: number, hAuthenticationKey: number, callback: Callback): void; - /** - * C_Login logs a user into a token. - * @param {number} hSession the session's handle - * @param {number} userType the user type - * @param {Buffer} pPin the user's PIN - * @param {number} ulPinLen the length of the PIN - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_Login(hSession: number, userType: number, pPin: Buffer, ulPinLen: number): number; - C_Login(hSession: number, userType: number, pPin: Buffer, ulPinLen: number, callback: Callback): void; - /** - * C_Logout logs a user out from a token. - * @param {number} hSession the session's handle - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_Logout(hSession: number): number; - C_Logout(hSession: number, callback: Callback): void; - /** - * C_CreateObject creates a new object. - * @param {number} hSession the session's handle - * @param {Buffer} pTemplate the object's template - * @param {number} ulCount attributes in template - * @param {Buffer} phObject gets new object's handle - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_CreateObject(hSession: number, pTemplate: Buffer, ulCount: number, phObject: Buffer): number; - C_CreateObject(hSession: number, pTemplate: Buffer, ulCount: number, phObject: Buffer, callback: Callback): void; - /** - * C_CopyObject copies an object, creating a new object for the copy. - * @param {number} hSession the session's handle - * @param {number} hObject the object's handle - * @param {Buffer} pTemplate template for new object - * @param {number} ulCount attributes in template - * @param {Buffer} phNewObject receives handle of copy - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_CopyObject(hSession: number, hObject: number, pTemplate: Buffer, ulCount: number, phNewObject: Buffer): number; - C_CopyObject(hSession: number, hObject: number, pTemplate: Buffer, ulCount: number, phNewObject: Buffer, callback: Callback): void; - /** - * C_DestroyObject destroys an object. - * @param {number} hSession the session's handle - * @param {number} hObject the object's handle - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_DestroyObject(hSession: number, hObject: number): number; - C_DestroyObject(hSession: number, hObject: number, callback: Callback): void; - /** - * C_GetObjectSize gets the size of an object in bytes. - * @param {number} hSession the session's handle - * @param {number} hObject the object's handle - * @param {Buffer} pulSize receives size of object - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_GetObjectSize(hSession: number, hObject: number, pulSize: Buffer): number; - C_GetObjectSize(hSession: number, hObject: number, pulSize: Buffer, callback: Callback): void; - /** - * C_GetAttributeValue obtains the value of one or more object attributes. - * @param {number} hSession the session's handle - * @param {number} hObject the object's handle - * @param {Buffer} pTemplate specifies attrs; gets vals - * @param {number} ulCount attributes in template - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_GetAttributeValue(hSession: number, hObject: number, pTemplate: Buffer, ulCount: number): number; - C_GetAttributeValue(hSession: number, hObject: number, pTemplate: Buffer, ulCount: number, callback: Callback): void; - /** - * C_SetAttributeValue modifies the value of one or more object attributes - * @param {number} hSession the session's handle - * @param {number} hObject the object's handle - * @param {Buffer} pTemplate specifies attrs and values - * @param {number} ulCount attributes in template - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_SetAttributeValue(hSession: number, hObject: number, pTemplate: Buffer, ulCount: number): number; - C_SetAttributeValue(hSession: number, hObject: number, pTemplate: Buffer, ulCount: number, callback: Callback): void; - /** - * C_FindObjectsInit initializes a search for token and session - * objects that match a template. - * @param {number} hSession the session's handle - * @param {Buffer} pTemplate attribute values to match - * @param {number} ulCount attrs in search template - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_FindObjectsInit(hSession: number, pTemplate: Buffer, ulCount: number): number; - C_FindObjectsInit(hSession: number, pTemplate: Buffer, ulCount: number, callback: Callback): void; - /** - * C_FindObjects continues a search for token and session - * objects that match a template, obtaining additional object - * handles. - * @param {number} hSession the session's handle - * @param {Buffer} phObject gets obj. handles - * @param {number} ulMaxObjectCount max handles to get - * @param {Buffer} pulObjectCount actual # returned - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_FindObjects(hSession: number, phObject: Buffer, ulMaxObjectCount: number, pulObjectCount: Buffer): number; - C_FindObjects(hSession: number, phObject: Buffer, ulMaxObjectCount: number, pulObjectCount: Buffer, callback: Callback): void; - /** - * C_FindObjectsFinal finishes a search for token and session objects. - * @param {number} hSession the session's handle - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_FindObjectsFinal(hSession: number): number; - C_FindObjectsFinal(hSession: number, callback: Callback): void; - /** - * C_EncryptInit initializes an encryption operation. - * @param {number} hSession the session's handle - * @param {Buffer} pMechanism the encryption mechanism - * @param {number} hKey handle of encryption key - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_EncryptInit(hSession: number, pMechanism: Buffer, hKey: number): number; - C_EncryptInit(hSession: number, pMechanism: Buffer, hKey: number, callback: Callback): void; - /** - * C_Encrypt encrypts single-part data. - * @param {number} hSession the session's handle - * @param {Buffer} pData the plaintext data - * @param {number} ulDataLen bytes of plaintext - * @param {Buffer} pEncryptedData gets ciphertext - * @param {Buffer} pulEncryptedDataLen gets c-text size - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_Encrypt(hSession: number, pData: Buffer, ulDataLen: number, pEncryptedData: Buffer, pulEncryptedDataLen: Buffer): number; - C_Encrypt(hSession: number, pData: Buffer, ulDataLen: number, pEncryptedData: Buffer, pulEncryptedDataLen: Buffer, callback: Callback): void; - /** - * C_EncryptUpdate continues a multiple-part encryption operation. - * @param {number} hSession the session's handle - * @param {Buffer} pPart the plaintext data - * @param {number} ulPartLen plaintext data len - * @param {Buffer} pEncryptedPart gets ciphertext - * @param {Buffer} pulEncryptedPartLen gets c-text size - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_EncryptUpdate(hSession: number, pPart: Buffer, ulPartLen: number, pEncryptedPart: Buffer, pulEncryptedPartLen: Buffer): number; - C_EncryptUpdate(hSession: number, pPart: Buffer, ulPartLen: number, pEncryptedPart: Buffer, pulEncryptedPartLen: Buffer, callback: Callback): void; - /** - * C_EncryptFinal finishes a multiple-part encryption operation. - * @param {number} hSession the session's handle - * @param {Buffer} pLastEncryptedPart last c-text - * @param {Buffer} pulLastEncryptedPartLen gets last size - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_EncryptFinal(hSession: number, pLastEncryptedPart: Buffer, pulLastEncryptedPartLen: Buffer): number; - C_EncryptFinal(hSession: number, pLastEncryptedPart: Buffer, pulLastEncryptedPartLen: Buffer, callback: Callback): void; - /** - * C_DecryptInit initializes a decryption operation. - * @param {number} hSession the session's handle - * @param {Buffer} pMechanism the decryption mechanism - * @param {number} hKey handle of decryption key - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_DecryptInit(hSession: number, pMechanism: Buffer, hKey: number): any; - C_DecryptInit(hSession: number, pMechanism: Buffer, hKey: number, callback: Callback): void; - /** - * C_Decrypt decrypts encrypted data in a single part. - * @param {number} hSession the session's handle - * @param {Buffer} pEncryptedData ciphertext - * @param {number} ulEncryptedDataLen ciphertext length - * @param {Buffer} pData gets plaintext - * @param {number} pulDataLen gets p-text size - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_Decrypt(hSession: number, pEncryptedData: Buffer, ulEncryptedDataLen: number, pData: Buffer, pulDataLen: Buffer): number; - C_Decrypt(hSession: number, pEncryptedData: Buffer, ulEncryptedDataLen: number, pData: Buffer, pulDataLen: Buffer, callback: Callback): void; - /** - * C_DecryptUpdate continues a multiple-part decryption operation. - * @param {number} hSession the session's handle - * @param {Buffer} pEncryptedPart encrypted data - * @param {number} ulEncryptedPartLen input length - * @param {Buffer} pPart gets plaintext - * @param {Buffer} pulPartLen p-text size - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_DecryptUpdate(hSession: number, pEncryptedPart: Buffer, ulEncryptedPartLen: number, pPart: Buffer, pulPartLen: Buffer): number; - C_DecryptUpdate(hSession: number, pEncryptedPart: Buffer, ulEncryptedPartLen: number, pPart: Buffer, pulPartLen: Buffer, callback: Callback): void; - /** - * C_DecryptFinal finishes a multiple-part decryption operation. - * @param {number} hSession the session's handle - * @param {Buffer} pLastPart gets plaintext - * @param {Buffer} pulLastPartLen p-text size - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_DecryptFinal(hSession: number, pLastPart: Buffer, pulLastPartLen: Buffer): number; - C_DecryptFinal(hSession: number, pLastPart: Buffer, pulLastPartLen: Buffer, callback: Callback): void; - /** - * C_DigestInit initializes a message-digesting operation. - * @param {number} hSession the session's handle - * @param {Buffer} pMechanism the digesting mechanism - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_DigestInit(hSession: number, pMechanism: Buffer): number; - C_DigestInit(hSession: number, pMechanism: Buffer, callback: Callback): void; - /** - * C_Digest digests data in a single part. - * @param {number} hSession the session's handle - * @param {Buffer} pData data to be digested - * @param {number} ulDataLen bytes of data to digest - * @param {Buffer} pDigest gets the message digest - * @param {Buffer} pulDigestLen gets digest length - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_Digest(hSession: number, pData: Buffer, ulDataLen: number, pDigest: Buffer, pulDigestLen: Buffer): number; - C_Digest(hSession: number, pData: Buffer, ulDataLen: number, pDigest: Buffer, pulDigestLen: Buffer, callback: Callback): void; - /** - * C_DigestUpdate continues a multiple-part message-digesting operation. - * @param {number} hSession the session's handle - * @param {Buffer} pPart data to be digested - * @param {number} ulPartLen bytes of data to be digested - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_DigestUpdate(hSession: number, pPart: Buffer, ulPartLen: number): number; - C_DigestUpdate(hSession: number, pPart: Buffer, ulPartLen: number, callback: Callback): void; - /** - * C_DigestKey continues a multi-part message-digesting operation, - * by digesting the value of a secret key as part of - * the data already digested. - * @param {number} hSession the session's handle - * @param {number} hKey secret key to digest - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_DigestKey(hSession: number, hKey: number): number; - C_DigestKey(hSession: number, hKey: number, callback: Callback): void; - /** - * C_DigestFinal finishes a multiple-part message-digesting - * operation. - * @param {number} hSession the session's handle - * @param {Buffer} pDigest gets the message digest - * @param {Buffer} pulDigestLen gets byte count of digest - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_DigestFinal(hSession: number, pDigest: Buffer, pulDigestLen: Buffer): number; - C_DigestFinal(hSession: number, pDigest: Buffer, pulDigestLen: Buffer, callback: Callback): void; - /** - * C_SignInit initializes a signature (private key encryption) - * operation, where the signature is (will be) an appendix to - * the data, and plaintext cannot be recovered from the signature. - * @param {number} hSession the session's handle - * @param {Buffer} pMechanism the signature mechanism - * @param {number} hKey handle of signature key - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_SignInit(hSession: number, pMechanism: Buffer, hKey: number): number; - C_SignInit(hSession: number, pMechanism: Buffer, hKey: number, callback: Callback): void; - /** - * C_Sign signs (encrypts with private key) data in a single - * part, where the signature is (will be) an appendix to the - * data, and plaintext cannot be recovered from the signature. - * @param {number} hSession the session's handle - * @param {Buffer} pData the data to sign - * @param {number} ulDataLen count of bytes to sign - * @param {Buffer} pSignature gets the signature - * @param {Buffer} pulSignatureLen gets signature length - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_Sign(hSession: number, pData: Buffer, ulDataLen: number, pSignature: Buffer, pulSignatureLen: Buffer): number; - C_Sign(hSession: number, pData: Buffer, ulDataLen: number, pSignature: Buffer, pulSignatureLen: Buffer, callback: Callback): void; - /** - * C_SignUpdate continues a multiple-part signature operation, - * where the signature is (will be) an appendix to the data, - * and plaintext cannot be recovered from the signature. - * @param {number} hSession the session's handle - * @param {Buffer} pPart the data to sign - * @param {number} ulPartLen count of bytes to sign - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_SignUpdate(hSession: number, pPart: Buffer, ulPartLen: Buffer): number; - C_SignUpdate(hSession: number, pPart: Buffer, ulPartLen: Buffer, callback: Callback): void; - /** - * C_SignFinal finishes a multiple-part signature operation, - * returning the signature. - * @param {number} hSession the session's handle - * @param {Buffer} pSignature gets the signature - * @param {Buffer} pulSignatureLen gets signature length - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_SignFinal(hSession: number, pSignature: Buffer, pulSignatureLen: Buffer): number; - C_SignFinal(hSession: number, pSignature: Buffer, pulSignatureLen: Buffer, callback: Callback): void; - /** - * C_SignRecoverInit initializes a signature operation, where - * the data can be recovered from the signature. - * @param {number} hSession the session's handle - * @param {Buffer} pMechanism the signature mechanism - * @param {number} hKey handle of the signature key - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_SignRecoverInit(hSession: number, pMechanism: Buffer, hKey: number): number; - C_SignRecoverInit(hSession: number, pMechanism: Buffer, hKey: number, callback: Callback): void; - /** - * C_SignRecover signs data in a single operation, where the - * data can be recovered from the signature. - * @param {number} hSession the session's handle - * @param {Buffer} pData the data to sign - * @param {number} ulDataLen count of bytes to sign - * @param {Buffer} pSignature gets the signature - * @param {Buffer} pulSignatureLen gets signature length - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_SignRecover(hSession: number, pData: Buffer, ulDataLen: number, pSignature: Buffer, pulSignatureLen: Buffer): number; - C_SignRecover(hSession: number, pData: Buffer, ulDataLen: number, pSignature: Buffer, pulSignatureLen: Buffer, callback: Callback): void; - /** - * C_VerifyInit initializes a verification operation, where the - * signature is an appendix to the data, and plaintext cannot - * cannot be recovered from the signature (e.g. DSA). - * @param {number} hSession the session's handle - * @param {Buffer} pMechanism the verification mechanism - * @param {number} hKey verification key - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_VerifyInit(hSession: number, pMechanism: Buffer, hKey: number): number; - C_VerifyInit(hSession: number, pMechanism: Buffer, hKey: number, callback: Callback): void; - /** - * C_Verify verifies a signature in a single-part operation, - * where the signature is an appendix to the data, and plaintext - * cannot be recovered from the signature. - * @param {number} hSession the session's handle - * @param {Buffer} pData signed data - * @param {number} ulDataLen length of signed data - * @param {Buffer} pSignature signature - * @param {number} ulSignatureLen signature length - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_Verify(hSession: number, pData: Buffer, ulDataLen: number, pSignature: Buffer, ulSignatureLen: Buffer): number; - C_Verify(hSession: number, pData: Buffer, ulDataLen: number, pSignature: Buffer, ulSignatureLen: Buffer, callback: Callback): void; - /** - * C_VerifyUpdate continues a multiple-part verification - * operation, where the signature is an appendix to the data, - * and plaintext cannot be recovered from the signature. - * @param {number} hSession the session's handle - * @param {Buffer} pPart signed data - * @param {number} ulPartLen length of signed data - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_VerifyUpdate(hSession: number, pPart: Buffer, ulPartLen: number): number; - C_VerifyUpdate(hSession: number, pPart: Buffer, ulPartLen: number, callback: Callback): void; - /** - * C_VerifyFinal finishes a multiple-part verification - * operation, checking the signature. - * @param {number} hSession the session's handle - * @param {Buffer} pSignature signature to verify - * @param {number} ulSignatureLen signature length - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_VerifyFinal(hSession: number, pSignature: Buffer, ulSignatureLen: number): number; - C_VerifyFinal(hSession: number, pSignature: Buffer, ulSignatureLen: number, callback: Callback): void; - /** - * C_VerifyRecoverInit initializes a signature verification - * operation, where the data is recovered from the signature. - * @param {number} hSession the session's handle - * @param {Buffer} pMechanism the verification mechanism - * @param {number} hKey verification key - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_VerifyRecoverInit(hSession: number, pMechanism: Buffer, hKey: number): number; - C_VerifyRecoverInit(hSession: number, pMechanism: Buffer, hKey: number, callback: Callback): void; - /** - * C_VerifyRecover verifies a signature in a single-part - * operation, where the data is recovered from the signature. - * @param {number} hSession the session's handle - * @param {Buffer} pSignature signature to verify - * @param {number} ulSignatureLen signature length - * @param {Buffer} pData gets signed data - * @param {Buffer} pulDataLen gets signed data len - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_VerifyRecover(hSession: number, pSignature: Buffer, ulSignatureLen: number, pData: Buffer, pulDataLen: Buffer): number; - C_VerifyRecover(hSession: number, pSignature: Buffer, ulSignatureLen: number, pData: Buffer, pulDataLen: Buffer, callback: Callback): void; - /** - * C_DigestEncryptUpdate continues a multiple-part digesting - * and encryption operation. - * @param {number} hSession the session's handle - * @param {Buffer} pPart the plaintext data - * @param {number} ulPartLen plaintext length - * @param {Buffer} pEncryptedPart gets ciphertext - * @param {Buffer} pulEncryptedPartLen gets c-text length - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_DigestEncryptUpdate(hSession: number, pPart: Buffer, ulPartLen: number, pEncryptedPart: Buffer, pulEncryptedPartLen: Buffer): number; - C_DigestEncryptUpdate(hSession: number, pPart: Buffer, ulPartLen: number, pEncryptedPart: Buffer, pulEncryptedPartLen: Buffer, callback: Callback): void; - /** - * C_DecryptDigestUpdate continues a multiple-part decryption and - * digesting operation. - * @param {number} hSession the session's handle - * @param {Buffer} pEncryptedPart ciphertext - * @param {number} ulEncryptedPartLen ciphertext length - * @param {Buffer} pPart gets plaintext - * @param {Buffer} pulPartLen gets plaintext len - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_DecryptDigestUpdate(hSession: number, pEncryptedPart: Buffer, ulEncryptedPartLen: number, pPart: Buffer, pulPartLen: Buffer): number; - C_DecryptDigestUpdate(hSession: number, pEncryptedPart: Buffer, ulEncryptedPartLen: number, pPart: Buffer, pulPartLen: Buffer, callback: Callback): void; - /** - * C_SignEncryptUpdate continues a multiple-part signing and - * encryption operation. - * @param {number} hSession the session's handle - * @param {Buffer} pPart the plaintext data - * @param {number} ulPartLen plaintext length - * @param {Buffer} pEncryptedPart gets ciphertext - * @param {Buffer} pulEncryptedPartLen gets c-text length - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_SignEncryptUpdate(hSession: number, pPart: Buffer, ulPartLen: number, pEncryptedPart: Buffer, pulEncryptedPartLen: Buffer): number; - C_SignEncryptUpdate(hSession: number, pPart: Buffer, ulPartLen: number, pEncryptedPart: Buffer, pulEncryptedPartLen: Buffer, callback: Callback): void; - /** - * C_DecryptVerifyUpdate continues a multiple-part decryption and - * verify operation. - * @param {number} hSession the session's handle - * @param {Buffer} pEncryptedPart ciphertext - * @param {number} ulEncryptedPartLen ciphertext length - * @param {Buffer} pPart gets plaintext - * @param {Buffer} pulPartLen gets p-text length - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_DecryptVerifyUpdate(hSession: number, pEncryptedPart: Buffer, ulEncryptedPartLen: number, pPart: Buffer, pulPartLen: Buffer): number; - C_DecryptVerifyUpdate(hSession: number, pEncryptedPart: Buffer, ulEncryptedPartLen: number, pPart: Buffer, pulPartLen: Buffer, callback: Callback): void; - /** - * C_GenerateKey generates a secret key, creating a new key object. - * @param {number} hSession the session's handle - * @param {Buffer} pMechanism key generation mech. - * @param {Buffer} pTemplate template for new key - * @param {number} ulCount # of attrs in template - * @param {Buffer} phKey gets handle of new key - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_GenerateKey(hSession: number, pMechanism: Buffer, pTemplate: Buffer, ulCount: number, phKey: Buffer): number; - C_GenerateKey(hSession: number, pMechanism: Buffer, pTemplate: Buffer, ulCount: number, phKey: Buffer, callback: Callback): any; - /** - * C_GenerateKeyPair generates a public-key/private-key pair, - * creating new key objects. - * @param {number} hSession the session's handle - * @param {Buffer} pMechanism key-gen mech. - * @param {Buffer} pPublicKeyTemplate template for public key - * @param {number} ulPublicKeyAttributeCount public attrs - * @param {Buffer} pPrivateKeyTemplate template for private key - * @param {number} ulPrivateKeyAttributeCount private attrs - * @param {Buffer} phPublicKey gets public key handle - * @param {Buffer} phPrivateKey gets private key handle - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_GenerateKeyPair(hSession: number, pMechanism: Buffer, pPublicKeyTemplate: Buffer, ulPublicKeyAttributeCount: number, pPrivateKeyTemplate: Buffer, ulPrivateKeyAttributeCount: number, phPublicKey: Buffer, phPrivateKey: Buffer): number; - C_GenerateKeyPair(hSession: number, pMechanism: Buffer, pPublicKeyTemplate: Buffer, ulPublicKeyAttributeCount: number, pPrivateKeyTemplate: Buffer, ulPrivateKeyAttributeCount: number, phPublicKey: Buffer, phPrivateKey: Buffer, callback: Callback): void; - /** - * C_WrapKey wraps (i.e., encrypts) a key. - * @param {number} hSession the session's handle - * @param {Buffer} pMechanism the wrapping mechanism - * @param {number} hWrappingKey wrapping key - * @param {number} hKey key to be wrapped - * @param {Buffer} pWrappedKey gets wrapped key - * @param {Buffer} pulWrappedKeyLen gets wrapped key size - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_WrapKey(hSession: number, pMechanism: Buffer, hWrappingKey: number, hKey: number, pWrappedKey: Buffer, pulWrappedKeyLen: Buffer): number; - C_WrapKey(hSession: number, pMechanism: Buffer, hWrappingKey: number, hKey: number, pWrappedKey: Buffer, pulWrappedKeyLen: Buffer, callback: Callback): void; - /** - * C_UnwrapKey unwraps (decrypts) a wrapped key, creating a new - * key object. - * @param {number} hSession the session's handle - * @param {Buffer} pMechanism unwrapping mech. - * @param {Buffer} pWrappedKey the wrapped key - * @param {number} ulWrappedKeyLen wrapped key len - * @param {Buffer} pTemplate new key template - * @param {number} ulAttributeCount template length - * @param {Buffer} pTemplate new key template - * @param {number} ulAttributeCount template length - * @param {Buffer} phKey gets new handle - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_UnwrapKey(hSession: number, pMechanism: Buffer, hUnwrappingKey: number, pWrappedKey: Buffer, ulWrappedKeyLen: number, pTemplate: Buffer, ulAttributeCount: number, phKey: Buffer): number; - C_UnwrapKey(hSession: number, pMechanism: Buffer, hUnwrappingKey: number, pWrappedKey: Buffer, ulWrappedKeyLen: number, pTemplate: Buffer, ulAttributeCount: number, phKey: Buffer, callback: Callback): void; - /** - * C_DeriveKey derives a key from a base key, creating a new key object. - * @param {number} hSession the session's handle - * @param {Buffer} pMechanism key deriv. mech. - * @param {number} hBaseKey base key - * @param {Buffer} pTemplate new key template - * @param {number} ulAttributeCount template length - * @param {Buffer} phKey gets new handle - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_DeriveKey(hSession: number, pMechanism: Buffer, hBaseKey: number, pTemplate: Buffer, ulAttributeCount: number, phKey: Buffer): number; - C_DeriveKey(hSession: number, pMechanism: Buffer, hBaseKey: number, pTemplate: Buffer, ulAttributeCount: number, phKey: Buffer, callback: Callback): void; - /** - * C_SeedRandom mixes additional seed material into the token's - * random number generator. - * @param {number} hSession the session's handle - * @param {Buffer} pSeed the seed material - * @param {number} ulSeedLen length of seed material - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_SeedRandom(hSession: number, pSeed: Buffer, ulSeedLen: number): number; - C_SeedRandom(hSession: number, pSeed: Buffer, ulSeedLen: number, callback: Callback): void; - /** - * C_GenerateRandom generates random data. - * @param {number} hSession the session's handle - * @param {Buffer} pRandomData receives the random data - * @param {number} ulRandomLen # of bytes to generate - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_GenerateRandom(hSession: number, pRandomData: Buffer, ulRandomLen: number): number; - C_GenerateRandom(hSession: number, pRandomData: Buffer, ulRandomLen: number, callback: Callback): void; - /** - * C_GetFunctionStatus is a legacy function; it obtains an - * updated status of a function running in parallel with an - * application. - * @param {number} hSession the session's handle - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_GetFunctionStatus(hSession: number): number; - C_GetFunctionStatus(hSession: number, callback: Callback): void; - /** - * C_CancelFunction is a legacy function; it cancels a function - * running in parallel. - * @param {number} hSession the session's handle - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_CancelFunction(hSession: number): number; - C_CancelFunction(hSession: number, callback: Callback): void; - /** - * C_WaitForSlotEvent waits for a slot event (token insertion, - * removal, etc.) to occur. - * @param {number} flags blocking/nonblocking flag - * @param {Buffer} pSlot location that receives the slot ID - * @param {Buffer} pRserved reserved. Should be NULL_PTR - * @param {Callback} callback callback function with PKCS11 result value - * @returns void PKCS11 result value - */ - C_WaitForSlotEvent(flags: number, pSlot: Buffer, pRserved: Buffer): number; - C_WaitForSlotEvent(flags: number, pSlot: Buffer, pRserved: Buffer, callback: Callback): number; + // ========== Core ========== + + /** + * Handle + */ + type Handle = Buffer; + /** + * BaseObject + * + * @interface BaseObject + */ + interface BaseObject { + } + /** + * HandleObject + * + * @interface HandleObject + * @extends {BaseObject} + */ + interface HandleObject extends BaseObject { + /** + * handle to pkcs11 object + */ + handle: Handle; } - enum KeyType { - RSA, - DSA, - DH, - ECDSA, - EC, - X9_42_DH, - KEA, - GENERIC_SECRET, - RC2, - RC4, - DES, - DES2, - DES3, - CAST, - CAST3, - CAST5, - CAST128, - RC5, - IDEA, - SKIPJACK, - BATON, - JUNIPER, - CDMF, - AES, - GOSTR3410, - GOSTR3411, - GOST28147, - BLOWFISH, - TWOFISH, - SECURID, - HOTP, - ACTI, - CAMELLIA, - ARIA, - } - enum KeyGenMechanism { - AES, - RSA, - RSA_X9_31, - DSA, - DH_PKCS, - DH_X9_42, - GOSTR3410, - GOST28147, - RC2, - RC4, - DES, - DES2, - SECURID, - ACTI, - CAST, - CAST3, - CAST5, - CAST128, - RC5, - IDEA, - GENERIC_SECRET, - SSL3_PRE_MASTER, - CAMELLIA, - ARIA, - SKIPJACK, - KEA, - BATON, - ECDSA, - EC, - JUNIPER, - TWOFISH, - } + /** + * Collection + * + * @interface Collection + * @extends {BaseObject} + * @template T + */ + interface Collection extends BaseObject { - enum MechanismEnum { - RSA_PKCS_KEY_PAIR_GEN, - RSA_PKCS, - RSA_9796, - RSA_X_509, - MD2_RSA_PKCS, - MD5_RSA_PKCS, - SHA1_RSA_PKCS, - RIPEMD128_RSA_PKCS, - RIPEMD160_RSA_PKCS, - RSA_PKCS_OAEP, - RSA_X9_31_KEY_PAIR_GEN, - RSA_X9_31, - SHA1_RSA_X9_31, - RSA_PKCS_PSS, - SHA1_RSA_PKCS_PSS, - DSA_KEY_PAIR_GEN, - DSA, - DSA_SHA1, - DH_PKCS_KEY_PAIR_GEN, - DH_PKCS_DERIVE, - X9_42_DH_KEY_PAIR_GEN, - X9_42_DH_DERIVE, - X9_42_DH_HYBRID_DERIVE, - X9_42_MQV_DERIVE, - SHA256_RSA_PKCS, - SHA384_RSA_PKCS, - SHA512_RSA_PKCS, - SHA256_RSA_PKCS_PSS, - SHA384_RSA_PKCS_PSS, - SHA512_RSA_PKCS_PSS, - SHA224_RSA_PKCS, - SHA224_RSA_PKCS_PSS, - RC2_KEY_GEN, - RC2_ECB, - RC2_CBC, - RC2_MAC, - RC2_MAC_GENERAL, - RC2_CBC_PAD, - RC4_KEY_GEN, - RC4, - DES_KEY_GEN, - DES_ECB, - DES_CBC, - DES_MAC, - DES_MAC_GENERAL, - DES_CBC_PAD, - DES2_KEY_GEN, - DES3_KEY_GEN, - DES3_ECB, - DES3_CBC, - DES3_MAC, - DES3_MAC_GENERAL, - DES3_CBC_PAD, - CDMF_KEY_GEN, - CDMF_ECB, - CDMF_CBC, - CDMF_MAC, - CDMF_MAC_GENERAL, - CDMF_CBC_PAD, - DES_OFB64, - DES_OFB8, - DES_CFB64, - DES_CFB8, - MD2, - MD2_HMAC, - MD2_HMAC_GENERAL, - MD5, - MD5_HMAC, - MD5_HMAC_GENERAL, - SHA1, - SHA, - SHA_1, - SHA_1_HMAC, - SHA_1_HMAC_GENERAL, - RIPEMD128, - RIPEMD128_HMAC, - RIPEMD128_HMAC_GENERAL, - RIPEMD160, - RIPEMD160_HMAC, - RIPEMD160_HMAC_GENERAL, - SHA256, - SHA256_HMAC, - SHA256_HMAC_GENERAL, - SHA224, - SHA224_HMAC, - SHA224_HMAC_GENERAL, - SHA384, - SHA384_HMAC, - SHA384_HMAC_GENERAL, - SHA512, - SHA512_HMAC, - SHA512_HMAC_GENERAL, - SECURID_KEY_GEN, - SECURID, - HOTP_KEY_GEN, - HOTP, - ACTI, - ACTI_KEY_GEN, - CAST_KEY_GEN, - CAST_ECB, - CAST_CBC, - CAST_MAC, - CAST_MAC_GENERAL, - CAST_CBC_PAD, - CAST3_KEY_GEN, - CAST3_ECB, - CAST3_CBC, - CAST3_MAC, - CAST3_MAC_GENERAL, - CAST3_CBC_PAD, - CAST5_KEY_GEN, - CAST128_KEY_GEN, - CAST5_ECB, - CAST128_ECB, - CAST5_CBC, - CAST128_CBC, - CAST5_MAC, - CAST128_MAC, - CAST5_MAC_GENERAL, - CAST128_MAC_GENERAL, - CAST5_CBC_PAD, - CAST128_CBC_PAD, - RC5_KEY_GEN, - RC5_ECB, - RC5_CBC, - RC5_MAC, - RC5_MAC_GENERAL, - RC5_CBC_PAD, - IDEA_KEY_GEN, - IDEA_ECB, - IDEA_CBC, - IDEA_MAC, - IDEA_MAC_GENERAL, - IDEA_CBC_PAD, - GENERIC_SECRET_KEY_GEN, - CONCATENATE_BASE_AND_KEY, - CONCATENATE_BASE_AND_DATA, - CONCATENATE_DATA_AND_BASE, - XOR_BASE_AND_DATA, - EXTRACT_KEY_FROM_KEY, - SSL3_PRE_MASTER_KEY_GEN, - SSL3_MASTER_KEY_DERIVE, - SSL3_KEY_AND_MAC_DERIVE, - SSL3_MASTER_KEY_DERIVE_DH, - TLS_PRE_MASTER_KEY_GEN, - TLS_MASTER_KEY_DERIVE, - TLS_KEY_AND_MAC_DERIVE, - TLS_MASTER_KEY_DERIVE_DH, - TLS_PRF, - SSL3_MD5_MAC, - SSL3_SHA1_MAC, - MD5_KEY_DERIVATION, - MD2_KEY_DERIVATION, - SHA1_KEY_DERIVATION, - SHA256_KEY_DERIVATION, - SHA384_KEY_DERIVATION, - SHA512_KEY_DERIVATION, - SHA224_KEY_DERIVATION, - PBE_MD2_DES_CBC, - PBE_MD5_DES_CBC, - PBE_MD5_CAST_CBC, - PBE_MD5_CAST3_CBC, - PBE_MD5_CAST5_CBC, - PBE_MD5_CAST128_CBC, - PBE_SHA1_CAST5_CBC, - PBE_SHA1_CAST128_CBC, - PBE_SHA1_RC4_128, - PBE_SHA1_RC4_40, - PBE_SHA1_DES3_EDE_CBC, - PBE_SHA1_DES2_EDE_CBC, - PBE_SHA1_RC2_128_CBC, - PBE_SHA1_RC2_40_CBC, - PKCS5_PBKD2, - PBA_SHA1_WITH_SHA1_HMAC, - WTLS_PRE_MASTER_KEY_GEN, - WTLS_MASTER_KEY_DERIVE, - WTLS_MASTER_KEY_DERIVE_DH_ECC, - WTLS_PRF, - WTLS_SERVER_KEY_AND_MAC_DERIVE, - WTLS_CLIENT_KEY_AND_MAC_DERIVE, - KEY_WRAP_LYNKS, - KEY_WRAP_SET_OAEP, - CMS_SIG, - KIP_DERIVE, - KIP_WRAP, - KIP_MAC, - CAMELLIA_KEY_GEN, - CAMELLIA_ECB, - CAMELLIA_CBC, - CAMELLIA_MAC, - CAMELLIA_MAC_GENERAL, - CAMELLIA_CBC_PAD, - CAMELLIA_ECB_ENCRYPT_DATA, - CAMELLIA_CBC_ENCRYPT_DATA, - CAMELLIA_CTR, - ARIA_KEY_GEN, - ARIA_ECB, - ARIA_CBC, - ARIA_MAC, - ARIA_MAC_GENERAL, - ARIA_CBC_PAD, - ARIA_ECB_ENCRYPT_DATA, - ARIA_CBC_ENCRYPT_DATA, - SKIPJACK_KEY_GEN, - SKIPJACK_ECB64, - SKIPJACK_CBC64, - SKIPJACK_OFB64, - SKIPJACK_CFB64, - SKIPJACK_CFB32, - SKIPJACK_CFB16, - SKIPJACK_CFB8, - SKIPJACK_WRAP, - SKIPJACK_PRIVATE_WRAP, - SKIPJACK_RELAYX, - KEA_KEY_PAIR_GEN, - KEA_KEY_DERIVE, - FORTEZZA_TIMESTAMP, - BATON_KEY_GEN, - BATON_ECB128, - BATON_ECB96, - BATON_CBC128, - BATON_COUNTER, - BATON_SHUFFLE, - BATON_WRAP, - ECDSA_KEY_PAIR_GEN, - EC_KEY_PAIR_GEN, - ECDSA, - ECDSA_SHA1, - ECDSA_SHA224, - ECDSA_SHA256, - ECDSA_SHA384, - ECDSA_SHA512, - ECDH1_DERIVE, - ECDH1_COFACTOR_DERIVE, - ECMQV_DERIVE, - JUNIPER_KEY_GEN, - JUNIPER_ECB128, - JUNIPER_CBC128, - JUNIPER_COUNTER, - JUNIPER_SHUFFLE, - JUNIPER_WRAP, - FASTHASH, - AES_KEY_GEN, - AES_ECB, - AES_CBC, - AES_MAC, - AES_MAC_GENERAL, - AES_CBC_PAD, - AES_CTR, - AES_CMAC, - AES_CMAC_GENERAL, - BLOWFISH_KEY_GEN, - BLOWFISH_CBC, - TWOFISH_KEY_GEN, - TWOFISH_CBC, - AES_GCM, - AES_CCM, - AES_KEY_WRAP, - AES_KEY_WRAP_PAD, - DES_ECB_ENCRYPT_DATA, - DES_CBC_ENCRYPT_DATA, - DES3_ECB_ENCRYPT_DATA, - DES3_CBC_ENCRYPT_DATA, - AES_ECB_ENCRYPT_DATA, - AES_CBC_ENCRYPT_DATA, - GOSTR3410_KEY_PAIR_GEN, - GOSTR3410, - GOSTR3410_WITH_GOSTR3411, - GOSTR3410_KEY_WRAP, - GOSTR3410_DERIVE, - GOSTR3411, - GOSTR3411_HMAC, - GOST28147_KEY_GEN, - GOST28147_ECB, - GOST28147, - GOST28147_MAC, - GOST28147_KEY_WRAP, - DSA_PARAMETER_GEN, - DH_PKCS_PARAMETER_GEN, - X9_42_DH_PARAMETER_GEN, - VENDOR_DEFINED, - } + /** + * returns length of collection + */ + length: number; - interface IParams { - toCKI(): Buffer; - } - - interface IAlgorithm { - name: string; - params: Buffer | IParams; - } - - type MechanismType = MechanismEnum | KeyGenMechanism | IAlgorithm | string; - - enum MechanismFlag { - /** - * `True` if the mechanism is performed by the device; `false` if the mechanism is performed in software - */ - HW, - /** - * `True` if the mechanism can be used with encrypt function - */ - ENCRYPT, - /** - * `True` if the mechanism can be used with decrypt function - */ - DECRYPT, - /** - * `True` if the mechanism can be used with digest function - */ - DIGEST, - /** - * `True` if the mechanism can be used with sign function - */ - SIGN, - /** - * `True` if the mechanism can be used with sign recover function - */ - SIGN_RECOVER, - /** - * `True` if the mechanism can be used with verify function - */ - VERIFY, - /** - * `True` if the mechanism can be used with verify recover function - */ - VERIFY_RECOVER, - /** - * `True` if the mechanism can be used with geberate function - */ - GENERATE, - /** - * `True` if the mechanism can be used with generate key pair function - */ - GENERATE_KEY_PAIR, - /** - * `True` if the mechanism can be used with wrap function - */ - WRAP, - /** - * `True` if the mechanism can be used with unwrap function - */ - UNWRAP, - /** - * `True` if the mechanism can be used with derive function - */ - DERIVE, - } - class Mechanism extends HandleObject { - protected slotHandle: number; - /** - * the minimum size of the key for the mechanism - * _whether this is measured in bits or in bytes is mechanism-dependent_ - */ - minKeySize: number; - /** - * the maximum size of the key for the mechanism - * _whether this is measured in bits or in bytes is mechanism-dependent_ - */ - maxKeySize: number; - /** - * bit flag specifying mechanism capabilities - */ - flags: number; - /** - * returns string name from MechanismEnum - */ - name: string; - constructor(handle: number, slotHandle: number, lib: Pkcs11); - protected getInfo(): void; - static create(alg: MechanismType): Buffer; - static vendor(jsonFile: string): any; - static vendor(name: string, value: number): any; - } - - class MechanismCollection extends Collection { - protected slotHandle: number; - constructor(items: Array, slotHandle: number, lib: Pkcs11, classType?: typeof Mechanism); /** * returns item from collection by index * @param {number} index of element in collection `[0..n]` */ - items(index: number): Mechanism; + items(index: number): T; + + } + type SessionObjectCollection = Collection + type MechanismCollection = Collection; + type SlotCollection = Collection; + + // ========== PKCS11 Objects ========== + + /** + * Certificate objects (object class CKO_CERTIFICATE) hold public-key or attribute certificates + */ + interface Certificate extends Storage { + /** + * Type of certificate + */ + type: graphene.CertificateType; + /** + * The certificate can be trusted for the application that it was created. + */ + trusted: boolean; + /** + * Categorization of the certificate + */ + category: graphene.CertificateCategory; + /** + * Checksum + */ + checkValue: Buffer; + /** + * Start date for the certificate (default empty) + */ + startDate: Date; + /** + * End date for the certificate (default empty) + */ + endDate: Date; + } + + /** + * X.509 certificate objects (certificate type `CKC_X_509`) hold X.509 public key certificates + */ + interface X509Certificate extends Certificate { + /** + * DER-encoding of the certificate subject name + * - Must be specified when the object is created. + * - Must be non-empty if `CKA_URL` is empty. + */ + subject: Buffer; + /** + * Key identifier for public/private key pair (default empty) + */ + id: Buffer; + /** + * DER-encoding of the certificate issuer name (default empty) + */ + issuer: Buffer; + /** + * HEX-encoding of the certificate serial number (default empty) + */ + serialNumber: string; + /** + * BER-encoding of the certificate + * - Must be specified when the object is created. + * - Must be non-empty if `CKA_URL` is empty. + */ + value: Buffer; + /** + * If not empty this attribute gives the URL where the complete certificate + * can be obtained (default empty) + * - Must be non-empty if `CKA_VALUE` is empty + */ + url: string; + /** + * SHA-1 hash of the subject public key (default empty) + * - Can only be empty if `CKA_URL` is empty. + */ + subjetcKeyIdentifier: Buffer; + /** + * SHA-1 hash of the issuer public key (default empty) + * - Can only be empty if `CKA_URL` is empty. + */ + authorityKeyIdentifier: Buffer; + /** + * Java MIDP security domain + */ + java: graphene.JavaMIDP; + } + + /** + * WTLS certificate objects (certificate type `CKC_WTLS`) hold WTLS public key certificates + */ + interface WtlsCertificate extends Certificate { + /** + * WTLS-encoding (Identifier type) of the certificate subject + * - Must be specified when the object is created. + * - Can only be empty if `CKA_VALUE` is empty. + */ + subject: Buffer; + /** + * WTLS-encoding (Identifier type) of the certificate issuer (default empty) + */ + issuer: Buffer; + /** + * Key identifier for public/private key pair (default empty) + */ + id: Buffer; + /** + * WTLS-encoding of the certificate + * - Must be specified when the object is created. + * - Must be non-empty if `CKA_URL` is empty. + */ + value: Buffer; + /** + * If not empty this attribute gives the URL where the complete certificate + * can be obtained (default empty) + * - Must be non-empty if `CKA_VALUE` is empty + */ + url: string; + /** + * DER-encoding of the certificate serial number (default empty) + */ + serialNumber: Buffer; + /** + * SHA-1 hash of the subject public key (default empty) + * - Can only be empty if `CKA_URL` is empty. + */ + subjetcKeyIdentifier: Buffer; + /** + * SHA-1 hash of the issuer public key (default empty) + * - Can only be empty if `CKA_URL` is empty. + */ + authorityKeyIdentifier: Buffer; + } + + /** + * X.509 attribute certificate objects (certificate type `CKC_X_509_ATTR_CERT`) hold X.509 attribute certificates + */ + interface AttributeCertificate extends Certificate { + /** + * DER-encoding of the attribute certificate's subject field. + * This is distinct from the `CKA_SUBJECT` attribute contained in `CKC_X_509` certificates + * because the `ASN.1` syntax and encoding are different. + * - Must be specified when the object is created + */ + owner: Buffer; + /** + * DER-encoding of the attribute certificate's issuer field. + * This is distinct from the `CKA_ISSUER` attribute contained in `CKC_X_509` certificates + * because the ASN.1 syntax and encoding are different. (default empty) + */ + issuer: Buffer; + /** + * DER-encoding of the certificate serial number (default empty) + */ + serialNumber: Buffer; + /** + * BER-encoding of a sequence of object identifier values corresponding + * to the attribute types contained in the certificate. + * When present, this field offers an opportunity for applications + * to search for a particular attribute certificate without fetching + * and parsing the certificate itself. (default empty) + */ + types: Buffer; + /** + * BER-encoding of the certificate + * - Must be specified when the object is created. + */ + value: Buffer; + } + + interface DomainParameters extends Storage { + /** + * Type of key the domain parameters can be used to generate. + */ + keyType: graphene.KeyType; + /** + * `CK_TRUE` only if domain parameters were either * generated locally (i.e., on the token) + * with a `C_GenerateKey` * created with a `C_CopyObject` call as a copy of domain parameters + * which had its `CKA_LOCAL` attribute set to `CK_TRUE` + */ + local: boolean; + } + + /** + * Data objects (object class `CKO_DATA`) hold information defined by an application. + * Other than providing access to it, Cryptoki does not attach any special meaning to a data object + * + * @ + * @class Data + * @extends {Storage} + */ + interface Data extends Storage { + /** + * Description of the application that manages the object (default empty) + * + * @type {string} + */ + application: string; + /** + * DER-encoding of the object identifier indicating the data object type (default empty) + * + * @type {Buffer} + */ + objectId: Buffer; + /** + * Value of the object (default empty) + * + * @type {Buffer} + */ + value: Buffer; } /** @@ -1232,13 +278,13 @@ declare module "graphene-pk11" { * - defines the object class `CKO_PUBLIC_KEY`, `CKO_PRIVATE_KEY` and `CKO_SECRET_KEY` for type `CK_OBJECT_CLASS` * as used in the `CKA_CLASS` attribute of objects */ - class Key extends Storage { + interface Key extends Storage { /** * Type of key * - Must be specified when object is created with `C_CreateObject` * - Must be specified when object is unwrapped with `C_UnwrapKey` */ - type: KeyType; + type: graphene.KeyType; /** * Key identifier for key (default empty) * - May be modified after object is created with a `C_SetAttributeValue` call, @@ -1288,41 +334,737 @@ declare module "graphene-pk11" { * - Must not be specified when object is generated with `C_GenerateKey` or `C_GenerateKeyPair`. * - Must not be specified when object is unwrapped with `C_UnwrapKey`. */ - mechanism: KeyGenMechanism; + mechanism: graphene.KeyGenMechanism; allowedMechanisms: void; } - - class DomainParameters extends Storage { + /** + * Private key objects (object class `CKO_PRIVATE_KEY`) hold private keys + */ + interface PrivateKey extends Key { /** - * Type of key the domain parameters can be used to generate. + * DER-encoding of the key subject name (default empty) + * - May be modified after object is created with a `C_SetAttributeValue` call, + * or in the process of copying object with a `C_CopyObject` call. + * However, it is possible that a particular token may not permit modification of the attribute + * during the course of a `C_CopyObject` call. */ - keyType: KeyType; + subject: Buffer; /** - * `CK_TRUE` only if domain parameters were either * generated locally (i.e., on the token) - * with a `C_GenerateKey` * created with a `C_CopyObject` call as a copy of domain parameters - * which had its `CKA_LOCAL` attribute set to `CK_TRUE` + * `CK_TRUE` if key is sensitive + * - May be modified after object is created with a `C_SetAttributeValue` call, + * or in the process of copying object with a `C_CopyObject` call. + * However, it is possible that a particular token may not permit modification of the attribute + * during the course of a `C_CopyObject` call. + * - Attribute cannot be changed once set to CK_TRUE. It becomes a read only attribute. + * - Default value is token-specific, and may depend on the values of other attributes. */ - local: boolean; + sensitive: boolean; + /** + * `CK_TRUE` if key supports decryption + * - May be modified after object is created with a `C_SetAttributeValue` call, + * or in the process of copying object with a `C_CopyObject` call. + * However, it is possible that a particular token may not permit modification of the attribute + * during the course of a `C_CopyObject` call. + * - Default value is token-specific, and may depend on the values of other attributes. + */ + decrypt: boolean; + /** + * `CK_TRUE` if key supports signatures where the signature is an appendix to the data + * - May be modified after object is created with a `C_SetAttributeValue` call, + * or in the process of copying object with a `C_CopyObject` call. + * However, it is possible that a particular token may not permit modification of the attribute + * during the course of a `C_CopyObject` call. + * - Default value is token-specific, and may depend on the values of other attributes. + */ + sign: boolean; + /** + * `CK_TRUE` if key supports signatures where the data can be recovered from the signature + * - May be modified after object is created with a `C_SetAttributeValue` call, + * or in the process of copying object with a `C_CopyObject` call. + * However, it is possible that a particular token may not permit modification of the attribute + * during the course of a `C_CopyObject` call. + * - Default value is token-specific, and may depend on the values of other attributes. + */ + signRecover: boolean; + /** + * `CK_TRUE` if key supports unwrapping (i.e., can be used to unwrap other keys) + * - May be modified after object is created with a `C_SetAttributeValue` call, + * or in the process of copying object with a `C_CopyObject` call. + * However, it is possible that a particular token may not permit modification of the attribute + * during the course of a `C_CopyObject` call. + * - Default value is token-specific, and may depend on the values of other attributes. + */ + unwrap: boolean; + /** + * `CK_TRUE` if key is extractable and can be wrapped + * - May be modified after object is created with a `C_SetAttributeValue` call, + * or in the process of copying object with a `C_CopyObject` call. + * However, it is possible that a particular token may not permit modification of the attribute + * during the course of a `C_CopyObject` call. + * - Attribute cannot be changed once set to `CK_FALSE`. It becomes a read only attribute. + * - Default value is token-specific, and may depend on the values of other attributes. + */ + extractable: boolean; + /** + * `CK_TRUE` if key has always had the `CKA_SENSITIVE` attribute set to `CK_TRUE` + * - Must not be specified when object is created with `C_CreateObject`. + * - Must not be specified when object is generated with `C_GenerateKey` or `C_GenerateKeyPair`. + * - Must not be specified when object is unwrapped with `C_UnwrapKey`. + */ + alwaysSensitive: boolean; + /** + * `CK_TRUE` if key has never had the `CKA_EXTRACTABLE` attribute set to `CK_TRUE` + * - Must not be specified when object is created with `C_CreateObject`. + * - Must not be specified when object is generated with `C_GenerateKey` or `C_GenerateKeyPair`. + * - Must not be specified when object is unwrapped with `C_UnwrapKey`. + */ + neverExtractable: boolean; + /** + * `CK_TRUE` if the key can only be wrapped with a wrapping key + * that has `CKA_TRUSTED` set to `CK_TRUE`. Default is `CK_FALSE`. + * - Attribute cannot be changed once set to `CK_TRUE`. It becomes a read only attribute. + */ + wrapTrusted: boolean; + /** + * For wrapping keys. The attribute template to apply to any keys unwrapped + * using this wrapping key. Any user supplied template is applied after this template + * as if the object has already been created. + */ + template: void; + alwaysAuthenticate: boolean; } /** - * Data objects (object class `CKO_DATA`) hold information defined by an application. - * Other than providing access to it, Cryptoki does not attach any special meaning to a data object + * Public key objects (object class CKO_PUBLIC_KEY) hold public keys */ - class Data extends Storage { + interface PublicKey extends Key { /** - * Description of the application that manages the object (default empty) + * DER-encoding of the key subject name (default empty) + * - May be modified after object is created with a `C_SetAttributeValue` call, + * or in the process of copying object with a `C_CopyObject` call. + * However, it is possible that a particular token may not permit modification of the attribute + * during the course of a `C_CopyObject` call. */ - application: string; + subject: Buffer; /** - * DER-encoding of the object identifier indicating the data object type (default empty) + * `CK_TRUE` if key supports encryption + * - May be modified after object is created with a `C_SetAttributeValue` call, + * or in the process of copying object with a `C_CopyObject` call. + * However, it is possible that a particular token may not permit modification of the attribute + * during the course of a `C_CopyObject` call. + * - Default value is token-specific, and may depend on the values of other attributes. */ - objectId: Buffer; + encrypt: boolean; /** - * Value of the object (default empty) + * `CK_TRUE` if key supports verification where the signature is an appendix to the data + * - May be modified after object is created with a `C_SetAttributeValue` call, + * or in the process of copying object with a `C_CopyObject` call. + * However, it is possible that a particular token may not permit modification of the attribute + * during the course of a `C_CopyObject` call. + * - Default value is token-specific, and may depend on the values of other attributes. */ + verify: boolean; + /** + * `CK_TRUE` if key supports verification where the data is recovered from the signature + * - May be modified after object is created with a `C_SetAttributeValue` call, + * or in the process of copying object with a `C_CopyObject` call. + * However, it is possible that a particular token may not permit modification of the attribute + * during the course of a `C_CopyObject` call. + * - Default value is token-specific, and may depend on the values of other attributes. + */ + verifyRecover: boolean; + /** + * `CK_TRUE` if key supports wrapping (i.e., can be used to wrap other keys) + * - May be modified after object is created with a `C_SetAttributeValue` call, + * or in the process of copying object with a `C_CopyObject` call. + * However, it is possible that a particular token may not permit modification of the attribute + * during the course of a `C_CopyObject` call. + * - Default value is token-specific, and may depend on the values of other attributes. + */ + wrap: boolean; + /** + * The key can be trusted for the application that it was created. + * - The wrapping key can be used to wrap keys with `CKA_WRAP_WITH_TRUSTED` set to `CK_TRUE`. + * - Can only be set to CK_TRUE by the SO user. + */ + trusted: boolean; + /** + * For wrapping keys. The attribute template to match against any keys wrapped using this wrapping key. + * Keys that do not match cannot be wrapped. + */ + template: void; + } + + /** + * Secret key objects (object class `CKO_SECRET_KEY`) hold secret keys. + */ + interface SecretKey extends Key { + /** + * `CK_TRUE` if key is sensitive + * - May be modified after object is created with a `C_SetAttributeValue` call, + * or in the process of copying object with a `C_CopyObject` call. + * However, it is possible that a particular token may not permit modification of the attribute + * during the course of a `C_CopyObject` call. + * - Attribute cannot be changed once set to `CK_TRUE`. It becomes a read only attribute. + */ + sensitive: boolean; + /** + * `CK_TRUE` if key supports encryption + * - May be modified after object is created with a `C_SetAttributeValue` call, + * or in the process of copying object with a `C_CopyObject` call. + * However, it is possible that a particular token may not permit modification of the attribute + * during the course of a `C_CopyObject` call. + * - Default value is token-specific, and may depend on the values of other attributes. + */ + encrypt: boolean; + /** + * `CK_TRUE` if key supports decryption + * - May be modified after object is created with a `C_SetAttributeValue` call, + * or in the process of copying object with a `C_CopyObject` call. + * However, it is possible that a particular token may not permit modification of the attribute + * during the course of a `C_CopyObject` call. + * - Default value is token-specific, and may depend on the values of other attributes. + */ + decrypt: boolean; + /** + * `CK_TRUE` if key supports verification (i.e., of authentication codes) where the signature is an appendix to the data + * - May be modified after object is created with a `C_SetAttributeValue` call, + * or in the process of copying object with a `C_CopyObject` call. + * However, it is possible that a particular token may not permit modification of the attribute + * during the course of a `C_CopyObject` call. + * - Default value is token-specific, and may depend on the values of other attributes. + */ + verify: boolean; + /** + * `CK_TRUE` if key supports signatures (i.e., authentication codes) where the signature is an appendix to the data + * - May be modified after object is created with a `C_SetAttributeValue` call, + * or in the process of copying object with a `C_CopyObject` call. + * However, it is possible that a particular token may not permit modification of the attribute + * during the course of a `C_CopyObject` call. + * - Default value is token-specific, and may depend on the values of other attributes. + */ + sign: boolean; + /** + * `CK_TRUE` if key supports wrapping (i.e., can be used to wrap other keys) + * - May be modified after object is created with a `C_SetAttributeValue` call, + * or in the process of copying object with a `C_CopyObject` call. + * However, it is possible that a particular token may not permit modification of the attribute + * during the course of a `C_CopyObject` call. + * - Default value is token-specific, and may depend on the values of other attributes. + */ + wrap: boolean; + /** + * `CK_TRUE` if key supports unwrapping (i.e., can be used to unwrap other keys) + * - May be modified after object is created with a `C_SetAttributeValue` call, + * or in the process of copying object with a `C_CopyObject` call. + * However, it is possible that a particular token may not permit modification of the attribute + * during the course of a `C_CopyObject` call. + * - Default value is token-specific, and may depend on the values of other attributes. + */ + unwrap: boolean; + /** + * `CK_TRUE` if key is extractable and can be wrapped + * - May be modified after object is created with a `C_SetAttributeValue` call, + * or in the process of copying object with a `C_CopyObject` call. + * However, it is possible that a particular token may not permit modification of the attribute + * during the course of a `C_CopyObject` call. + * - Attribute cannot be changed once set to `CK_FALSE`. It becomes a read only attribute. + * - Default value is token-specific, and may depend on the values of other attributes. + */ + extractable: boolean; + /** + * `CK_TRUE` if key has always had the `CKA_SENSITIVE` attribute set to `CK_TRUE` + * - Must not be specified when object is created with `C_CreateObject`. + * - Must not be specified when object is generated with `C_GenerateKey` or `C_GenerateKeyPair`. + * - Must not be specified when object is unwrapped with `C_UnwrapKey`. + */ + alwaysSensitive: boolean; + /** + * `CK_TRUE` if key has never had the `CKA_EXTRACTABLE` attribute set to `CK_TRUE` + * - Must not be specified when object is created with `C_CreateObject`. + * - Must not be specified when object is generated with `C_GenerateKey` or `C_GenerateKeyPair`. + * - Must not be specified when object is unwrapped with `C_UnwrapKey`. + */ + neverExtractable: boolean; + /** + * Key checksum + */ + checkValue: Buffer; + /** + * `CK_TRUE` if the key can only be wrapped with a wrapping key + * that has `CKA_TRUSTED` set to `CK_TRUE`. Default is `CK_FALSE`. + * - Attribute cannot be changed once set to `CK_TRUE`. It becomes a read only attribute. + */ + wrapTrusted: boolean; + /** + * The wrapping key can be used to wrap keys with `CKA_WRAP_WITH_TRUSTED` set to `CK_TRUE`. + * - Can only be set to CK_TRUE by the SO user. + */ + trusted: boolean; + /** + * For wrapping keys. + * The attribute template to match against any keys wrapped using this wrapping key. + * Keys that do not match cannot be wrapped. + */ + wrapTemplate: void; + /** + * For wrapping keys. + * The attribute template to apply to any keys unwrapped using this wrapping key. + * Any user supplied template is applied after this template as if the object has already been created. + */ + unwrapTemplate: void; + } + + interface Storage extends SessionObject { + /** + * `true` if object is a token object; + * `false` if object is a session object. Default is `false`. + */ + token: boolean; + /** + * `true` if object is a private object; + * `false` if object is a public object. + * Default value is token-specific, and may depend on the values of other attributes of the object. + */ + private: boolean; + /** + * `true` if object can be modified. Default is `false` + */ + modifiable: boolean; + /** + * Description of the object (default empty) + */ + label: string; + } + + interface SessionObject extends HandleObject { + /** + * Session + */ + session: Session; + /** + * gets the size of an object in bytes + * + * @readonly + * @type {number} + */ + size: number; + /** + * copies an object, creating a new object for the copy + * + * @param {ITemplate} template template for the new object + * @returns {SessionObject} + */ + copy(template: ITemplate): SessionObject; + /** + * destroys an object + */ + destroy(): void; + getAttribute(attr: string): ITemplate; + getAttribute(attrs: ITemplate): ITemplate; + setAttribute(attrs: string, value: any): void; + setAttribute(attrs: ITemplate): void; + class: graphene.ObjectClass; + toType(): T; + } + + // ========== Crypto ========== + + /** + * Type CryptoData + */ + type CryptoData = string | Buffer; + + interface INamedCurve { + name: string; + oid: string; value: Buffer; + size: number; + } + + /** + * Cipher + * + * @interface Cipher + * @extends {BaseObject} + */ + interface Cipher extends BaseObject { + update(data: CryptoData): Buffer; + final(): Buffer; + once(data: CryptoData, enc: Buffer): Buffer; + once(data: CryptoData, enc: Buffer, cb: (error: Error, data: Buffer) => void): void; + } + + /** + * Decipher + * + * @interface Decipher + * @extends {BaseObject} + */ + interface Decipher extends BaseObject { + update(data: Buffer): Buffer; + final(): Buffer; + once(data: Buffer, dec: Buffer): Buffer; + once(data: Buffer, dec: Buffer, cb: (error: Error, data: Buffer) => void): void; + } + + /** + * Digest + * + * @interface Digest + * @extends {BaseObject} + */ + interface Digest extends BaseObject { + update(data: CryptoData): void; + final(): Buffer; + once(data: CryptoData): Buffer; + once(data: CryptoData, cb: (error: Error, data: Buffer) => void): void; + } + + /** + * Sign + * + * @interface Sign + * @extends {BaseObject} + */ + interface Sign extends BaseObject { + update(data: CryptoData): void; + final(): Buffer; + once(data: CryptoData): Buffer; + once(data: CryptoData, cb: (error: Error, data: Buffer) => void): void; + } + + /** + * Verify + * + * @interface Verify + * @extends {BaseObject} + */ + interface Verify extends BaseObject { + update(data: CryptoData): void; + final(signature: Buffer): boolean; + once(data: CryptoData, signature: Buffer): boolean; + once(data: CryptoData, signature: Buffer, cb: (error: Error, valid: boolean) => void): void; + } + + interface IAlgorithm { + name: string; + params: Buffer | IParams; + } + + type MechanismType = graphene.MechanismEnum | graphene.KeyGenMechanism | IAlgorithm | string; + + interface Mechanism extends BaseObject { + /** + * the minimum size of the key for the mechanism + * _whether this is measured in bits or in bytes is mechanism-dependent_ + */ + minKeySize: number; + /** + * the maximum size of the key for the mechanism + * _whether this is measured in bits or in bytes is mechanism-dependent_ + */ + maxKeySize: number; + /** + * bit flag specifying mechanism capabilities + */ + flags: number; + /** + * returns string name from MechanismEnum + */ + name: string; + } + + interface IParams { + toCKI(): any; + } + + interface IKeyPair { + privateKey: PrivateKey; + publicKey: PublicKey; + } + + /** + * provides information about a session + * + * @ + * @class Session + * @extends {HandleObject} + */ + interface Session extends HandleObject { + constructor(handle: Handle, slot: Slot, lib: pkcs11.PKCS11); + /** + * Slot + * + * @type {Slot} + */ + slot: Slot; + /** + * the state of the session + * + * @type {number} + */ + state: number; + /** + * bit flags that define the type of session + * + * @type {number} + */ + flags: number; + /** + * an error code defined by the cryptographic device. Used for errors not covered by Cryptoki + * + * @type {number} + */ + deviceError: number; + /** + * closes a session between an application and a token + */ + close(): void; + /** + * initializes the normal user's PIN + * @param {string} pin the normal user's PIN + */ + initPin(pin: string): void; + /** + * modifies the PIN of the user who is logged in + * @param {string} oldPin + * @param {string} newPin + */ + setPin(oldPin: string, newPin: string): void; + /** + * obtains a copy of the cryptographic operations state of a session, encoded as a string of bytes + */ + getOperationState(): Buffer; + /** + * restores the cryptographic operations state of a session + * from a string of bytes obtained with getOperationState + * @param {Buffer} state the saved state + * @param {number} encryptionKey holds key which will be used for an ongoing encryption + * or decryption operation in the restored session + * (or 0 if no encryption or decryption key is needed, + * either because no such operation is ongoing in the stored session + * or because all the necessary key information is present in the saved state) + * @param {number} authenticationKey holds a handle to the key which will be used for an ongoing signature, + * MACing, or verification operation in the restored session + * (or 0 if no such key is needed, either because no such operation is ongoing in the stored session + * or because all the necessary key information is present in the saved state) + */ + setOperationState(state: Buffer, encryptionKey?: number, authenticationKey?: number): void; + /** + * logs a user into a token + * @param {string} pin the user's PIN. + * - This standard allows PIN values to contain any valid `UTF8` character, + * but the token may impose subset restrictions + * @param {} userType the user type. Default is `USER` + */ + login(pin: string, userType?: graphene.UserType): void; + /** + * logs a user out from a token + */ + logout(): void; + /** + * creates a new object + * - Only session objects can be created during a read-only session. + * - Only public objects can be created unless the normal user is logged in. + * @param {ITemplate} template the object's template + * @returns {SessionObject} + */ + create(template: ITemplate): SessionObject; + /** + * Copies an object, creating a new object for the copy + * @param {SessionObject} object the copied object + * @param {ITemplate} template template for new object + * @returns {SessionObject} + */ + copy(object: SessionObject, template: ITemplate): SessionObject; + /** + * removes all session objects matched to template + * - if template is null, removes all session objects + * - returns a number of destroied session objects + * @param {ITemplate} template template + */ + destroy(template: ITemplate): number; + /** + * @param {SessionObject} object + */ + destroy(object: SessionObject): number; + destroy(): number; + /** + * removes all session objects + * - returns a number of destroied session objects + */ + clear(): number; + /** + * returns a collection of session objects mached to template + * @param template template + * @param callback optional callback function wich is called for each founded object + * - if callback function returns false, it breaks find function. + */ + find(callback?: (obj: SessionObject) => any): SessionObjectCollection; + find(template: ITemplate, callback?: (obj: SessionObject, index: number) => any): SessionObjectCollection; + /** + * Returns object from session by handle + * @param {number} handle handle of object + * @returns T + */ + getObject(handle: Handle): T; + /** + * generates a secret key or set of domain parameters, creating a new object. + * @param mechanism generation mechanism + * @param template template for the new key or set of domain parameters + */ + generateKey(mechanism: MechanismType, template?: ITemplate): SecretKey; + generateKey(mechanism: MechanismType, template: ITemplate, callback: (err: Error, key: SecretKey) => void): void; + generateKeyPair(mechanism: MechanismType, publicTemplate: ITemplate, privateTemplate: ITemplate): IKeyPair; + generateKeyPair(mechanism: MechanismType, publicTemplate: ITemplate, privateTemplate: ITemplate, callback: (err: Error, keys: IKeyPair) => void): void; + createSign(alg: MechanismType, key: Key): Sign; + createVerify(alg: MechanismType, key: Key): Verify; + createCipher(alg: MechanismType, key: Key): Cipher; + createDecipher(alg: MechanismType, key: Key, blockSize?: number): Decipher; + createDigest(alg: MechanismType): Digest; + wrapKey(alg: MechanismType, wrappingKey: Key, key: Key): Buffer; + wrapKey(alg: MechanismType, wrappingKey: Key, key: Key, callback: (err: Error, wkey: Buffer) => void): void; + unwrapKey(alg: MechanismType, unwrappingKey: Key, wrappedKey: Buffer, template: ITemplate): Key; + unwrapKey(alg: MechanismType, unwrappingKey: Key, wrappedKey: Buffer, template: ITemplate, callback: (err: Error, key: Key) => void): void; + /** + * derives a key from a base key, creating a new key object + * @param {MechanismType} alg key deriv. mech + * @param {Key} baseKey base key + * @param {ITemplate} template new key template + */ + deriveKey(alg: MechanismType, baseKey: Key, template: ITemplate): SecretKey; + deriveKey(alg: MechanismType, baseKey: Key, template: ITemplate, callback: (err: Error, key: Key) => void): void; + /** + * generates random data + * @param {number} size \# of bytes to generate + */ + generateRandom(size: number): Buffer; + } + + interface Slot extends HandleObject { + slotDescription: string; + manufacturerID: string; + flags: number; + hardwareVersion: pkcs11.Version; + firmwareVersion: pkcs11.Version; + module: graphene.Module; + /** + * Returns information about token + * + * @returns {Token} + */ + getToken(): Token; + /** + * returns list of `MechanismInfo` + * + * @returns {MechanismCollection} + */ + getMechanisms(): MechanismCollection; + /** + * initializes a token + * + * @param {string} pin the SO's initial PIN + * @returns {string} + */ + initToken(pin: string): string; + /** + * opens a session between an application and a token in a particular slot + * + * @param {SessionFlag} [flags=session.SessionFlag.SERIAL_SESSION] indicates the type of session + * @returns {Session} + */ + open(flags?: graphene.SessionFlag): Session; + /** + * closes all sessions an application has with a token + */ + closeAll(): void; + } + + interface Token extends HandleObject { + /** + * application-defined label, assigned during token initialization. + * - Must be padded with the blank character (' '). + * - Should __not__ be null-terminated. + */ + label: string; + /** + * ID of the device manufacturer. + * - Must be padded with the blank character (' '). + * - Should __not__ be null-terminated. + */ + manufacturerID: string; + /** + * model of the device. + * - Must be padded with the blank character (' '). + * - Should __not__ be null-terminated. + */ + model: string; + /** + * character-string serial number of the device. + * - Must be padded with the blank character (' '). + * - Should __not__ be null-terminated. + */ + serialNumber: string; + /** + * bit flags indicating capabilities and status of the device + */ + flags: number; + /** + * maximum number of sessions that can be opened with the token at one time by a single application + */ + maxSessionCount: number; + /** + * number of sessions that this application currently has open with the token + */ + sessionCount: number; + /** + * maximum number of read/write sessions that can be opened + * with the token at one time by a single application + */ + maxRwSessionCount: number; + /** + * number of read/write sessions that this application currently has open with the token + */ + rwSessionCount: number; + /** + * maximum length in bytes of the PIN + */ + maxPinLen: number; + /** + * minimum length in bytes of the PIN + */ + minPinLen: number; + /** + * the total amount of memory on the token in bytes in which public objects may be stored + */ + totalPublicMemory: number; + /** + * the amount of free (unused) memory on the token in bytes for public objects + */ + freePublicMemory: number; + /** + * the total amount of memory on the token in bytes in which private objects may be stored + */ + totalPrivateMemory: number; + /** + * the amount of free (unused) memory on the token in bytes for private objects + */ + freePrivateMemory: number; + /** + * version number of hardware + */ + hardwareVersion: pkcs11.Version; + /** + * version number of firmware + */ + firmwareVersion: pkcs11.Version; + /** + * current time as a character-string of length 16, + * represented in the format YYYYMMDDhhmmssxx + */ + utcTime: Date; } interface ITemplate { @@ -1638,7 +1380,7 @@ declare module "graphene-pk11" { /** * CKA_OTP_USER_IDENTIFIER */ - OtpUserId?: any; + otpUserId?: any; /** * CKA_OTP_SERVICE_IDENTIFIER */ @@ -1724,41 +1466,211 @@ declare module "graphene-pk11" { */ allowedMechanisms?: any; } - class Attribute { - protected $value: Buffer; - type: number; - name: string; - convertType: string; - length: number; - value: any; - constructor(type: number, value?: any); - constructor(type: string, value?: any); - get(): any; - set(template: any): void; - } - class Template { - protected attrs: Attribute[]; - length: number; - constructor(template: string); - constructor(template: ITemplate); - set(v: any): Template; - ref(): Buffer; - serialize(): any; + +} + +declare module "graphene-pk11" { + import * as graphene from "types/graphene-pk11"; + import * as pkcs11 from "pkcs11js"; + + // ========== Parameters ========== + + // ========== AES ========== + + /** + * Parameter AES CBC + * + * @class AesCbcParams + * @implements {graphene.IParams} + * @implements {pkcs11.AesCBC} + */ + class AesCbcParams implements graphene.IParams, pkcs11.AesCBC { + /** + * initialization vector + * - must have a fixed size of 16 bytes + */ + iv: Buffer; + /** + * the data + */ + data: Buffer; + type: MechParams; + constructor(iv: Buffer, data?: Buffer); + toCKI(): Buffer; } - class BaseObject { - protected lib: Pkcs11; - constructor(lib?: Pkcs11); - } - class HandleObject extends BaseObject { + /** + * Parameter AES CCM + * + * @class AesCcmParams + * @implements {graphene.IParams} + */ + class AesCcmParams implements graphene.IParams { /** - * handle to pkcs11 object + * length of the data where 0 <= dataLength < 2^8L */ - handle: number; - constructor(handle: number, lib: Pkcs11); - protected getInfo(): void; + dataLength: number; + /** + * the nonce + */ + nonce: Buffer; + /** + * the additional authentication data + * - This data is authenticated but not encrypted + */ + aad: Buffer; + /** + * length of authentication tag (output following cipher text) in bits. + * - Can be any value between 0 and 128 + */ + macLength: number; + type: MechParams; + constructor(dataLength: number, nonce: Buffer, aad?: Buffer, macLength?: number); + toCKI(): pkcs11.AesCCM; } + /** + * Parameter AES GCM + * + * @class AesGcmParams + * @implements {graphene.IParams} + */ + class AesGcmParams implements graphene.IParams { + /** + * initialization vector + * - The length of the initialization vector can be any number between 1 and 256. + * 96-bit (12 byte) IV values can be processed more efficiently, + * so that length is recommended for situations in which efficiency is critical. + */ + iv: Buffer; + /** + * pointer to additional authentication data. + * This data is authenticated but not encrypted. + */ + aad: Buffer; + /** + * length of authentication tag (output following cipher text) in bits. + * Can be any value between 0 and 128. Default 128 + */ + tagBits: number; + type: MechParams; + constructor(iv: Buffer, aad?: Buffer, tagBits?: number); + toCKI(): pkcs11.AesGCM; + } + + // ========== EC ========== + + /** + * Parameter EC DH + * + * @class EcdhParams + * @implements {graphene.IParams} + * @implements {pkcs11.ECDH1} + */ + class EcdhParams implements graphene.IParams, pkcs11.ECDH1 { + /** + * key derivation function used on the shared secret value + */ + kdf: EcKdf; + /** + * some data shared between the two parties + */ + sharedData: Buffer; + /** + * other party's EC public key value + */ + publicData: Buffer; + type: MechParams; + /** + * Creates an instance of EcdhParams. + * + * @param {EcKdf} kdf key derivation function used on the shared secret value + * @param {Buffer} [sharedData=null] some data shared between the two parties + * @param {Buffer} [publicData=null] other party's EC public key value + */ + constructor(kdf: EcKdf, sharedData?: Buffer, publicData?: Buffer); + toCKI(): pkcs11.ECDH1; + } + + class NamedCurve { + static getByName(name: string): graphene.INamedCurve; + static getByOid(oid: string): graphene.INamedCurve; + } + + /** + * EcKdf is used to indicate the Key Derivation Function (KDF) + * applied to derive keying data from a shared secret. + * The key derivation function will be used by the EC key agreement schemes. + */ + enum EcKdf { + NULL, + SHA1, + SHA224, + SHA256, + SHA384, + SHA512, + } + + // ========== RSA ========== + + /** + * Parameter RSA OAEP + * + * @class RsaOaepParams + * @implements {graphene.IParams} + */ + class RsaOaepParams implements graphene.IParams { + hashAlgorithm: MechanismEnum; + mgf: RsaMgf; + source: number; + sourceData: Buffer; + type: MechParams; + constructor(hashAlg?: MechanismEnum, mgf?: RsaMgf, sourceData?: Buffer); + toCKI(): pkcs11.RsaOAEP; + } + + /** + * Parameter RSA PSS + * + * @class RsaPssParams + * @implements {graphene.IParams} + */ + class RsaPssParams implements graphene.IParams { + /** + * hash algorithm used in the PSS encoding; + * - if the signature mechanism does not include message hashing, + * then this value must be the mechanism used by the application to generate + * the message hash; + * - if the signature mechanism includes hashing, + * then this value must match the hash algorithm indicated + * by the signature mechanism + */ + hashAlgorithm: MechanismEnum; + /** + * mask generation function to use on the encoded block + */ + mgf: RsaMgf; + /** + * length, in bytes, of the salt value used in the PSS encoding; + * - typical values are the length of the message hash and zero + */ + saltLength: number; + type: MechParams; + constructor(hashAlg?: MechanismEnum, mgf?: RsaMgf, saltLen?: number); + toCKI(): pkcs11.RsaPSS; + } + + enum RsaMgf { + MGF1_SHA1, + MGF1_SHA224, + MGF1_SHA256, + MGF1_SHA384, + MGF1_SHA512, + } + + + // ========== Enums ========== + enum ObjectClass { DATA, CERTIFICATE, @@ -1771,327 +1683,467 @@ declare module "graphene-pk11" { OTP_KEY, } - class SessionObject extends HandleObject { - /** - * Session - */ - session: Session; - /** - * gets the size of an object in bytes - */ - size: number; - constructor(object: SessionObject); - constructor(handle: number, session: Session, lib: Pkcs11); - /** - * copies an object, creating a new object for the copy - * @param {ITemplate} template template for the new object - */ - copy(template: ITemplate): SessionObject; - /** - * destroys an object - */ - destroy(): void; - getAttribute(attr: string): ITemplate; - getAttribute(attrs: ITemplate): ITemplate; - setAttribute(attrs: string, value: any): any; - setAttribute(attrs: ITemplate): any; - protected get(name: string): any; - protected set(name: string, value: any): void; - class: ObjectClass; - toType(): T; + class Mechanism { + static vendor(jsonFile: string): void; + static vendor(name: string, value: number): void; } - class SessionObjectCollection extends Collection { - session: Session; - items(index: number): SessionObject; - constructor(items: Array, session: Session, lib: Pkcs11, classType?: any); + enum CertificateType { + X_509, + X_509_ATTR_CERT, + WTLS, } - /** - * Private key objects (object class `CKO_PRIVATE_KEY`) hold private keys - */ - class PrivateKey extends Key { - /** - * DER-encoding of the key subject name (default empty) - * - May be modified after object is created with a `C_SetAttributeValue` call, - * or in the process of copying object with a `C_CopyObject` call. - * However, it is possible that a particular token may not permit modification of the attribute - * during the course of a `C_CopyObject` call. - */ - subject: Buffer; - /** - * `CK_TRUE` if key is sensitive - * - May be modified after object is created with a `C_SetAttributeValue` call, - * or in the process of copying object with a `C_CopyObject` call. - * However, it is possible that a particular token may not permit modification of the attribute - * during the course of a `C_CopyObject` call. - * - Attribute cannot be changed once set to CK_TRUE. It becomes a read only attribute. - * - Default value is token-specific, and may depend on the values of other attributes. - */ - sensitive: boolean; - /** - * `CK_TRUE` if key supports decryption - * - May be modified after object is created with a `C_SetAttributeValue` call, - * or in the process of copying object with a `C_CopyObject` call. - * However, it is possible that a particular token may not permit modification of the attribute - * during the course of a `C_CopyObject` call. - * - Default value is token-specific, and may depend on the values of other attributes. - */ - decrypt: boolean; - /** - * `CK_TRUE` if key supports signatures where the signature is an appendix to the data - * - May be modified after object is created with a `C_SetAttributeValue` call, - * or in the process of copying object with a `C_CopyObject` call. - * However, it is possible that a particular token may not permit modification of the attribute - * during the course of a `C_CopyObject` call. - * - Default value is token-specific, and may depend on the values of other attributes. - */ - sign: boolean; - /** - * `CK_TRUE` if key supports signatures where the data can be recovered from the signature - * - May be modified after object is created with a `C_SetAttributeValue` call, - * or in the process of copying object with a `C_CopyObject` call. - * However, it is possible that a particular token may not permit modification of the attribute - * during the course of a `C_CopyObject` call. - * - Default value is token-specific, and may depend on the values of other attributes. - */ - signRecover: boolean; - /** - * `CK_TRUE` if key supports unwrapping (i.e., can be used to unwrap other keys) - * - May be modified after object is created with a `C_SetAttributeValue` call, - * or in the process of copying object with a `C_CopyObject` call. - * However, it is possible that a particular token may not permit modification of the attribute - * during the course of a `C_CopyObject` call. - * - Default value is token-specific, and may depend on the values of other attributes. - */ - unwrap: boolean; - /** - * `CK_TRUE` if key is extractable and can be wrapped - * - May be modified after object is created with a `C_SetAttributeValue` call, - * or in the process of copying object with a `C_CopyObject` call. - * However, it is possible that a particular token may not permit modification of the attribute - * during the course of a `C_CopyObject` call. - * - Attribute cannot be changed once set to `CK_FALSE`. It becomes a read only attribute. - * - Default value is token-specific, and may depend on the values of other attributes. - */ - extractable: boolean; - /** - * `CK_TRUE` if key has always had the `CKA_SENSITIVE` attribute set to `CK_TRUE` - * - Must not be specified when object is created with `C_CreateObject`. - * - Must not be specified when object is generated with `C_GenerateKey` or `C_GenerateKeyPair`. - * - Must not be specified when object is unwrapped with `C_UnwrapKey`. - */ - alwaysSensitive: boolean; - /** - * `CK_TRUE` if key has never had the `CKA_EXTRACTABLE` attribute set to `CK_TRUE` - * - Must not be specified when object is created with `C_CreateObject`. - * - Must not be specified when object is generated with `C_GenerateKey` or `C_GenerateKeyPair`. - * - Must not be specified when object is unwrapped with `C_UnwrapKey`. - */ - neverExtractable: boolean; - /** - * `CK_TRUE` if the key can only be wrapped with a wrapping key - * that has `CKA_TRUSTED` set to `CK_TRUE`. Default is `CK_FALSE`. - * - Attribute cannot be changed once set to `CK_TRUE`. It becomes a read only attribute. - */ - wrapTrusted: boolean; - /** - * For wrapping keys. The attribute template to apply to any keys unwrapped - * using this wrapping key. Any user supplied template is applied after this template - * as if the object has already been created. - */ - template: void; - alwaysAuthenticate: boolean; + enum CertificateCategory { + Unspecified = 0, + TokenUser = 1, + Authority = 2, + OtherEntity = 3, } - /** - * Public key objects (object class CKO_PUBLIC_KEY) hold public keys - */ - class PublicKey extends Key { - /** - * DER-encoding of the key subject name (default empty) - * - May be modified after object is created with a `C_SetAttributeValue` call, - * or in the process of copying object with a `C_CopyObject` call. - * However, it is possible that a particular token may not permit modification of the attribute - * during the course of a `C_CopyObject` call. - */ - subject: Buffer; - /** - * `CK_TRUE` if key supports encryption - * - May be modified after object is created with a `C_SetAttributeValue` call, - * or in the process of copying object with a `C_CopyObject` call. - * However, it is possible that a particular token may not permit modification of the attribute - * during the course of a `C_CopyObject` call. - * - Default value is token-specific, and may depend on the values of other attributes. - */ - encrypt: boolean; - /** - * `CK_TRUE` if key supports verification where the signature is an appendix to the data - * - May be modified after object is created with a `C_SetAttributeValue` call, - * or in the process of copying object with a `C_CopyObject` call. - * However, it is possible that a particular token may not permit modification of the attribute - * during the course of a `C_CopyObject` call. - * - Default value is token-specific, and may depend on the values of other attributes. - */ - verify: boolean; - /** - * `CK_TRUE` if key supports verification where the data is recovered from the signature - * - May be modified after object is created with a `C_SetAttributeValue` call, - * or in the process of copying object with a `C_CopyObject` call. - * However, it is possible that a particular token may not permit modification of the attribute - * during the course of a `C_CopyObject` call. - * - Default value is token-specific, and may depend on the values of other attributes. - */ - verifyRecover: boolean; - /** - * `CK_TRUE` if key supports wrapping (i.e., can be used to wrap other keys) - * - May be modified after object is created with a `C_SetAttributeValue` call, - * or in the process of copying object with a `C_CopyObject` call. - * However, it is possible that a particular token may not permit modification of the attribute - * during the course of a `C_CopyObject` call. - * - Default value is token-specific, and may depend on the values of other attributes. - */ - wrap: boolean; - /** - * The key can be trusted for the application that it was created. - * - The wrapping key can be used to wrap keys with `CKA_WRAP_WITH_TRUSTED` set to `CK_TRUE`. - * - Can only be set to CK_TRUE by the SO user. - */ - trusted: boolean; - /** - * For wrapping keys. The attribute template to match against any keys wrapped using this wrapping key. - * Keys that do not match cannot be wrapped. - */ - template: void; + enum KeyType { + RSA, + DSA, + DH, + ECDSA, + EC, + X9_42_DH, + KEA, + GENERIC_SECRET, + RC2, + RC4, + DES, + DES2, + DES3, + CAST, + CAST3, + CAST5, + CAST128, + RC5, + IDEA, + SKIPJACK, + BATON, + JUNIPER, + CDMF, + AES, + GOSTR3410, + GOSTR3411, + GOST28147, + BLOWFISH, + TWOFISH, + SECURID, + HOTP, + ACTI, + CAMELLIA, + ARIA, } - /** - * Secret key objects (object class `CKO_SECRET_KEY`) hold secret keys. - */ - class SecretKey extends Key { - /** - * `CK_TRUE` if key is sensitive - * - May be modified after object is created with a `C_SetAttributeValue` call, - * or in the process of copying object with a `C_CopyObject` call. - * However, it is possible that a particular token may not permit modification of the attribute - * during the course of a `C_CopyObject` call. - * - Attribute cannot be changed once set to `CK_TRUE`. It becomes a read only attribute. - */ - sensitive: boolean; - /** - * `CK_TRUE` if key supports encryption - * - May be modified after object is created with a `C_SetAttributeValue` call, - * or in the process of copying object with a `C_CopyObject` call. - * However, it is possible that a particular token may not permit modification of the attribute - * during the course of a `C_CopyObject` call. - * - Default value is token-specific, and may depend on the values of other attributes. - */ - encrypt: boolean; - /** - * `CK_TRUE` if key supports decryption - * - May be modified after object is created with a `C_SetAttributeValue` call, - * or in the process of copying object with a `C_CopyObject` call. - * However, it is possible that a particular token may not permit modification of the attribute - * during the course of a `C_CopyObject` call. - * - Default value is token-specific, and may depend on the values of other attributes. - */ - decrypt: boolean; - /** - * `CK_TRUE` if key supports verification (i.e., of authentication codes) where the signature is an appendix to the data - * - May be modified after object is created with a `C_SetAttributeValue` call, - * or in the process of copying object with a `C_CopyObject` call. - * However, it is possible that a particular token may not permit modification of the attribute - * during the course of a `C_CopyObject` call. - * - Default value is token-specific, and may depend on the values of other attributes. - */ - verify: boolean; - /** - * `CK_TRUE` if key supports signatures (i.e., authentication codes) where the signature is an appendix to the data - * - May be modified after object is created with a `C_SetAttributeValue` call, - * or in the process of copying object with a `C_CopyObject` call. - * However, it is possible that a particular token may not permit modification of the attribute - * during the course of a `C_CopyObject` call. - * - Default value is token-specific, and may depend on the values of other attributes. - */ - sign: boolean; - /** - * `CK_TRUE` if key supports wrapping (i.e., can be used to wrap other keys) - * - May be modified after object is created with a `C_SetAttributeValue` call, - * or in the process of copying object with a `C_CopyObject` call. - * However, it is possible that a particular token may not permit modification of the attribute - * during the course of a `C_CopyObject` call. - * - Default value is token-specific, and may depend on the values of other attributes. - */ - wrap: boolean; - /** - * `CK_TRUE` if key supports unwrapping (i.e., can be used to unwrap other keys) - * - May be modified after object is created with a `C_SetAttributeValue` call, - * or in the process of copying object with a `C_CopyObject` call. - * However, it is possible that a particular token may not permit modification of the attribute - * during the course of a `C_CopyObject` call. - * - Default value is token-specific, and may depend on the values of other attributes. - */ - unwrap: boolean; - /** - * `CK_TRUE` if key is extractable and can be wrapped - * - May be modified after object is created with a `C_SetAttributeValue` call, - * or in the process of copying object with a `C_CopyObject` call. - * However, it is possible that a particular token may not permit modification of the attribute - * during the course of a `C_CopyObject` call. - * - Attribute cannot be changed once set to `CK_FALSE`. It becomes a read only attribute. - * - Default value is token-specific, and may depend on the values of other attributes. - */ - extractable: boolean; - /** - * `CK_TRUE` if key has always had the `CKA_SENSITIVE` attribute set to `CK_TRUE` - * - Must not be specified when object is created with `C_CreateObject`. - * - Must not be specified when object is generated with `C_GenerateKey` or `C_GenerateKeyPair`. - * - Must not be specified when object is unwrapped with `C_UnwrapKey`. - */ - alwaysSensitive: boolean; - /** - * `CK_TRUE` if key has never had the `CKA_EXTRACTABLE` attribute set to `CK_TRUE` - * - Must not be specified when object is created with `C_CreateObject`. - * - Must not be specified when object is generated with `C_GenerateKey` or `C_GenerateKeyPair`. - * - Must not be specified when object is unwrapped with `C_UnwrapKey`. - */ - neverExtractable: boolean; - /** - * Key checksum - */ - checkValue: Buffer; - /** - * `CK_TRUE` if the key can only be wrapped with a wrapping key - * that has `CKA_TRUSTED` set to `CK_TRUE`. Default is `CK_FALSE`. - * - Attribute cannot be changed once set to `CK_TRUE`. It becomes a read only attribute. - */ - wrapTrusted: boolean; - /** - * The wrapping key can be used to wrap keys with `CKA_WRAP_WITH_TRUSTED` set to `CK_TRUE`. - * - Can only be set to CK_TRUE by the SO user. - */ - trusted: boolean; - /** - * For wrapping keys. - * The attribute template to match against any keys wrapped using this wrapping key. - * Keys that do not match cannot be wrapped. - */ - wrapTemplate: void; - /** - * For wrapping keys. - * The attribute template to apply to any keys unwrapped using this wrapping key. - * Any user supplied template is applied after this template as if the object has already been created. - */ - unwrapTemplate: void; + enum KeyGenMechanism { + AES, + RSA, + RSA_X9_31, + DSA, + DH_PKCS, + DH_X9_42, + GOSTR3410, + GOST28147, + RC2, + RC4, + DES, + DES2, + SECURID, + ACTI, + CAST, + CAST3, + CAST5, + CAST128, + RC5, + IDEA, + GENERIC_SECRET, + SSL3_PRE_MASTER, + CAMELLIA, + ARIA, + SKIPJACK, + KEA, + BATON, + ECDSA, + EC, + JUNIPER, + TWOFISH, } + enum MechanismFlag { + /** + * `True` if the mechanism is performed by the device; `false` if the mechanism is performed in software + */ + HW, + /** + * `True` if the mechanism can be used with encrypt function + */ + ENCRYPT, + /** + * `True` if the mechanism can be used with decrypt function + */ + DECRYPT, + /** + * `True` if the mechanism can be used with digest function + */ + DIGEST, + /** + * `True` if the mechanism can be used with sign function + */ + SIGN, + /** + * `True` if the mechanism can be used with sign recover function + */ + SIGN_RECOVER, + /** + * `True` if the mechanism can be used with verify function + */ + VERIFY, + /** + * `True` if the mechanism can be used with verify recover function + */ + VERIFY_RECOVER, + /** + * `True` if the mechanism can be used with geberate function + */ + GENERATE, + /** + * `True` if the mechanism can be used with generate key pair function + */ + GENERATE_KEY_PAIR, + /** + * `True` if the mechanism can be used with wrap function + */ + WRAP, + /** + * `True` if the mechanism can be used with unwrap function + */ + UNWRAP, + /** + * `True` if the mechanism can be used with derive function + */ + DERIVE, + } - interface ISlotInfo { - slotDescription: string; - manufacturerID: string; - flags: number; - hardwareVersion: IVersion; - firmwareVersion: IVersion; + enum MechanismEnum { + RSA_PKCS_KEY_PAIR_GEN, + RSA_PKCS, + RSA_9796, + RSA_X_509, + MD2_RSA_PKCS, + MD5_RSA_PKCS, + SHA1_RSA_PKCS, + RIPEMD128_RSA_PKCS, + RIPEMD160_RSA_PKCS, + RSA_PKCS_OAEP, + RSA_X9_31_KEY_PAIR_GEN, + RSA_X9_31, + SHA1_RSA_X9_31, + RSA_PKCS_PSS, + SHA1_RSA_PKCS_PSS, + DSA_KEY_PAIR_GEN, + DSA, + DSA_SHA1, + DSA_SHA224, + DSA_SHA256, + DSA_SHA384, + DSA_SHA512, + DH_PKCS_KEY_PAIR_GEN, + DH_PKCS_DERIVE, + X9_42_DH_KEY_PAIR_GEN, + X9_42_DH_DERIVE, + X9_42_DH_HYBRID_DERIVE, + X9_42_MQV_DERIVE, + SHA256_RSA_PKCS, + SHA384_RSA_PKCS, + SHA512_RSA_PKCS, + SHA256_RSA_PKCS_PSS, + SHA384_RSA_PKCS_PSS, + SHA512_RSA_PKCS_PSS, + SHA224_RSA_PKCS, + SHA224_RSA_PKCS_PSS, + RC2_KEY_GEN, + RC2_ECB, + RC2_CBC, + RC2_MAC, + RC2_MAC_GENERAL, + RC2_CBC_PAD, + RC4_KEY_GEN, + RC4, + DES_KEY_GEN, + DES_ECB, + DES_CBC, + DES_MAC, + DES_MAC_GENERAL, + DES_CBC_PAD, + DES2_KEY_GEN, + DES3_KEY_GEN, + DES3_ECB, + DES3_CBC, + DES3_MAC, + DES3_MAC_GENERAL, + DES3_CBC_PAD, + CDMF_KEY_GEN, + CDMF_ECB, + CDMF_CBC, + CDMF_MAC, + CDMF_MAC_GENERAL, + CDMF_CBC_PAD, + DES_OFB64, + DES_OFB8, + DES_CFB64, + DES_CFB8, + MD2, + MD2_HMAC, + MD2_HMAC_GENERAL, + MD5, + MD5_HMAC, + MD5_HMAC_GENERAL, + SHA1, + SHA, + SHA_1, + SHA_1_HMAC, + SHA_1_HMAC_GENERAL, + RIPEMD128, + RIPEMD128_HMAC, + RIPEMD128_HMAC_GENERAL, + RIPEMD160, + RIPEMD160_HMAC, + RIPEMD160_HMAC_GENERAL, + SHA256, + SHA256_HMAC, + SHA256_HMAC_GENERAL, + SHA224, + SHA224_HMAC, + SHA224_HMAC_GENERAL, + SHA384, + SHA384_HMAC, + SHA384_HMAC_GENERAL, + SHA512, + SHA512_HMAC, + SHA512_HMAC_GENERAL, + SECURID_KEY_GEN, + SECURID, + HOTP_KEY_GEN, + HOTP, + ACTI, + ACTI_KEY_GEN, + CAST_KEY_GEN, + CAST_ECB, + CAST_CBC, + CAST_MAC, + CAST_MAC_GENERAL, + CAST_CBC_PAD, + CAST3_KEY_GEN, + CAST3_ECB, + CAST3_CBC, + CAST3_MAC, + CAST3_MAC_GENERAL, + CAST3_CBC_PAD, + CAST5_KEY_GEN, + CAST128_KEY_GEN, + CAST5_ECB, + CAST128_ECB, + CAST5_CBC, + CAST128_CBC, + CAST5_MAC, + CAST128_MAC, + CAST5_MAC_GENERAL, + CAST128_MAC_GENERAL, + CAST5_CBC_PAD, + CAST128_CBC_PAD, + RC5_KEY_GEN, + RC5_ECB, + RC5_CBC, + RC5_MAC, + RC5_MAC_GENERAL, + RC5_CBC_PAD, + IDEA_KEY_GEN, + IDEA_ECB, + IDEA_CBC, + IDEA_MAC, + IDEA_MAC_GENERAL, + IDEA_CBC_PAD, + GENERIC_SECRET_KEY_GEN, + CONCATENATE_BASE_AND_KEY, + CONCATENATE_BASE_AND_DATA, + CONCATENATE_DATA_AND_BASE, + XOR_BASE_AND_DATA, + EXTRACT_KEY_FROM_KEY, + SSL3_PRE_MASTER_KEY_GEN, + SSL3_MASTER_KEY_DERIVE, + SSL3_KEY_AND_MAC_DERIVE, + SSL3_MASTER_KEY_DERIVE_DH, + TLS_PRE_MASTER_KEY_GEN, + TLS_MASTER_KEY_DERIVE, + TLS_KEY_AND_MAC_DERIVE, + TLS_MASTER_KEY_DERIVE_DH, + TLS_PRF, + SSL3_MD5_MAC, + SSL3_SHA1_MAC, + MD5_KEY_DERIVATION, + MD2_KEY_DERIVATION, + SHA1_KEY_DERIVATION, + SHA256_KEY_DERIVATION, + SHA384_KEY_DERIVATION, + SHA512_KEY_DERIVATION, + SHA224_KEY_DERIVATION, + PBE_MD2_DES_CBC, + PBE_MD5_DES_CBC, + PBE_MD5_CAST_CBC, + PBE_MD5_CAST3_CBC, + PBE_MD5_CAST5_CBC, + PBE_MD5_CAST128_CBC, + PBE_SHA1_CAST5_CBC, + PBE_SHA1_CAST128_CBC, + PBE_SHA1_RC4_128, + PBE_SHA1_RC4_40, + PBE_SHA1_DES3_EDE_CBC, + PBE_SHA1_DES2_EDE_CBC, + PBE_SHA1_RC2_128_CBC, + PBE_SHA1_RC2_40_CBC, + PKCS5_PBKD2, + PBA_SHA1_WITH_SHA1_HMAC, + WTLS_PRE_MASTER_KEY_GEN, + WTLS_MASTER_KEY_DERIVE, + WTLS_MASTER_KEY_DERIVE_DH_ECC, + WTLS_PRF, + WTLS_SERVER_KEY_AND_MAC_DERIVE, + WTLS_CLIENT_KEY_AND_MAC_DERIVE, + KEY_WRAP_LYNKS, + KEY_WRAP_SET_OAEP, + CAMELLIA_KEY_GEN, + CAMELLIA_ECB, + CAMELLIA_CBC, + CAMELLIA_MAC, + CAMELLIA_MAC_GENERAL, + CAMELLIA_CBC_PAD, + CAMELLIA_ECB_ENCRYPT_DATA, + CAMELLIA_CBC_ENCRYPT_DATA, + CAMELLIA_CTR, + ARIA_KEY_GEN, + ARIA_ECB, + ARIA_CBC, + ARIA_MAC, + ARIA_MAC_GENERAL, + ARIA_CBC_PAD, + ARIA_ECB_ENCRYPT_DATA, + ARIA_CBC_ENCRYPT_DATA, + SKIPJACK_KEY_GEN, + SKIPJACK_ECB64, + SKIPJACK_CBC64, + SKIPJACK_OFB64, + SKIPJACK_CFB64, + SKIPJACK_CFB32, + SKIPJACK_CFB16, + SKIPJACK_CFB8, + SKIPJACK_WRAP, + SKIPJACK_PRIVATE_WRAP, + SKIPJACK_RELAYX, + KEA_KEY_PAIR_GEN, + KEA_KEY_DERIVE, + FORTEZZA_TIMESTAMP, + BATON_KEY_GEN, + BATON_ECB128, + BATON_ECB96, + BATON_CBC128, + BATON_COUNTER, + BATON_SHUFFLE, + BATON_WRAP, + ECDSA_KEY_PAIR_GEN, + EC_KEY_PAIR_GEN, + ECDSA, + ECDSA_SHA1, + ECDSA_SHA224, + ECDSA_SHA256, + ECDSA_SHA384, + ECDSA_SHA512, + ECDH1_DERIVE, + ECDH1_COFACTOR_DERIVE, + ECMQV_DERIVE, + JUNIPER_KEY_GEN, + JUNIPER_ECB128, + JUNIPER_CBC128, + JUNIPER_COUNTER, + JUNIPER_SHUFFLE, + JUNIPER_WRAP, + FASTHASH, + AES_KEY_GEN, + AES_ECB, + AES_CBC, + AES_MAC, + AES_MAC_GENERAL, + AES_CBC_PAD, + AES_CTR, + AES_CMAC, + AES_CMAC_GENERAL, + BLOWFISH_KEY_GEN, + BLOWFISH_CBC, + TWOFISH_KEY_GEN, + TWOFISH_CBC, + AES_GCM, + AES_CCM, + AES_KEY_WRAP, + AES_KEY_WRAP_PAD, + DES_ECB_ENCRYPT_DATA, + DES_CBC_ENCRYPT_DATA, + DES3_ECB_ENCRYPT_DATA, + DES3_CBC_ENCRYPT_DATA, + AES_ECB_ENCRYPT_DATA, + AES_CBC_ENCRYPT_DATA, + GOSTR3410_KEY_PAIR_GEN, + GOSTR3410, + GOSTR3410_WITH_GOSTR3411, + GOSTR3410_KEY_WRAP, + GOSTR3410_DERIVE, + GOSTR3411, + GOSTR3411_HMAC, + GOST28147_KEY_GEN, + GOST28147_ECB, + GOST28147, + GOST28147_MAC, + GOST28147_KEY_WRAP, + DSA_PARAMETER_GEN, + DH_PKCS_PARAMETER_GEN, + X9_42_DH_PARAMETER_GEN, + VENDOR_DEFINED, + } + + enum MechParams { + AesCBC = 1, + AesCCM = 2, + AesGCM = 3, + RsaOAEP = 4, + RsaPSS = 5, + EcDH = 6, + } + + enum SessionFlag { + /** + * `True` if the session is read/write; `false` if the session is read-only + */ + RW_SESSION, + /** + * This flag is provided for backward compatibility, and should always be set to `true` + */ + SERIAL_SESSION + } + + enum UserType { + /** + * Security Officer + */ + SO, + /** + * User + */ + USER, + /** + * Context specific + */ + CONTEXT_SPECIFIC } enum SlotFlag { @@ -2106,205 +2158,7 @@ declare module "graphene-pk11" { /** * True if the slot is a hardware slot, as opposed to a software slot implementing a "soft token" */ - HW_SLOT, - } - - interface IVersion { - major: number; - minor: number; - } - interface IModuleInfo { - cryptokiVersion: IVersion; - manufacturerID: string; - flags: number; - libraryDescription: string; - libraryVersion: IVersion; - } - - class Collection { - protected items_: Array; - protected classType: any; - protected lib: Pkcs11; - constructor(items: Array, lib: Pkcs11, classType: any); - /** - * returns length of collection - */ - length: number; - /** - * returns item from collection by index - * @param {number} index of element in collection `[0..n]` - */ - items(index: number): T; - } - - enum SessionOpenFlag { - /** - * session is r/w - */ - RW_SESSION, - /** - * no parallel - */ - SERIAL_SESSION, - } - enum SessionFlag { - /** - * `True` if the session is read/write; `false` if the session is read-only - */ - RW_SESSION, - /** - * This flag is provided for backward compatibility, and should always be set to `true` - */ - SERIAL_SESSION, - } - enum UserType { - /** - * Security Officer - */ - SO, - /** - * User - */ - USER, - /** - * Context specific - */ - CONTEXT_SPECIFIC, - } - interface IKeyPair { - privateKey: PrivateKey; - publicKey: PublicKey; - } - /** - * provides information about a session - */ - class Session extends HandleObject { - constructor(handle: number, slot: Slot, lib: Pkcs11); - slot: Slot; - /** - * the state of the session - */ - state: number; - /** - * bit flags that define the type of session - */ - flags: number; - /** - * an error code defined by the cryptographic device. Used for errors not covered by Cryptoki - */ - deviceError: number; - protected getInfo(): void; - /** - * closes a session between an application and a token - */ - close(): void; - /** - * initializes the normal user's PIN - * @param {string} pin the normal user's PIN - */ - initPin(pin: string): void; - /** - * modifies the PIN of the user who is logged in - * @param {string} oldPin - * @param {string} newPin - */ - setPin(oldPin: string, newPin: string): void; - /** - * obtains a copy of the cryptographic operations state of a session, encoded as a string of bytes - */ - getOperationState(): Buffer; - /** - * restores the cryptographic operations state of a session - * from a string of bytes obtained with getOperationState - * @param {Buffer} state the saved state - * @param {number} encryptionKey holds key which will be used for an ongoing encryption - * or decryption operation in the restored session - * (or 0 if no encryption or decryption key is needed, - * either because no such operation is ongoing in the stored session - * or because all the necessary key information is present in the saved state) - * @param {number} authenticationKey holds a handle to the key which will be used for an ongoing signature, - * MACing, or verification operation in the restored session - * (or 0 if no such key is needed, either because no such operation is ongoing in the stored session - * or because all the necessary key information is present in the saved state) - */ - setOperationState(state: Buffer, encryptionKey?: number, authenticationKey?: number): void; - /** - * logs a user into a token - * @param {string} pin the user's PIN. - * - This standard allows PIN values to contain any valid `UTF8` character, - * but the token may impose subset restrictions - * @param {} userType the user type. Default is `USER` - */ - login(pin: string, userType?: UserType): void; - /** - * logs a user out from a token - */ - logout(): void; - /** - * creates a new object - * - Only session objects can be created during a read-only session. - * - Only public objects can be created unless the normal user is logged in. - * @param {ITemplate} template the object's template - */ - create(template: ITemplate): SessionObject; - /** - * removes all session objects matched to template - * - if template is null, removes all session objects - * - returns a number of destroied session objects - * @param {ITemplate} template template - */ - destroy(template: ITemplate): number; - /** - * @param {SessionObject} object - */ - destroy(object: SessionObject): number; - destroy(): number; - /** - * removes all session objects - * - returns a number of destroied session objects - */ - clear(): number; - /** - * returns a collection of session objects mached to template - * @param template template - * @param callback optional callback function wich is called for each founded object - * - if callback function returns false, it breaks find function. - */ - find(callback?: (obj: SessionObject) => void): SessionObjectCollection; - find(template: ITemplate, callback?: (obj: SessionObject) => void): SessionObjectCollection; - /** - * Returns object from session by handle - * @param {number} handle handle of object - * @returns T - */ - getObject(handle: number): T; - /** - * generates a secret key or set of domain parameters, creating a new object. - * @param mechanism generation mechanism - * @param template template for the new key or set of domain parameters - */ - generateKey(mechanism: MechanismType, template?: ITemplate): SecretKey; - generateKey(mechanism: MechanismType, template: ITemplate, callback: (err: Error, key: SecretKey) => void): void; - generateKeyPair(mechanism: MechanismType, publicTemplate: ITemplate, privateTemplate: ITemplate): IKeyPair; - createSign(alg: MechanismType, key: Key): Sign; - createVerify(alg: MechanismType, key: Key): Verify; - createCipher(alg: MechanismType, key: Key): Cipher; - createDecipher(alg: MechanismType, key: Key): Decipher; - createDigest(alg: MechanismType): Digest; - wrapKey(alg: MechanismType, wrappingKey: Key, key: Key): Buffer; - unwrapKey(alg: MechanismType, unwrappingKey: Key, wrappedKey: Buffer, template: ITemplate): Key; - /** - * derives a key from a base key, creating a new key object - * @param {MechanismType} alg key deriv. mech - * @param {Key} baseKey base key - * @param {ITemplate} template new key template - */ - deriveKey(alg: MechanismType, baseKey: Key, template: ITemplate): SecretKey; - /** - * generates random data - * @param {number} size \# of bytes to generate - */ - generateRandom(size: number): Buffer; + HW_SLOT } enum TokenFlag { @@ -2325,139 +2179,25 @@ declare module "graphene-pk11" { SO_PIN_COUNT_LOW, SO_PIN_FINAL_TRY, SO_PIN_LOCKED, - SO_PIN_TO_BE_CHANGED, - } - class Token extends HandleObject { - /** - * application-defined label, assigned during token initialization. - * - Must be padded with the blank character (' '). - * - Should __not__ be null-terminated. - */ - label: string; - /** - * ID of the device manufacturer. - * - Must be padded with the blank character (' '). - * - Should __not__ be null-terminated. - */ - manufacturerID: string; - /** - * model of the device. - * - Must be padded with the blank character (' '). - * - Should __not__ be null-terminated. - */ - model: string; - /** - * character-string serial number of the device. - * - Must be padded with the blank character (' '). - * - Should __not__ be null-terminated. - */ - serialNumber: string; - /** - * bit flags indicating capabilities and status of the device - */ - flags: number; - /** - * maximum number of sessions that can be opened with the token at one time by a single application - */ - maxSessionCount: number; - /** - * number of sessions that this application currently has open with the token - */ - sessionCount: number; - /** - * maximum number of read/write sessions that can be opened - * with the token at one time by a single application - */ - maxRwSessionCount: number; - /** - * number of read/write sessions that this application currently has open with the token - */ - rwSessionCount: number; - /** - * maximum length in bytes of the PIN - */ - maxPinLen: number; - /** - * minimum length in bytes of the PIN - */ - minPinLen: number; - /** - * the total amount of memory on the token in bytes in which public objects may be stored - */ - totalPublicMemory: number; - /** - * the amount of free (unused) memory on the token in bytes for public objects - */ - freePublicMemory: number; - /** - * the total amount of memory on the token in bytes in which private objects may be stored - */ - totalPrivateMemory: number; - /** - * the amount of free (unused) memory on the token in bytes for private objects - */ - freePrivateMemory: number; - /** - * version number of hardware - */ - hardwareVersion: IVersion; - /** - * version number of firmware - */ - firmwareVersion: IVersion; - /** - * current time as a character-string of length 16, - * represented in the format YYYYMMDDhhmmssxx - */ - utcTime: Date; - constructor(handle: number, lib: Pkcs11); - protected getInfo(): void; + SO_PIN_TO_BE_CHANGED } - class Slot extends HandleObject implements ISlotInfo { - slotDescription: string; - manufacturerID: string; - flags: number; - hardwareVersion: IVersion; - firmwareVersion: IVersion; - module: Module; - constructor(handle: number, module: Module, lib: Pkcs11); - protected getInfo(): void; - getToken(): Token; - /** - * returns list of `MechanismInfo` - */ - getMechanisms(): MechanismCollection; - /** - * initializes a token - * @param {string} pin the SO's initial PIN - * @param {string} label label of the token - */ - initToken(pin: string, label: string): void; - /** - * opens a session between an application and a token in a particular slot - * @parsm flags indicates the type of session - */ - open(flags?: number): Session; - /** - * closes all sessions an application has with a token - */ - closeAll(): void; + enum JavaMIDP { + Unspecified, + Manufacturer, + Operator, + ThirdParty } - class SlotCollection extends Collection { - module: Module; - items(index: number): Slot; - constructor(items: Array, module: Module, lib: Pkcs11, classType?: any); - } + // ========== Module ========== - class Module extends BaseObject implements IModuleInfo { + class Module implements graphene.BaseObject { libFile: string; libName: string; /** * Cryptoki interface version */ - cryptokiVersion: IVersion; + cryptokiVersion: pkcs11.Version; /** * blank padded manufacturer ID */ @@ -2473,9 +2213,10 @@ declare module "graphene-pk11" { /** * version of library */ - libraryVersion: IVersion; - constructor(lib: Pkcs11); - protected getInfo(): void; + libraryVersion: pkcs11.Version; + + constructor(lib: pkcs11.PKCS11); + /** * initializes the Cryptoki library */ @@ -2489,231 +2230,17 @@ declare module "graphene-pk11" { * @param {number} index index of an element in collection * @param {number} tokenPresent only slots with tokens. Default `True` */ - getSlots(index: number, tokenPresent?: boolean): Slot; + getSlots(index: number, tokenPresent?: boolean): graphene.Slot; /** * @param {number} tokenPresent only slots with tokens. Default `True` */ - getSlots(tokenPresent?: boolean): SlotCollection; + getSlots(tokenPresent?: boolean): graphene.SlotCollection; /** * loads pkcs11 lib + * @param libFile path to PKCS11 library + * @param libName name of PKCS11 library */ static load(libFile: string, libName?: string): Module; } - class Cipher { - session: Session; - lib: Pkcs11; - constructor(session: Session, alg: MechanismType, key: Key, lib: Pkcs11); - protected init(alg: MechanismType, key: Key): void; - update(text: string): Buffer; - update(data: Buffer): Buffer; - final(): Buffer; - } - - class Decipher { - session: Session; - lib: Pkcs11; - constructor(session: Session, alg: MechanismType, key: Key, lib: Pkcs11); - protected init(alg: MechanismType, key: Key): void; - update(text: string): Buffer; - update(data: Buffer): Buffer; - final(): Buffer; - } - - class Digest { - session: Session; - lib: Pkcs11; - constructor(session: Session, alg: MechanismType, lib: Pkcs11); - protected init(alg: MechanismType): void; - update(text: string): void; - update(data: Buffer): void; - final(): Buffer; - } - - class Sign { - session: Session; - lib: Pkcs11; - constructor(session: Session, alg: MechanismType, key: Key, lib: Pkcs11); - protected init(alg: MechanismType, key: Key): void; - update(text: string): void; - update(data: Buffer): void; - final(): Buffer; - } - - class Verify { - session: Session; - lib: Pkcs11; - constructor(session: Session, alg: MechanismType, key: Key, lib: Pkcs11); - protected init(alg: MechanismType, key: Key): void; - update(text: string): void; - update(data: Buffer): void; - final(signature: Buffer): boolean; - } - - /** - * - * EC - * - */ - - /** - * EcKdf is used to indicate the Key Derivation Function (KDF) - * applied to derive keying data from a shared secret. - * The key derivation function will be used by the EC key agreement schemes. - */ - enum EcKdf { - NULL, - SHA1, - SHA224, - SHA256, - SHA384, - SHA512, - } - - class EcdhParams implements IParams { - /** - * key derivation function used on the shared secret value - */ - kdf: EcKdf; - /** - * some data shared between the two parties - */ - sharedData: Buffer; - /** - * other party's EC public key value - */ - publicData: Buffer; - /** - * @param {EcKdf} kdf key derivation function used on the shared secret value - * @param {Buffer=null} sharedData some data shared between the two parties - * @param {Buffer=null} publicData other party's EC public key value - */ - constructor(kdf: EcKdf, sharedData?: Buffer, publicData?: Buffer); - toCKI(): Buffer; - } - - export interface INamedCurve { - name: string; - oid: string; - value: Buffer; - size: number; - } - - class NamedCurve { - static getByName(name: string): INamedCurve; - static getByOid(oid: string): INamedCurve; - } - - /** - * - * AES - * - */ - - class AesCbcParams implements IParams { - /** - * initialization vector - * - must have a fixed size of 16 bytes - */ - iv: Buffer; - /** - * the data - */ - data: Buffer; - constructor(iv: Buffer, data: Buffer); - toCKI(): Buffer; - } - - class AesCcmParams implements IParams { - /** - * length of the data where 0 <= dataLength < 2^8L - */ - dataLength: number; - /** - * the nonce - */ - nonce: Buffer; - /** - * the additional authentication data - * - This data is authenticated but not encrypted - */ - aad: Buffer; - /** - * length of authentication tag (output following cipher text) in bits. - * - Can be any value between 0 and 128 - */ - macLength: number; - constructor(dataLength: number, nonce: Buffer, aad?: Buffer, macLength?: number); - toCKI(): Buffer; - } - - class AesGcmParams implements IParams { - /** - * initialization vector - * - The length of the initialization vector can be any number between 1 and 256. - * 96-bit (12 byte) IV values can be processed more efficiently, - * so that length is recommended for situations in which efficiency is critical. - */ - iv: Buffer; - /** - * pointer to additional authentication data. - * This data is authenticated but not encrypted. - */ - aad: Buffer; - /** - * length of authentication tag (output following cipher text) in bits. - * Can be any value between 0 and 128. Default 128 - */ - tagBits: number; - constructor(iv: Buffer, aad?: Buffer, tagBits?: number); - toCKI(): Buffer; - } - - /** - * - * RSA - * - */ - - enum RsaMgf { - MGF1_SHA1, - MGF1_SHA224, - MGF1_SHA256, - MGF1_SHA384, - MGF1_SHA512, - } - - class RsaOaepParams implements IParams { - hashAlgorithm: MechanismEnum; - mgf: RsaMgf; - source: number; - sourceData: Buffer; - constructor(hashAlg?: MechanismEnum, mgf?: RsaMgf, sourceData?: Buffer); - toCKI(): Buffer; - } - - class RsaPssParams implements IParams { - /** - * hash algorithm used in the PSS encoding; - * - if the signature mechanism does not include message hashing, - * then this value must be the mechanism used by the application to generate - * the message hash; - * - if the signature mechanism includes hashing, - * then this value must match the hash algorithm indicated - * by the signature mechanism - */ - hashAlgorithm: MechanismEnum; - /** - * mask generation function to use on the encoded block - */ - mgf: RsaMgf; - /** - * length, in bytes, of the salt value used in the PSS encoding; - * - typical values are the length of the message hash and zero - */ - saltLength: number; - constructor(hashAlg?: MechanismEnum, mgf?: RsaMgf, saltLen?: number); - toCKI(): Buffer; - } - } \ No newline at end of file From c66c9bc8537ddae07c7a38c8149ab08ec11be4d9 Mon Sep 17 00:00:00 2001 From: microshine Date: Fri, 12 Aug 2016 00:55:47 +0300 Subject: [PATCH 41/41] Fix error --- graphene-pk11/graphene-pk11.d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/graphene-pk11/graphene-pk11.d.ts b/graphene-pk11/graphene-pk11.d.ts index 2ebec894dd..bc6e178ae6 100644 --- a/graphene-pk11/graphene-pk11.d.ts +++ b/graphene-pk11/graphene-pk11.d.ts @@ -793,7 +793,6 @@ declare module "types/graphene-pk11" { * @extends {HandleObject} */ interface Session extends HandleObject { - constructor(handle: Handle, slot: Slot, lib: pkcs11.PKCS11); /** * Slot *