@0xsequence/waas
Advanced tools
Comparing version 0.0.0-20231113164400 to 0.0.0-20231121142317
@@ -322,2 +322,5 @@ 'use strict'; | ||
} | ||
function isFinishValidateSessionResponse(receipt) { | ||
return typeof receipt === 'object' && typeof receipt.code === 'string' && receipt.code === 'finishedSessionValidation' && typeof receipt.data === 'object'; | ||
} | ||
function isGetSessionResponse(receipt) { | ||
@@ -336,2 +339,3 @@ return typeof receipt === 'object' && typeof receipt.code === 'string' && receipt.code === 'getSessionResponse' && typeof receipt.data === 'object' && typeof receipt.data.session === 'string' && typeof receipt.data.wallet === 'string'; | ||
isValidateSessionResponse: isValidateSessionResponse, | ||
isFinishValidateSessionResponse: isFinishValidateSessionResponse, | ||
isGetSessionResponse: isGetSessionResponse | ||
@@ -1264,17 +1268,16 @@ }); | ||
async handleValidationRequired({ | ||
onValidationRequired, | ||
redirectURL | ||
onValidationRequired | ||
} = {}) { | ||
var _await$this$deviceNam; | ||
const proceed = onValidationRequired ? onValidationRequired() : true; | ||
if (!proceed) { | ||
return false; | ||
} | ||
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; | ||
if (!proceed) { | ||
return false; | ||
} | ||
this.validationRequiredSalt = sendIntent.data.salt; | ||
for (const callback of this.validationRequiredCallback) { | ||
callback(sendIntent.data.salt); | ||
callback(); | ||
} | ||
@@ -1459,5 +1462,10 @@ return this.waitForSessionValid(); | ||
} | ||
async finishValidateSession(salt, challenge) { | ||
const intent = await this.waas.finishValidateSession(salt, challenge); | ||
return this.sendIntent(intent); | ||
async finishValidateSession(challenge) { | ||
const intent = await this.waas.finishValidateSession(this.validationRequiredSalt, challenge); | ||
const result = await this.sendIntent(intent); | ||
if (!isFinishValidateSessionResponse(result)) { | ||
throw new Error(`Invalid response: ${JSON.stringify(result)}`); | ||
} | ||
this.validationRequiredSalt = ""; | ||
return result.data.isValid; | ||
} | ||
@@ -1540,2 +1548,3 @@ async isSessionValid() { | ||
exports.isFailedTransactionResponse = isFailedTransactionResponse; | ||
exports.isFinishValidateSessionResponse = isFinishValidateSessionResponse; | ||
exports.isGetSessionResponse = isGetSessionResponse; | ||
@@ -1542,0 +1551,0 @@ exports.isMaySentTransactionResponse = isMaySentTransactionResponse; |
@@ -322,2 +322,5 @@ 'use strict'; | ||
} | ||
function isFinishValidateSessionResponse(receipt) { | ||
return typeof receipt === 'object' && typeof receipt.code === 'string' && receipt.code === 'finishedSessionValidation' && typeof receipt.data === 'object'; | ||
} | ||
function isGetSessionResponse(receipt) { | ||
@@ -336,2 +339,3 @@ return typeof receipt === 'object' && typeof receipt.code === 'string' && receipt.code === 'getSessionResponse' && typeof receipt.data === 'object' && typeof receipt.data.session === 'string' && typeof receipt.data.wallet === 'string'; | ||
isValidateSessionResponse: isValidateSessionResponse, | ||
isFinishValidateSessionResponse: isFinishValidateSessionResponse, | ||
isGetSessionResponse: isGetSessionResponse | ||
@@ -1264,17 +1268,16 @@ }); | ||
async handleValidationRequired({ | ||
onValidationRequired, | ||
redirectURL | ||
onValidationRequired | ||
} = {}) { | ||
var _await$this$deviceNam; | ||
const proceed = onValidationRequired ? onValidationRequired() : true; | ||
if (!proceed) { | ||
return false; | ||
} | ||
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; | ||
if (!proceed) { | ||
return false; | ||
} | ||
this.validationRequiredSalt = sendIntent.data.salt; | ||
for (const callback of this.validationRequiredCallback) { | ||
callback(sendIntent.data.salt); | ||
callback(); | ||
} | ||
@@ -1459,5 +1462,10 @@ return this.waitForSessionValid(); | ||
} | ||
async finishValidateSession(salt, challenge) { | ||
const intent = await this.waas.finishValidateSession(salt, challenge); | ||
return this.sendIntent(intent); | ||
async finishValidateSession(challenge) { | ||
const intent = await this.waas.finishValidateSession(this.validationRequiredSalt, challenge); | ||
const result = await this.sendIntent(intent); | ||
if (!isFinishValidateSessionResponse(result)) { | ||
throw new Error(`Invalid response: ${JSON.stringify(result)}`); | ||
} | ||
this.validationRequiredSalt = ""; | ||
return result.data.isValid; | ||
} | ||
@@ -1540,2 +1548,3 @@ async isSessionValid() { | ||
exports.isFailedTransactionResponse = isFailedTransactionResponse; | ||
exports.isFinishValidateSessionResponse = isFinishValidateSessionResponse; | ||
exports.isGetSessionResponse = isGetSessionResponse; | ||
@@ -1542,0 +1551,0 @@ exports.isMaySentTransactionResponse = isMaySentTransactionResponse; |
@@ -318,2 +318,5 @@ import { ethers } from 'ethers'; | ||
} | ||
function isFinishValidateSessionResponse(receipt) { | ||
return typeof receipt === 'object' && typeof receipt.code === 'string' && receipt.code === 'finishedSessionValidation' && typeof receipt.data === 'object'; | ||
} | ||
function isGetSessionResponse(receipt) { | ||
@@ -332,2 +335,3 @@ return typeof receipt === 'object' && typeof receipt.code === 'string' && receipt.code === 'getSessionResponse' && typeof receipt.data === 'object' && typeof receipt.data.session === 'string' && typeof receipt.data.wallet === 'string'; | ||
isValidateSessionResponse: isValidateSessionResponse, | ||
isFinishValidateSessionResponse: isFinishValidateSessionResponse, | ||
isGetSessionResponse: isGetSessionResponse | ||
@@ -1260,17 +1264,16 @@ }); | ||
async handleValidationRequired({ | ||
onValidationRequired, | ||
redirectURL | ||
onValidationRequired | ||
} = {}) { | ||
var _await$this$deviceNam; | ||
const proceed = onValidationRequired ? onValidationRequired() : true; | ||
if (!proceed) { | ||
return false; | ||
} | ||
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; | ||
if (!proceed) { | ||
return false; | ||
} | ||
this.validationRequiredSalt = sendIntent.data.salt; | ||
for (const callback of this.validationRequiredCallback) { | ||
callback(sendIntent.data.salt); | ||
callback(); | ||
} | ||
@@ -1455,5 +1458,10 @@ return this.waitForSessionValid(); | ||
} | ||
async finishValidateSession(salt, challenge) { | ||
const intent = await this.waas.finishValidateSession(salt, challenge); | ||
return this.sendIntent(intent); | ||
async finishValidateSession(challenge) { | ||
const intent = await this.waas.finishValidateSession(this.validationRequiredSalt, challenge); | ||
const result = await this.sendIntent(intent); | ||
if (!isFinishValidateSessionResponse(result)) { | ||
throw new Error(`Invalid response: ${JSON.stringify(result)}`); | ||
} | ||
this.validationRequiredSalt = ""; | ||
return result.data.isValid; | ||
} | ||
@@ -1531,2 +1539,2 @@ async isSessionValid() { | ||
export { Sequence, SequenceWaaSBase, defaultArgsOrFail, defaults, isFailedTransactionResponse, isGetSessionResponse, isMaySentTransactionResponse, isOpenSessionResponse, isSentTransactionResponse, isSignedMessageResponse, isValidateSessionResponse, isValidationRequiredResponse, parseApiKey, index as payloads, store }; | ||
export { Sequence, SequenceWaaSBase, defaultArgsOrFail, defaults, isFailedTransactionResponse, isFinishValidateSessionResponse, isGetSessionResponse, isMaySentTransactionResponse, isOpenSessionResponse, isSentTransactionResponse, isSignedMessageResponse, isValidateSessionResponse, isValidationRequiredResponse, parseApiKey, index as payloads, store }; |
import { Store } from "./store.js"; | ||
import { MaySentTransactionResponse, SignedMessageResponse } from "./payloads/responses.js"; | ||
import { Session, SendIntentReturn } from "./clients/authenticator.gen.js"; | ||
import { Session } from "./clients/authenticator.gen.js"; | ||
import { SendDelayedEncodeArgs, SendERC1155Args, SendERC20Args, SendERC721Args, SendTransactionsArgs } from "./payloads/packets/transactions.js"; | ||
@@ -36,3 +36,2 @@ import { SignMessageArgs } from "./payloads/packets/messages.js"; | ||
onValidationRequired?: () => boolean; | ||
redirectURL?: string; | ||
}; | ||
@@ -50,2 +49,3 @@ export type CommonAuthArgs = { | ||
private validationRequiredCallback; | ||
private validationRequiredSalt; | ||
readonly config: Required<SequenceExplicitConfig> & ExtendedSequenceConfig; | ||
@@ -57,3 +57,3 @@ private readonly kmsKey; | ||
get email(): EmailAuth; | ||
onValidationRequired(callback: (salt: string) => void): Promise<() => void>; | ||
onValidationRequired(callback: () => void): Promise<() => void>; | ||
private handleValidationRequired; | ||
@@ -75,3 +75,3 @@ private useStoredCypherKey; | ||
validateSession(args?: ValidationArgs): Promise<boolean>; | ||
finishValidateSession(salt: string, challenge: string): Promise<SendIntentReturn>; | ||
finishValidateSession(challenge: string): Promise<boolean>; | ||
isSessionValid(): Promise<boolean>; | ||
@@ -78,0 +78,0 @@ waitForSessionValid(timeout?: number, pollRate?: number): Promise<boolean>; |
@@ -72,2 +72,8 @@ import { TransactionsPacket } from "./packets/transactions.js"; | ||
}; | ||
export type FinishValidateSessionResponse = { | ||
code: 'finishedSessionValidation'; | ||
data: { | ||
isValid: boolean; | ||
}; | ||
}; | ||
export type GetSessionResponse = { | ||
@@ -88,3 +94,4 @@ code: 'getSessionResponse'; | ||
export declare function isValidateSessionResponse(receipt: any): receipt is ValidateSessionResponse; | ||
export declare function isFinishValidateSessionResponse(receipt: any): receipt is FinishValidateSessionResponse; | ||
export declare function isGetSessionResponse(receipt: any): receipt is GetSessionResponse; | ||
export {}; |
{ | ||
"name": "@0xsequence/waas", | ||
"version": "0.0.0-20231113164400", | ||
"version": "0.0.0-20231121142317", | ||
"description": "waas session client", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/waas", |
@@ -11,3 +11,4 @@ import { fromCognitoIdentityPool } from '@aws-sdk/credential-providers' | ||
isSignedMessageResponse, | ||
isValidationRequiredResponse | ||
isValidationRequiredResponse, | ||
isFinishValidateSessionResponse | ||
} from './payloads/responses' | ||
@@ -88,3 +89,2 @@ import { | ||
onValidationRequired?: () => boolean | ||
redirectURL?: string | ||
} | ||
@@ -132,3 +132,4 @@ | ||
private validationRequiredCallback: ((salt: string) => void)[] = [] | ||
private validationRequiredCallback: (() => void)[] = [] | ||
private validationRequiredSalt: string | ||
@@ -171,3 +172,3 @@ public readonly config: Required<SequenceExplicitConfig> & ExtendedSequenceConfig | ||
async onValidationRequired(callback: (salt: string) => void) { | ||
async onValidationRequired(callback: () => void) { | ||
this.validationRequiredCallback.push(callback) | ||
@@ -179,5 +180,9 @@ return () => { | ||
private async handleValidationRequired({ onValidationRequired, redirectURL }: ValidationArgs = {}): Promise<boolean> { | ||
private async handleValidationRequired({ onValidationRequired }: ValidationArgs = {}): Promise<boolean> { | ||
const proceed = onValidationRequired ? onValidationRequired() : true | ||
if (!proceed) { | ||
return false | ||
} | ||
const intent = await this.waas.validateSession({ | ||
redirectURL, | ||
deviceMetadata: (await this.deviceName.get()) ?? 'Unknown device' | ||
@@ -187,10 +192,6 @@ }) | ||
const sendIntent = await this.sendIntent(intent) | ||
this.validationRequiredSalt = sendIntent.data.salt | ||
const proceed = onValidationRequired ? onValidationRequired() : true | ||
if (!proceed) { | ||
return false | ||
} | ||
for (const callback of this.validationRequiredCallback) { | ||
callback(sendIntent.data.salt) | ||
callback() | ||
} | ||
@@ -390,5 +391,13 @@ | ||
async finishValidateSession(salt: string, challenge: string): Promise<SendIntentReturn> { | ||
const intent = await this.waas.finishValidateSession(salt, challenge) | ||
return this.sendIntent(intent) | ||
async finishValidateSession(challenge: string): Promise<boolean> { | ||
const intent = await this.waas.finishValidateSession(this.validationRequiredSalt, challenge) | ||
const result = await this.sendIntent(intent) | ||
if (!isFinishValidateSessionResponse(result)) { | ||
throw new Error(`Invalid response: ${JSON.stringify(result)}`) | ||
} | ||
this.validationRequiredSalt = "" | ||
return result.data.isValid | ||
} | ||
@@ -395,0 +404,0 @@ |
@@ -84,2 +84,9 @@ import { TransactionsPacket } from "./packets/transactions" | ||
export type FinishValidateSessionResponse = { | ||
code: 'finishedSessionValidation', | ||
data: { | ||
isValid: boolean | ||
} | ||
} | ||
export type GetSessionResponse = { | ||
@@ -163,2 +170,11 @@ code: 'getSessionResponse' | ||
export function isFinishValidateSessionResponse(receipt: any): receipt is FinishValidateSessionResponse { | ||
return ( | ||
typeof receipt === 'object' && | ||
typeof receipt.code === 'string' && | ||
receipt.code === 'finishedSessionValidation' && | ||
typeof receipt.data === 'object' | ||
) | ||
} | ||
export function isGetSessionResponse(receipt: any): receipt is GetSessionResponse { | ||
@@ -165,0 +181,0 @@ return ( |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
262404
7804
9