Skip to content

Commit

Permalink
feat: ID-746 Passport - ZkEvm message signing
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenfowler authored Sep 20, 2023
1 parent 289a865 commit 3c37b9a
Show file tree
Hide file tree
Showing 47 changed files with 2,078 additions and 248 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- @imtbl/orderbook: Added `getTrade` and `listTrades` methods for querying trades
- @imtbl/blockchain-data: Added method `listCollectionsByNFTOwner`
- @imtbl/passport: Added support for `eth_signTypedData_v4` to Passport zkEvm provider.

## [0.16.0] - 2023-08-31

Expand Down
1 change: 1 addition & 0 deletions packages/internal/guardian/src/client/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@



export * from './domain/messages-api';
export * from './domain/starkex-transactions-api';
export * from './domain/transactions-api';

7 changes: 3 additions & 4 deletions packages/internal/guardian/src/client/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
*/


import type { Configuration } from './configuration';
import { Configuration } from "./configuration";
// Some imports not used depending on template conditions
// @ts-ignore
import type { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios';
import globalAxios from 'axios';
import globalAxios, { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios';

export const BASE_PATH = "https://guardian.sandbox.imtbl.com".replace(/\/+$/, "");

Expand Down Expand Up @@ -65,8 +64,8 @@ export class BaseAPI {
* @extends {Error}
*/
export class RequiredError extends Error {
name: "RequiredError" = "RequiredError";
constructor(public field: string, msg?: string) {
super(msg);
this.name = "RequiredError"
}
}
8 changes: 3 additions & 5 deletions packages/internal/guardian/src/client/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
*/


import type { Configuration } from "./configuration";
import type { RequestArgs } from "./base";
import type { AxiosInstance, AxiosResponse } from 'axios';
import { RequiredError } from "./base";
import { Configuration } from "./configuration";
import { RequiredError, RequestArgs } from "./base";
import { AxiosInstance, AxiosResponse } from 'axios';

/**
*
Expand Down Expand Up @@ -85,7 +84,6 @@ export const setOAuthToObject = async function (object: any, name: string, scope
}

function setFlattenedQueryParams(urlSearchParams: URLSearchParams, parameter: any, key: string = ""): void {
if (parameter == null) return;
if (typeof parameter === "object") {
if (Array.isArray(parameter)) {
(parameter as any[]).forEach(item => setFlattenedQueryParams(urlSearchParams, item, key));
Expand Down
331 changes: 331 additions & 0 deletions packages/internal/guardian/src/client/domain/messages-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,331 @@
/* tslint:disable */
/* eslint-disable */
/**
* Guardian
* Guardian API
*
* The version of the OpenAPI document: 1.0.0
* Contact: support@immutable.com
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/


import globalAxios, { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios';
import { Configuration } from '../configuration';
// Some imports not used depending on template conditions
// @ts-ignore
import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObject, setBearerAuthToObject, setOAuthToObject, setSearchParams, serializeDataIfNeeded, toPathString, createRequestFunction } from '../common';
// @ts-ignore
import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } from '../base';
// @ts-ignore
import { APIError400 } from '../models';
// @ts-ignore
import { APIError403 } from '../models';
// @ts-ignore
import { APIError404 } from '../models';
// @ts-ignore
import { APIError500 } from '../models';
// @ts-ignore
import { BasicAPIError } from '../models';
// @ts-ignore
import { EVMMessage } from '../models';
// @ts-ignore
import { MessageEvaluationRequest } from '../models';
// @ts-ignore
import { MessageEvaluationResponse } from '../models';
/**
* MessagesApi - axios parameter creator
* @export
*/
export const MessagesApiAxiosParamCreator = function (configuration?: Configuration) {
return {
/**
* Approve a pending evm message
* @summary Approve a pending evm message
* @param {string} messageID id for the message
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
approvePendingMessage: async (messageID: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'messageID' is not null or undefined
assertParamExists('approvePendingMessage', 'messageID', messageID)
const localVarPath = `/guardian/v1/messages/{messageID}/approve`
.replace(`{${"messageID"}}`, encodeURIComponent(String(messageID)));
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;

// authentication BearerAuth required
// http bearer authentication required
await setBearerAuthToObject(localVarHeaderParameter, configuration)



setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};

return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
/**
* Check if a given message is valid for EVM
* @summary Evaluate an evm message to sign
* @param {MessageEvaluationRequest} messageEvaluationRequest Specifies the kind of transaction
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
evaluateMessage: async (messageEvaluationRequest: MessageEvaluationRequest, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'messageEvaluationRequest' is not null or undefined
assertParamExists('evaluateMessage', 'messageEvaluationRequest', messageEvaluationRequest)
const localVarPath = `/guardian/v1/messages/evaluate`;
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;

// authentication BearerAuth required
// http bearer authentication required
await setBearerAuthToObject(localVarHeaderParameter, configuration)



localVarHeaderParameter['Content-Type'] = 'application/json';

setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
localVarRequestOptions.data = serializeDataIfNeeded(messageEvaluationRequest, localVarRequestOptions, configuration)

return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
/**
* Get an evm message by id
* @summary Info for a specific evm message
* @param {string} messageID The id of the evm message
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getMessageByID: async (messageID: string, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
// verify required parameter 'messageID' is not null or undefined
assertParamExists('getMessageByID', 'messageID', messageID)
const localVarPath = `/guardian/v1/messages/{messageID}`
.replace(`{${"messageID"}}`, encodeURIComponent(String(messageID)));
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;

// authentication BearerAuth required
// http bearer authentication required
await setBearerAuthToObject(localVarHeaderParameter, configuration)



setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};

return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
}
};

/**
* MessagesApi - functional programming interface
* @export
*/
export const MessagesApiFp = function(configuration?: Configuration) {
const localVarAxiosParamCreator = MessagesApiAxiosParamCreator(configuration)
return {
/**
* Approve a pending evm message
* @summary Approve a pending evm message
* @param {string} messageID id for the message
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async approvePendingMessage(messageID: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.approvePendingMessage(messageID, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
* Check if a given message is valid for EVM
* @summary Evaluate an evm message to sign
* @param {MessageEvaluationRequest} messageEvaluationRequest Specifies the kind of transaction
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async evaluateMessage(messageEvaluationRequest: MessageEvaluationRequest, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<MessageEvaluationResponse>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.evaluateMessage(messageEvaluationRequest, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
/**
* Get an evm message by id
* @summary Info for a specific evm message
* @param {string} messageID The id of the evm message
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async getMessageByID(messageID: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<EVMMessage>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.getMessageByID(messageID, options);
return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration);
},
}
};

/**
* MessagesApi - factory interface
* @export
*/
export const MessagesApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
const localVarFp = MessagesApiFp(configuration)
return {
/**
* Approve a pending evm message
* @summary Approve a pending evm message
* @param {string} messageID id for the message
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
approvePendingMessage(messageID: string, options?: any): AxiosPromise<void> {
return localVarFp.approvePendingMessage(messageID, options).then((request) => request(axios, basePath));
},
/**
* Check if a given message is valid for EVM
* @summary Evaluate an evm message to sign
* @param {MessageEvaluationRequest} messageEvaluationRequest Specifies the kind of transaction
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
evaluateMessage(messageEvaluationRequest: MessageEvaluationRequest, options?: any): AxiosPromise<MessageEvaluationResponse> {
return localVarFp.evaluateMessage(messageEvaluationRequest, options).then((request) => request(axios, basePath));
},
/**
* Get an evm message by id
* @summary Info for a specific evm message
* @param {string} messageID The id of the evm message
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
getMessageByID(messageID: string, options?: any): AxiosPromise<EVMMessage> {
return localVarFp.getMessageByID(messageID, options).then((request) => request(axios, basePath));
},
};
};

/**
* Request parameters for approvePendingMessage operation in MessagesApi.
* @export
* @interface MessagesApiApprovePendingMessageRequest
*/
export interface MessagesApiApprovePendingMessageRequest {
/**
* id for the message
* @type {string}
* @memberof MessagesApiApprovePendingMessage
*/
readonly messageID: string
}

/**
* Request parameters for evaluateMessage operation in MessagesApi.
* @export
* @interface MessagesApiEvaluateMessageRequest
*/
export interface MessagesApiEvaluateMessageRequest {
/**
* Specifies the kind of transaction
* @type {MessageEvaluationRequest}
* @memberof MessagesApiEvaluateMessage
*/
readonly messageEvaluationRequest: MessageEvaluationRequest
}

/**
* Request parameters for getMessageByID operation in MessagesApi.
* @export
* @interface MessagesApiGetMessageByIDRequest
*/
export interface MessagesApiGetMessageByIDRequest {
/**
* The id of the evm message
* @type {string}
* @memberof MessagesApiGetMessageByID
*/
readonly messageID: string
}

/**
* MessagesApi - object-oriented interface
* @export
* @class MessagesApi
* @extends {BaseAPI}
*/
export class MessagesApi extends BaseAPI {
/**
* Approve a pending evm message
* @summary Approve a pending evm message
* @param {MessagesApiApprovePendingMessageRequest} requestParameters Request parameters.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof MessagesApi
*/
public approvePendingMessage(requestParameters: MessagesApiApprovePendingMessageRequest, options?: AxiosRequestConfig) {
return MessagesApiFp(this.configuration).approvePendingMessage(requestParameters.messageID, options).then((request) => request(this.axios, this.basePath));
}

/**
* Check if a given message is valid for EVM
* @summary Evaluate an evm message to sign
* @param {MessagesApiEvaluateMessageRequest} requestParameters Request parameters.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof MessagesApi
*/
public evaluateMessage(requestParameters: MessagesApiEvaluateMessageRequest, options?: AxiosRequestConfig) {
return MessagesApiFp(this.configuration).evaluateMessage(requestParameters.messageEvaluationRequest, options).then((request) => request(this.axios, this.basePath));
}

/**
* Get an evm message by id
* @summary Info for a specific evm message
* @param {MessagesApiGetMessageByIDRequest} requestParameters Request parameters.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof MessagesApi
*/
public getMessageByID(requestParameters: MessagesApiGetMessageByIDRequest, options?: AxiosRequestConfig) {
return MessagesApiFp(this.configuration).getMessageByID(requestParameters.messageID, options).then((request) => request(this.axios, this.basePath));
}
}
Loading

0 comments on commit 3c37b9a

Please sign in to comment.