New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@0xsequence/waas

Package Overview
Dependencies
Maintainers
6
Versions
160
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@0xsequence/waas - npm Package Compare versions

Comparing version 0.0.0-20231108174744 to 0.0.0-20231113164400

38

dist/0xsequence-waas.cjs.dev.js

@@ -66,2 +66,11 @@ 'use strict';

}
function finishValidateSession(wallet, session, salt, challenge, lifespan) {
return _extends({}, useLifespan(lifespan), {
wallet: wallet,
session: session,
code: 'finishValidateSession',
salt: salt,
challenge: challenge
});
}
async function getSession(args) {

@@ -78,2 +87,3 @@ return _extends({}, useLifespan(args.lifespan), args, {

validateSession: validateSession,
finishValidateSession: finishValidateSession,
getSession: getSession

@@ -874,2 +884,8 @@ });

}
async finishValidateSession(salt, challenge) {
const session = await this.getSignerAddress();
const wallet = await this.getWalletAddress();
const packet = finishValidateSession(wallet, session, salt, challenge, DEFAULT_LIFESPAN);
return this.buildPayload(packet);
}
async isSessionValid() {

@@ -1191,3 +1207,3 @@ const sessionAddress = await this.getSignerAddress();

function encodeHex(data) {
return "0x" + Array.from(typeof data === 'string' ? new TextEncoder().encode(data) : data, byte => byte.toString(16).padStart(2, '0')).join("");
return '0x' + Array.from(typeof data === 'string' ? new TextEncoder().encode(data) : data, byte => byte.toString(16).padStart(2, '0')).join('');
}

@@ -1254,2 +1270,7 @@ function decodeHex(hex) {

var _await$this$deviceNam;
const intent = await this.waas.validateSession({
redirectURL,
deviceMetadata: (_await$this$deviceNam = await this.deviceName.get()) != null ? _await$this$deviceNam : 'Unknown device'
});
const sendIntent = await this.sendIntent(intent);
const proceed = onValidationRequired ? onValidationRequired() : true;

@@ -1260,9 +1281,4 @@ if (!proceed) {

for (const callback of this.validationRequiredCallback) {
callback();
callback(sendIntent.data.salt);
}
const intent = await this.waas.validateSession({
redirectURL,
deviceMetadata: (_await$this$deviceNam = await this.deviceName.get()) != null ? _await$this$deviceNam : 'Unknown device'
});
await this.sendIntent(intent);
return this.waitForSessionValid();

@@ -1287,3 +1303,3 @@ }

if (!dataKeyRes.CiphertextBlob || !dataKeyRes.Plaintext) {
throw new Error("invalid response from KMS");
throw new Error('invalid response from KMS');
}

@@ -1315,3 +1331,3 @@ return this.kmsKey.set(JSON.stringify({

};
const key = await window.crypto.subtle.importKey("raw", decodeHex(plainHex), cbcParams, false, ['encrypt']);
const key = await window.crypto.subtle.importKey('raw', decodeHex(plainHex), cbcParams, false, ['encrypt']);
const payloadBytes = new TextEncoder().encode(JSON.stringify(payload));

@@ -1448,2 +1464,6 @@ const encrypted = await window.crypto.subtle.encrypt(cbcParams, key, payloadBytes);

}
async finishValidateSession(salt, challenge) {
const intent = await this.waas.finishValidateSession(salt, challenge);
return this.sendIntent(intent);
}
async isSessionValid() {

@@ -1450,0 +1470,0 @@ const payload = await this.waas.getSession();

@@ -66,2 +66,11 @@ 'use strict';

}
function finishValidateSession(wallet, session, salt, challenge, lifespan) {
return _extends({}, useLifespan(lifespan), {
wallet: wallet,
session: session,
code: 'finishValidateSession',
salt: salt,
challenge: challenge
});
}
async function getSession(args) {

@@ -78,2 +87,3 @@ return _extends({}, useLifespan(args.lifespan), args, {

validateSession: validateSession,
finishValidateSession: finishValidateSession,
getSession: getSession

@@ -874,2 +884,8 @@ });

}
async finishValidateSession(salt, challenge) {
const session = await this.getSignerAddress();
const wallet = await this.getWalletAddress();
const packet = finishValidateSession(wallet, session, salt, challenge, DEFAULT_LIFESPAN);
return this.buildPayload(packet);
}
async isSessionValid() {

@@ -1191,3 +1207,3 @@ const sessionAddress = await this.getSignerAddress();

function encodeHex(data) {
return "0x" + Array.from(typeof data === 'string' ? new TextEncoder().encode(data) : data, byte => byte.toString(16).padStart(2, '0')).join("");
return '0x' + Array.from(typeof data === 'string' ? new TextEncoder().encode(data) : data, byte => byte.toString(16).padStart(2, '0')).join('');
}

@@ -1254,2 +1270,7 @@ function decodeHex(hex) {

var _await$this$deviceNam;
const intent = await this.waas.validateSession({
redirectURL,
deviceMetadata: (_await$this$deviceNam = await this.deviceName.get()) != null ? _await$this$deviceNam : 'Unknown device'
});
const sendIntent = await this.sendIntent(intent);
const proceed = onValidationRequired ? onValidationRequired() : true;

@@ -1260,9 +1281,4 @@ if (!proceed) {

for (const callback of this.validationRequiredCallback) {
callback();
callback(sendIntent.data.salt);
}
const intent = await this.waas.validateSession({
redirectURL,
deviceMetadata: (_await$this$deviceNam = await this.deviceName.get()) != null ? _await$this$deviceNam : 'Unknown device'
});
await this.sendIntent(intent);
return this.waitForSessionValid();

@@ -1287,3 +1303,3 @@ }

if (!dataKeyRes.CiphertextBlob || !dataKeyRes.Plaintext) {
throw new Error("invalid response from KMS");
throw new Error('invalid response from KMS');
}

@@ -1315,3 +1331,3 @@ return this.kmsKey.set(JSON.stringify({

};
const key = await window.crypto.subtle.importKey("raw", decodeHex(plainHex), cbcParams, false, ['encrypt']);
const key = await window.crypto.subtle.importKey('raw', decodeHex(plainHex), cbcParams, false, ['encrypt']);
const payloadBytes = new TextEncoder().encode(JSON.stringify(payload));

@@ -1448,2 +1464,6 @@ const encrypted = await window.crypto.subtle.encrypt(cbcParams, key, payloadBytes);

}
async finishValidateSession(salt, challenge) {
const intent = await this.waas.finishValidateSession(salt, challenge);
return this.sendIntent(intent);
}
async isSessionValid() {

@@ -1450,0 +1470,0 @@ const payload = await this.waas.getSession();

@@ -62,2 +62,11 @@ import { ethers } from 'ethers';

}
function finishValidateSession(wallet, session, salt, challenge, lifespan) {
return _extends({}, useLifespan(lifespan), {
wallet: wallet,
session: session,
code: 'finishValidateSession',
salt: salt,
challenge: challenge
});
}
async function getSession(args) {

@@ -74,2 +83,3 @@ return _extends({}, useLifespan(args.lifespan), args, {

validateSession: validateSession,
finishValidateSession: finishValidateSession,
getSession: getSession

@@ -870,2 +880,8 @@ });

}
async finishValidateSession(salt, challenge) {
const session = await this.getSignerAddress();
const wallet = await this.getWalletAddress();
const packet = finishValidateSession(wallet, session, salt, challenge, DEFAULT_LIFESPAN);
return this.buildPayload(packet);
}
async isSessionValid() {

@@ -1187,3 +1203,3 @@ const sessionAddress = await this.getSignerAddress();

function encodeHex(data) {
return "0x" + Array.from(typeof data === 'string' ? new TextEncoder().encode(data) : data, byte => byte.toString(16).padStart(2, '0')).join("");
return '0x' + Array.from(typeof data === 'string' ? new TextEncoder().encode(data) : data, byte => byte.toString(16).padStart(2, '0')).join('');
}

@@ -1250,2 +1266,7 @@ function decodeHex(hex) {

var _await$this$deviceNam;
const intent = await this.waas.validateSession({
redirectURL,
deviceMetadata: (_await$this$deviceNam = await this.deviceName.get()) != null ? _await$this$deviceNam : 'Unknown device'
});
const sendIntent = await this.sendIntent(intent);
const proceed = onValidationRequired ? onValidationRequired() : true;

@@ -1256,9 +1277,4 @@ if (!proceed) {

for (const callback of this.validationRequiredCallback) {
callback();
callback(sendIntent.data.salt);
}
const intent = await this.waas.validateSession({
redirectURL,
deviceMetadata: (_await$this$deviceNam = await this.deviceName.get()) != null ? _await$this$deviceNam : 'Unknown device'
});
await this.sendIntent(intent);
return this.waitForSessionValid();

@@ -1283,3 +1299,3 @@ }

if (!dataKeyRes.CiphertextBlob || !dataKeyRes.Plaintext) {
throw new Error("invalid response from KMS");
throw new Error('invalid response from KMS');
}

@@ -1311,3 +1327,3 @@ return this.kmsKey.set(JSON.stringify({

};
const key = await window.crypto.subtle.importKey("raw", decodeHex(plainHex), cbcParams, false, ['encrypt']);
const key = await window.crypto.subtle.importKey('raw', decodeHex(plainHex), cbcParams, false, ['encrypt']);
const payloadBytes = new TextEncoder().encode(JSON.stringify(payload));

@@ -1444,2 +1460,6 @@ const encrypted = await window.crypto.subtle.encrypt(cbcParams, key, payloadBytes);

}
async finishValidateSession(salt, challenge) {
const intent = await this.waas.finishValidateSession(salt, challenge);
return this.sendIntent(intent);
}
async isSessionValid() {

@@ -1446,0 +1466,0 @@ const payload = await this.waas.getSession();

import { Store } from "./store.js";
import { MaySentTransactionResponse, SignedMessageResponse } from "./payloads/responses.js";
import { Session } from "./clients/authenticator.gen.js";
import { Session, SendIntentReturn } from "./clients/authenticator.gen.js";
import { SendDelayedEncodeArgs, SendERC1155Args, SendERC20Args, SendERC721Args, SendTransactionsArgs } from "./payloads/packets/transactions.js";

@@ -55,3 +55,3 @@ import { SignMessageArgs } from "./payloads/packets/messages.js";

get email(): EmailAuth;
onValidationRequired(callback: () => void): Promise<() => void>;
onValidationRequired(callback: (salt: string) => void): Promise<() => void>;
private handleValidationRequired;

@@ -73,2 +73,3 @@ private useStoredCypherKey;

validateSession(args?: ValidationArgs): Promise<boolean>;
finishValidateSession(salt: string, challenge: string): Promise<SendIntentReturn>;
isSessionValid(): Promise<boolean>;

@@ -75,0 +76,0 @@ waitForSessionValid(timeout?: number, pollRate?: number): Promise<boolean>;

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

import { GetSessionPacket, OpenSessionPacket, SessionPacketProof, ValidateSessionPacket } from "./payloads/packets/session.js";
import { GetSessionPacket, OpenSessionPacket, SessionPacketProof, ValidateSessionPacket, FinishValidateSessionPacket } from "./payloads/packets/session.js";
import { Store } from "./store.js";

@@ -120,2 +120,3 @@ import { Payload } from "./payloads/index.js";

getSession(): Promise<Payload<GetSessionPacket>>;
finishValidateSession(salt: string, challenge: string): Promise<Payload<FinishValidateSessionPacket>>;
isSessionValid(): Promise<boolean>;

@@ -122,0 +123,0 @@ waitForSessionValid(timeout?: number, pollRate?: number): Promise<boolean>;

@@ -18,2 +18,8 @@ import { ethers } from 'ethers';

};
export type FinishValidateSessionPacket = BasePacketForWallet & {
code: 'finishValidateSession';
session: string;
salt: string;
challenge: string;
};
export type GetSessionPacket = BasePacketForWallet & {

@@ -47,2 +53,3 @@ code: 'getSession';

}): Promise<ValidateSessionPacket>;
export declare function finishValidateSession(wallet: string, session: string, salt: string, challenge: string, lifespan: number): FinishValidateSessionPacket;
export declare function getSession(args: {

@@ -49,0 +56,0 @@ wallet: string;

{
"name": "@0xsequence/waas",
"version": "0.0.0-20231108174744",
"version": "0.0.0-20231113164400",
"description": "waas session client",

@@ -5,0 +5,0 @@ "repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/waas",

import { fromCognitoIdentityPool } from '@aws-sdk/credential-providers'
import { SequenceWaaSBase } from "./base"
import { LocalStore, Store, StoreObj } from "./store"
import { Payload } from "./payloads";
import { MaySentTransactionResponse, SignedMessageResponse, isGetSessionResponse, isMaySentTransactionResponse, isSignedMessageResponse, isValidationRequiredResponse } from "./payloads/responses";
import { WaasAuthenticator, Session, RegisterSessionPayload, SendIntentPayload, ListSessionsPayload, DropSessionPayload } from "./clients/authenticator.gen";
import { jwtDecode } from "jwt-decode"
import { SequenceWaaSBase } from './base'
import { LocalStore, Store, StoreObj } from './store'
import { Payload } from './payloads'
import {
MaySentTransactionResponse,
SignedMessageResponse,
isGetSessionResponse,
isMaySentTransactionResponse,
isSignedMessageResponse,
isValidationRequiredResponse
} from './payloads/responses'
import {
WaasAuthenticator,
Session,
RegisterSessionPayload,
SendIntentPayload,
ListSessionsPayload,
DropSessionPayload,
SendIntentReturn
} from './clients/authenticator.gen'
import { jwtDecode } from 'jwt-decode'
import { GenerateDataKeyCommand, KMSClient } from '@aws-sdk/client-kms'
import { SendDelayedEncodeArgs, SendERC1155Args, SendERC20Args, SendERC721Args, SendTransactionsArgs } from './payloads/packets/transactions';
import { SignMessageArgs } from './payloads/packets/messages';
import { SimpleNetwork, WithSimpleNetwork } from './networks';
import { TEMPLATE_LOCAL } from './defaults';
import { EmailAuth } from './email';
import {
SendDelayedEncodeArgs,
SendERC1155Args,
SendERC20Args,
SendERC721Args,
SendTransactionsArgs
} from './payloads/packets/transactions'
import { SignMessageArgs } from './payloads/packets/messages'
import { SimpleNetwork, WithSimpleNetwork } from './networks'
import { TEMPLATE_LOCAL } from './defaults'
import { EmailAuth } from './email'

@@ -18,24 +39,24 @@ export type Sessions = (Session & { isThis: boolean })[]

export type SequenceExplicitConfig = {
secret: string,
tenant: number,
secret: string
tenant: number
emailClientId?: string,
identityPoolId: string,
emailClientId?: string
identityPoolId: string
}
export type SequenceKeyConfig = {
key: string,
key: string
}
export type SequenceConfig = (SequenceExplicitConfig | SequenceKeyConfig) & {
network?: SimpleNetwork,
network?: SimpleNetwork
}
export type ExtendedSequenceConfig = {
rpcServer: string;
kmsRegion: string;
idpRegion: string;
keyId: string;
emailRegion?: string;
endpoint?: string;
rpcServer: string
kmsRegion: string
idpRegion: string
keyId: string
emailRegion?: string
endpoint?: string
}

@@ -48,10 +69,17 @@

function encodeHex(data: string | Uint8Array) {
return "0x" + Array.from(
typeof(data) === 'string' ? new TextEncoder().encode(data) : data,
byte => byte.toString(16).padStart(2, '0'),
).join("")
return (
'0x' +
Array.from(typeof data === 'string' ? new TextEncoder().encode(data) : data, byte => byte.toString(16).padStart(2, '0')).join(
''
)
)
}
function decodeHex(hex: string) {
return new Uint8Array(hex.substring(2).match(/.{1,2}/g)!.map(byte => parseInt(byte, 16)))
return new Uint8Array(
hex
.substring(2)
.match(/.{1,2}/g)!
.map(byte => parseInt(byte, 16))
)
}

@@ -65,4 +93,4 @@

export type CommonAuthArgs = {
validation?: ValidationArgs,
identifier?: string,
validation?: ValidationArgs
identifier?: string
}

@@ -105,3 +133,3 @@

private validationRequiredCallback: (() => void)[] = []
private validationRequiredCallback: ((salt: string) => void)[] = []

@@ -115,3 +143,3 @@ public readonly config: Required<SequenceExplicitConfig> & ExtendedSequenceConfig

constructor (
constructor(
config: SequenceConfig & Partial<ExtendedSequenceConfig>,

@@ -145,3 +173,3 @@ preset: ExtendedSequenceConfig = TEMPLATE_LOCAL,

async onValidationRequired(callback: () => void) {
async onValidationRequired(callback: (salt: string) => void) {
this.validationRequiredCallback.push(callback)

@@ -153,6 +181,10 @@ return () => {

private async handleValidationRequired({
onValidationRequired,
redirectURL,
}: ValidationArgs = {}): Promise<boolean> {
private async handleValidationRequired({ onValidationRequired, redirectURL }: ValidationArgs = {}): Promise<boolean> {
const intent = await this.waas.validateSession({
redirectURL,
deviceMetadata: (await this.deviceName.get()) ?? 'Unknown device'
})
const sendIntent = await this.sendIntent(intent)
const proceed = onValidationRequired ? onValidationRequired() : true

@@ -164,16 +196,9 @@ if (!proceed) {

for (const callback of this.validationRequiredCallback) {
callback()
callback(sendIntent.data.salt)
}
const intent = await this.waas.validateSession({
redirectURL,
deviceMetadata: await this.deviceName.get() ?? 'Unknown device',
})
await this.sendIntent(intent)
return this.waitForSessionValid()
}
private async useStoredCypherKey(): Promise<{ encryptedPayloadKey: string, plainHex: string }> {
private async useStoredCypherKey(): Promise<{ encryptedPayloadKey: string; plainHex: string }> {
const raw = await this.kmsKey.get()

@@ -193,16 +218,19 @@ if (!raw) {

private async saveCypherKey(kmsClient: KMSClient) {
const dataKeyRes = await kmsClient.send(new GenerateDataKeyCommand({
KeyId: this.config.keyId,
KeySpec: 'AES_256',
}))
const dataKeyRes = await kmsClient.send(
new GenerateDataKeyCommand({
KeyId: this.config.keyId,
KeySpec: 'AES_256'
})
)
if (!dataKeyRes.CiphertextBlob || !dataKeyRes.Plaintext) {
throw new Error("invalid response from KMS")
throw new Error('invalid response from KMS')
}
return this.kmsKey.set(JSON.stringify({
encryptedPayloadKey: encodeHex(dataKeyRes.CiphertextBlob),
plainHex: encodeHex(dataKeyRes.Plaintext),
}))
return this.kmsKey.set(
JSON.stringify({
encryptedPayloadKey: encodeHex(dataKeyRes.CiphertextBlob),
plainHex: encodeHex(dataKeyRes.Plaintext)
})
)
}

@@ -213,6 +241,7 @@

sessionId: await this.waas.getSessionID(),
intentJson: JSON.stringify(intent, null, 0),
intentJson: JSON.stringify(intent, null, 0)
}
const { args, headers } = await this.preparePayload(payload)
return this.client.sendIntent(args, headers)

@@ -229,14 +258,14 @@ }

const key = await window.crypto.subtle.importKey("raw", decodeHex(plainHex), cbcParams, false, ['encrypt'])
const key = await window.crypto.subtle.importKey('raw', decodeHex(plainHex), cbcParams, false, ['encrypt'])
const payloadBytes = new TextEncoder().encode(JSON.stringify(payload))
const encrypted = await window.crypto.subtle.encrypt(cbcParams, key, payloadBytes)
const payloadCiphertext = encodeHex(new Uint8Array([ ...cbcParams.iv, ...new Uint8Array(encrypted) ]))
const payloadCiphertext = encodeHex(new Uint8Array([...cbcParams.iv, ...new Uint8Array(encrypted)]))
const payloadSig = await this.waas.signUsingSessionKey(payloadBytes)
return {
headers: {
'X-Sequence-Tenant': this.config.tenant,
'X-Sequence-Tenant': this.config.tenant
// 'X-Sequence-Secret': this.config.secret,
},
args: { encryptedPayloadKey, payloadCiphertext, payloadSig },
args: { encryptedPayloadKey, payloadCiphertext, payloadSig }
}

@@ -269,9 +298,6 @@ }

logins: {
[decoded.iss
.replace('https://', '')
.replace('http://', '')
]: creds.idToken,
[decoded.iss.replace('https://', '').replace('http://', '')]: creds.idToken
},
clientConfig: { region: this.config.idpRegion },
}),
clientConfig: { region: this.config.idpRegion }
})
})

@@ -286,3 +312,3 @@

friendlyName: name,
intentJSON: JSON.stringify(waaspayload, null, 0),
intentJSON: JSON.stringify(waaspayload, null, 0)
}

@@ -313,3 +339,3 @@

async dropSession({ sessionId, strict }: { sessionId?: string, strict?: boolean } = {}) {
async dropSession({ sessionId, strict }: { sessionId?: string; strict?: boolean } = {}) {
const thisSessionId = await this.waas.getSessionID()

@@ -325,3 +351,3 @@ const closeSessionId = sessionId || thisSessionId

dropSessionId: closeSessionId,
sessionId: thisSessionId,
sessionId: thisSessionId
}

@@ -348,3 +374,3 @@

const payload: ListSessionsPayload = {
sessionId: await this.waas.getSessionID(),
sessionId: await this.waas.getSessionID()
}

@@ -357,3 +383,3 @@

...session,
isThis: session.address.toLowerCase() === thisSessionAddress,
isThis: session.address.toLowerCase() === thisSessionAddress
}))

@@ -375,2 +401,7 @@ }

async finishValidateSession(salt: string, challenge: string): Promise<SendIntentReturn> {
const intent = await this.waas.finishValidateSession(salt, challenge)
return this.sendIntent(intent)
}
async isSessionValid(): Promise<boolean> {

@@ -377,0 +408,0 @@ const payload = await this.waas.getSession()

@@ -1,11 +0,35 @@

import { ethers } from "ethers"
import { GetSessionPacket, OpenSessionPacket, SessionPacketProof, ValidateSessionPacket, closeSession, getSession, openSession, validateSession } from "./payloads/packets/session"
import { LocalStore, Store, StoreObj } from "./store"
import { BasePacket, Payload, signPacket } from "./payloads"
import { TransactionsPacket, combinePackets, sendERC1155, sendERC20, sendERC721, sendTransactions, SendTransactionsArgs, SendERC20Args, SendERC721Args, SendERC1155Args, SendDelayedEncodeArgs, sendDelayedEncode } from "./payloads/packets/transactions"
import { OpenSessionResponse } from "./payloads/responses"
import { Guard } from "./clients/guard.gen"
import { SignMessageArgs, SignMessagePacket, signMessage } from "./payloads/packets/messages"
import { SimpleNetwork, WithSimpleNetwork, toNetworkID } from "./networks"
import { DEFAULT_GUARD } from "./defaults"
import { ethers } from 'ethers'
import {
GetSessionPacket,
OpenSessionPacket,
SessionPacketProof,
ValidateSessionPacket,
FinishValidateSessionPacket,
closeSession,
getSession,
openSession,
validateSession,
finishValidateSession
} from './payloads/packets/session'
import { LocalStore, Store, StoreObj } from './store'
import { BasePacket, Payload, signPacket } from './payloads'
import {
TransactionsPacket,
combinePackets,
sendERC1155,
sendERC20,
sendERC721,
sendTransactions,
SendTransactionsArgs,
SendERC20Args,
SendERC721Args,
SendERC1155Args,
SendDelayedEncodeArgs,
sendDelayedEncode
} from './payloads/packets/transactions'
import { OpenSessionResponse } from './payloads/responses'
import { Guard } from './clients/guard.gen'
import { SignMessageArgs, SignMessagePacket, signMessage } from './payloads/packets/messages'
import { SimpleNetwork, WithSimpleNetwork, toNetworkID } from './networks'
import { DEFAULT_GUARD } from './defaults'

@@ -26,7 +50,7 @@ type status = 'pending' | 'signed-in' | 'signed-out'

export type ExtraTransactionArgs = ExtraArgs & {
identifier: string,
identifier: string
}
export type SequenceBaseConfig = {
network: SimpleNetwork,
network: SimpleNetwork
}

@@ -41,3 +65,3 @@

constructor (
constructor(
public readonly config = { network: 1 } as SequenceBaseConfig,

@@ -69,12 +93,16 @@ private readonly store: Store = new LocalStore(),

private async commonArgs<T>(args: T & {
identifier: string,
lifespan?: number,
network?: SimpleNetwork,
}): Promise<T & {
identifier: string,
wallet: string,
lifespan: number,
chainId: number
}> {
private async commonArgs<T>(
args: T & {
identifier: string
lifespan?: number
network?: SimpleNetwork
}
): Promise<
T & {
identifier: string
wallet: string
lifespan: number
chainId: number
}
> {
return {

@@ -85,3 +113,3 @@ ...args,

lifespan: args?.lifespan ?? DEFAULT_LIFESPAN,
chainId: toNetworkID(args.network || this.config.network),
chainId: toNetworkID(args.network || this.config.network)
}

@@ -113,6 +141,8 @@ }

packet,
signatures: [{
session: signer.address,
signature
}]
signatures: [
{
session: signer.address,
signature
}
]
}

@@ -184,6 +214,3 @@ }

await Promise.all([
this.status.set('pending'),
this.signer.set(result.signer.privateKey)
])
await Promise.all([this.status.set('pending'), this.signer.set(result.signer.privateKey)])

@@ -204,3 +231,3 @@ return {

wallet: await this.getWalletAddress(),
session: sessionId || await this.getSignerAddress(),
session: sessionId || (await this.getSignerAddress())
})

@@ -212,7 +239,3 @@

async completeSignOut() {
await Promise.all([
this.status.set('signed-out'),
this.signer.set(undefined),
this.wallet.set(undefined)
])
await Promise.all([this.status.set('signed-out'), this.signer.set(undefined), this.wallet.set(undefined)])
}

@@ -254,6 +277,3 @@

await Promise.all([
this.status.set('signed-in'),
this.wallet.set(receipt.data.wallet)
])
await Promise.all([this.status.set('signed-in'), this.wallet.set(receipt.data.wallet)])

@@ -305,3 +325,5 @@ return receipt.data.wallet

*/
async sendTransaction(args: WithSimpleNetwork<SendTransactionsArgs> & ExtraTransactionArgs): Promise<Payload<TransactionsPacket>> {
async sendTransaction(
args: WithSimpleNetwork<SendTransactionsArgs> & ExtraTransactionArgs
): Promise<Payload<TransactionsPacket>> {
const packet = sendTransactions(await this.commonArgs(args))

@@ -338,3 +360,5 @@ return this.buildPayload(packet)

async callContract(args: WithSimpleNetwork<SendDelayedEncodeArgs> & ExtraTransactionArgs): Promise<Payload<TransactionsPacket>> {
async callContract(
args: WithSimpleNetwork<SendDelayedEncodeArgs> & ExtraTransactionArgs
): Promise<Payload<TransactionsPacket>> {
const packet = sendDelayedEncode(await this.commonArgs(args))

@@ -348,3 +372,3 @@ return this.buildPayload(packet)

}: {
deviceMetadata: string,
deviceMetadata: string
redirectURL?: string

@@ -357,3 +381,3 @@ }): Promise<Payload<ValidateSessionPacket>> {

redirectURL,
wallet: await this.getWalletAddress(),
wallet: await this.getWalletAddress()
})

@@ -368,3 +392,3 @@

wallet: await this.getWalletAddress(),
lifespan: DEFAULT_LIFESPAN,
lifespan: DEFAULT_LIFESPAN
})

@@ -375,2 +399,9 @@

async finishValidateSession(salt: string, challenge: string): Promise<Payload<FinishValidateSessionPacket>> {
const session = await this.getSignerAddress()
const wallet = await this.getWalletAddress()
const packet = finishValidateSession(wallet, session, salt, challenge, DEFAULT_LIFESPAN)
return this.buildPayload(packet)
}
async isSessionValid(): Promise<boolean> {

@@ -403,5 +434,3 @@ const sessionAddress = await this.getSignerAddress()

async batch(
payloads: Payload<TransactionsPacket>[]
): Promise<Payload<TransactionsPacket>> {
async batch(payloads: Payload<TransactionsPacket>[]): Promise<Payload<TransactionsPacket>> {
const combined = combinePackets(payloads.map(p => p.packet))

@@ -408,0 +437,0 @@ return this.buildPayload(combined)

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

import { ethers } from 'ethers'

@@ -7,4 +6,4 @@ import { BasePacket, BasePacketForWallet } from '..'

export type SessionPacketProof = {
email?: string;
idToken?: string;
email?: string
idToken?: string
}

@@ -14,3 +13,3 @@

code: 'openSession'
session: string;
session: string
proof: SessionPacketProof

@@ -20,10 +19,17 @@ }

export type ValidateSessionPacket = BasePacketForWallet & {
code: 'validateSession',
session: string,
deviceMetadata: string,
redirectURL?: string,
code: 'validateSession'
session: string
deviceMetadata: string
redirectURL?: string
}
export type FinishValidateSessionPacket = BasePacketForWallet & {
code: 'finishValidateSession'
session: string
salt: string
challenge: string
}
export type GetSessionPacket = BasePacketForWallet & {
code: 'getSession',
code: 'getSession'
session: string

@@ -36,5 +42,5 @@ }

}: {
proof: SessionPacketProof | undefined,
proof: SessionPacketProof | undefined
lifespan: number
}): Promise<{ packet: OpenSessionPacket, signer: ethers.Wallet }> {
}): Promise<{ packet: OpenSessionPacket; signer: ethers.Wallet }> {
const signer = ethers.Wallet.createRandom()

@@ -49,3 +55,3 @@

proof // May be defined server side
},
}
}

@@ -64,4 +70,4 @@ }

}: {
session: string,
wallet: string,
session: string
wallet: string
lifespan: number

@@ -73,12 +79,14 @@ }): Promise<CloseSessionPacket> {

wallet,
session,
session
}
}
export async function validateSession(args: {
wallet: string,
session: string
deviceMetadata: string,
redirectURL?: string,
} & { lifespan: number }): Promise<ValidateSessionPacket> {
export async function validateSession(
args: {
wallet: string
session: string
deviceMetadata: string
redirectURL?: string
} & { lifespan: number }
): Promise<ValidateSessionPacket> {
return {

@@ -91,5 +99,22 @@ ...useLifespan(args.lifespan),

export function finishValidateSession(
wallet: string,
session: string,
salt: string,
challenge: string,
lifespan: number
): FinishValidateSessionPacket {
return {
...useLifespan(lifespan),
wallet: wallet,
session: session,
code: 'finishValidateSession',
salt: salt,
challenge: challenge
}
}
export async function getSession(
args: {
wallet: string,
wallet: string
session: string

@@ -96,0 +121,0 @@ } & { lifespan: number }

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