Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@0xpass/passport

Package Overview
Dependencies
Maintainers
3
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@0xpass/passport - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

13

dist/index.d.ts

@@ -1,2 +0,2 @@

import { GetSessionParams, GetSessionResponse, Method, RpcMethodParams, SendOtpParams, SendOtpResponse, SignParams, SignResponse } from "./types";
import { GetSessionParams, GetSessionResponse, Method, RpcMethodParams, SendOtpParams, SendOtpResponse, SignMessageParams, SignMessageResponse, SignTransactionParams, SignTransactionResponse } from "./types";
/**

@@ -39,3 +39,3 @@ * Passport class for interacting with a Passport node.

/**
* Gets a session from a Passport node.
* Signs a message.
* @param {object} params.session - The session object returned from getSession

@@ -45,4 +45,11 @@ * @param {string} params.message - The message to sign

*/
sign: (params: SignParams) => Promise<SignResponse>;
signMessage: (params: SignMessageParams) => Promise<SignMessageResponse>;
/**
* Signs a transaction.
* @param {object} params.session - The session object returned from getSession
* @param {object} params.transaction - The transaction to sign
* @returns A Promise that resolves to return a signature
*/
signTransaction: (params: SignTransactionParams) => Promise<SignTransactionResponse>;
/**
* Sends an OTP using a Passport node.

@@ -49,0 +56,0 @@ * @param params.scope_id - The ID of the scope you'd like to use

@@ -61,3 +61,3 @@ import axios from 'axios';

/**
* Gets a session from a Passport node.
* Signs a message.
* @param {object} params.session - The session object returned from getSession

@@ -67,6 +67,64 @@ * @param {string} params.message - The message to sign

*/
this.sign = async (params) => {
return await this.call("sign", params);
this.signMessage = async (params) => {
const payload = {
jsonrpc: "2.0",
id: 1,
method: "personal_sign",
// change this to address although for now it's fine
params: [params.session.message.public_key, params.message],
};
try {
const { data } = await axios.post(this.endpoint, payload, {
headers: {
session: JSON.stringify(params.session),
secure_context: "1",
},
});
return data;
}
catch (error) {
if (axios.isAxiosError(error)) {
if (error.response) {
throw new Error(`Server error: ${error.response.status}`);
}
}
else {
throw new Error("Unexpected error: " + error);
}
}
};
/**
* Signs a transaction.
* @param {object} params.session - The session object returned from getSession
* @param {object} params.transaction - The transaction to sign
* @returns A Promise that resolves to return a signature
*/
this.signTransaction = async (params) => {
const payload = {
jsonrpc: "2.0",
id: 1,
method: "eth_signTransaction",
params: [{ ...params.transaction }],
};
try {
const { data } = await axios.post(this.endpoint, payload, {
headers: {
session: JSON.stringify(params.session),
secure_context: "1",
},
});
return data;
}
catch (error) {
if (axios.isAxiosError(error)) {
if (error.response) {
throw new Error(`Server error: ${error.response.status}`);
}
}
else {
throw new Error("Unexpected error: " + error);
}
}
};
/**
* Sends an OTP using a Passport node.

@@ -73,0 +131,0 @@ * @param params.scope_id - The ID of the scope you'd like to use

@@ -1,2 +0,2 @@

export type Method = "getSession" | "sign" | "verify" | "exchangeKey" | "auth" | "sendOtp" | "authInOne";
export type Method = "getSession" | "personal_sign" | "eth_signTransaction" | "verify" | "exchangeKey" | "auth" | "sendOtp" | "authInOne";
export type GetSessionParams = {

@@ -19,11 +19,16 @@ scope_id: string;

};
export type SignParams = {
export type SignMessageParams = {
session: Session;
message: string;
};
export type SignResponse = {
result: {
signature: string;
};
export type SignMessageResponse = {
result: string;
};
export type SignTransactionParams = {
session: Session;
transaction: any;
};
export type SignTransactionResponse = {
result: string;
};
export type VerifyParams = {

@@ -73,5 +78,5 @@ scope_id: string;

};
export type RpcMethodParams = GetSessionParams | VerifyParams | ExchangeKeyParams | AuthParams | AuthInOneParams | SendOtpParams | SignParams;
export type RpcMethodResponse = VerifyResponse | ExchangeKeyResponse | AuthResponse | AuthInOneResponse | SendOtpResponse;
export type RpcMethodParams = GetSessionParams | VerifyParams | ExchangeKeyParams | AuthParams | AuthInOneParams | SendOtpParams | SignMessageParams | SignTransactionParams;
export type RpcMethodResponse = VerifyResponse | ExchangeKeyResponse | AuthResponse | AuthInOneResponse | SendOtpResponse | GetSessionResponse | SignMessageResponse | SignTransactionResponse;
export {};
//# sourceMappingURL=types.d.ts.map
{
"name": "@0xpass/passport",
"version": "0.0.5",
"version": "0.0.6",
"description": "",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -9,6 +9,7 @@ import axios from "axios";

SendOtpResponse,
SignParams,
SignResponse,
SignMessageParams,
SignMessageResponse,
SignTransactionParams,
SignTransactionResponse,
} from "./types";
import { generateKeyPair } from "./crypto";

@@ -119,3 +120,3 @@ /**

/**
* Gets a session from a Passport node.
* Signs a message.
* @param {object} params.session - The session object returned from getSession

@@ -125,7 +126,68 @@ * @param {string} params.message - The message to sign

*/
public sign = async (params: SignParams): Promise<SignResponse> => {
return await this.call("sign", params);
public signMessage = async (
params: SignMessageParams
): Promise<SignMessageResponse> => {
const payload = {
jsonrpc: "2.0",
id: 1,
method: "personal_sign",
// change this to address although for now it's fine
params: [params.session.message.public_key, params.message],
};
try {
const { data } = await axios.post(this.endpoint, payload, {
headers: {
session: JSON.stringify(params.session),
secure_context: "1",
},
});
return data;
} catch (error) {
if (axios.isAxiosError(error)) {
if (error.response) {
throw new Error(`Server error: ${error.response.status}`);
}
} else {
throw new Error("Unexpected error: " + error);
}
}
};
/**
* Signs a transaction.
* @param {object} params.session - The session object returned from getSession
* @param {object} params.transaction - The transaction to sign
* @returns A Promise that resolves to return a signature
*/
public signTransaction = async (
params: SignTransactionParams
): Promise<SignTransactionResponse> => {
const payload = {
jsonrpc: "2.0",
id: 1,
method: "eth_signTransaction",
params: [{ ...params.transaction }],
};
try {
const { data } = await axios.post(this.endpoint, payload, {
headers: {
session: JSON.stringify(params.session),
secure_context: "1",
},
});
return data;
} catch (error) {
if (axios.isAxiosError(error)) {
if (error.response) {
throw new Error(`Server error: ${error.response.status}`);
}
} else {
throw new Error("Unexpected error: " + error);
}
}
};
/**
* Sends an OTP using a Passport node.

@@ -132,0 +194,0 @@ * @param params.scope_id - The ID of the scope you'd like to use

export type Method =
| "getSession"
| "sign"
| "personal_sign"
| "eth_signTransaction"
| "verify"

@@ -30,3 +31,3 @@ | "exchangeKey"

export type SignParams = {
export type SignMessageParams = {
session: Session;

@@ -36,8 +37,15 @@ message: string;

export type SignResponse = {
result: {
signature: string;
};
export type SignMessageResponse = {
result: string;
};
export type SignTransactionParams = {
session: Session;
transaction: any; // todo
};
export type SignTransactionResponse = {
result: string;
};
export type VerifyParams = {

@@ -106,3 +114,4 @@ scope_id: string;

| SendOtpParams
| SignParams;
| SignMessageParams
| SignTransactionParams;

@@ -114,2 +123,5 @@ export type RpcMethodResponse =

| AuthInOneResponse
| SendOtpResponse;
| SendOtpResponse
| GetSessionResponse
| SignMessageResponse
| SignTransactionResponse;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc