@0xsequence/waas
Advanced tools
Comparing version 0.0.0-20240123145607 to 0.0.0-20240131180030
@@ -37,14 +37,11 @@ 'use strict'; | ||
async function openSession({ | ||
signer, | ||
proof = {}, | ||
lifespan | ||
}) { | ||
const signer = ethers.ethers.Wallet.createRandom(); | ||
return { | ||
signer, | ||
packet: _extends({}, useLifespan(lifespan), { | ||
code: 'openSession', | ||
session: signer.address, | ||
proof // May be defined server side | ||
}) | ||
}; | ||
return _extends({}, useLifespan(lifespan), { | ||
code: 'openSession', | ||
session: await signer.getAddress(), | ||
proof // May be defined server side | ||
}); | ||
} | ||
@@ -474,7 +471,3 @@ | ||
} | ||
const signerPk = await this.signer.get(); | ||
if (!signerPk) { | ||
throw new Error('No signer'); | ||
} | ||
const signer = new ethers.ethers.Wallet(signerPk); | ||
const signer = await this.getSigner(); | ||
const signature = await signPacket(signer, packet); | ||
@@ -490,16 +483,17 @@ return { | ||
} | ||
async signUsingSessionKey(message) { | ||
const signerPk = await this.signer.get(); | ||
async getSigner() { | ||
let signerPk = await this.signer.get(); | ||
if (!signerPk) { | ||
throw new Error('No signer'); | ||
const signer = ethers.ethers.Wallet.createRandom(); | ||
signerPk = signer.privateKey; | ||
await this.signer.set(signerPk); | ||
} | ||
const signer = new ethers.ethers.Wallet(signerPk); | ||
return new ethers.ethers.Wallet(signerPk); | ||
} | ||
async signUsingSessionKey(message) { | ||
const signer = await this.getSigner(); | ||
return signer.signMessage(message); | ||
} | ||
async getSignerAddress() { | ||
const signerPk = await this.signer.get(); | ||
if (!signerPk) { | ||
throw new Error('No signer'); | ||
} | ||
const signer = new ethers.ethers.Wallet(signerPk); | ||
const signer = await this.getSigner(); | ||
return signer.address; | ||
@@ -548,10 +542,11 @@ } | ||
} | ||
const result = await openSession({ | ||
const packet = await openSession({ | ||
signer: await this.getSigner(), | ||
proof, | ||
lifespan: DEFAULT_LIFESPAN | ||
}); | ||
await Promise.all([this.status.set('pending'), this.signer.set(result.signer.privateKey)]); | ||
await this.status.set('pending'); | ||
return { | ||
version: this.VERSION, | ||
packet: result.packet, | ||
packet, | ||
// NOTICE: We don't sign the open session packet. | ||
@@ -1058,3 +1053,4 @@ // because the session is not yet open, so it can't be used to sign. | ||
email, | ||
answer | ||
answer, | ||
sessionAddress | ||
}) { | ||
@@ -1068,2 +1064,5 @@ const res = await this.cognito().send(new clientCognitoIdentityProvider.RespondToAuthChallengeCommand({ | ||
ANSWER: answer | ||
}, | ||
ClientMetadata: { | ||
sessionAddress | ||
} | ||
@@ -1070,0 +1069,0 @@ })); |
@@ -37,14 +37,11 @@ 'use strict'; | ||
async function openSession({ | ||
signer, | ||
proof = {}, | ||
lifespan | ||
}) { | ||
const signer = ethers.ethers.Wallet.createRandom(); | ||
return { | ||
signer, | ||
packet: _extends({}, useLifespan(lifespan), { | ||
code: 'openSession', | ||
session: signer.address, | ||
proof // May be defined server side | ||
}) | ||
}; | ||
return _extends({}, useLifespan(lifespan), { | ||
code: 'openSession', | ||
session: await signer.getAddress(), | ||
proof // May be defined server side | ||
}); | ||
} | ||
@@ -474,7 +471,3 @@ | ||
} | ||
const signerPk = await this.signer.get(); | ||
if (!signerPk) { | ||
throw new Error('No signer'); | ||
} | ||
const signer = new ethers.ethers.Wallet(signerPk); | ||
const signer = await this.getSigner(); | ||
const signature = await signPacket(signer, packet); | ||
@@ -490,16 +483,17 @@ return { | ||
} | ||
async signUsingSessionKey(message) { | ||
const signerPk = await this.signer.get(); | ||
async getSigner() { | ||
let signerPk = await this.signer.get(); | ||
if (!signerPk) { | ||
throw new Error('No signer'); | ||
const signer = ethers.ethers.Wallet.createRandom(); | ||
signerPk = signer.privateKey; | ||
await this.signer.set(signerPk); | ||
} | ||
const signer = new ethers.ethers.Wallet(signerPk); | ||
return new ethers.ethers.Wallet(signerPk); | ||
} | ||
async signUsingSessionKey(message) { | ||
const signer = await this.getSigner(); | ||
return signer.signMessage(message); | ||
} | ||
async getSignerAddress() { | ||
const signerPk = await this.signer.get(); | ||
if (!signerPk) { | ||
throw new Error('No signer'); | ||
} | ||
const signer = new ethers.ethers.Wallet(signerPk); | ||
const signer = await this.getSigner(); | ||
return signer.address; | ||
@@ -548,10 +542,11 @@ } | ||
} | ||
const result = await openSession({ | ||
const packet = await openSession({ | ||
signer: await this.getSigner(), | ||
proof, | ||
lifespan: DEFAULT_LIFESPAN | ||
}); | ||
await Promise.all([this.status.set('pending'), this.signer.set(result.signer.privateKey)]); | ||
await this.status.set('pending'); | ||
return { | ||
version: this.VERSION, | ||
packet: result.packet, | ||
packet, | ||
// NOTICE: We don't sign the open session packet. | ||
@@ -1058,3 +1053,4 @@ // because the session is not yet open, so it can't be used to sign. | ||
email, | ||
answer | ||
answer, | ||
sessionAddress | ||
}) { | ||
@@ -1068,2 +1064,5 @@ const res = await this.cognito().send(new clientCognitoIdentityProvider.RespondToAuthChallengeCommand({ | ||
ANSWER: answer | ||
}, | ||
ClientMetadata: { | ||
sessionAddress | ||
} | ||
@@ -1070,0 +1069,0 @@ })); |
@@ -33,14 +33,11 @@ import { ethers } from 'ethers'; | ||
async function openSession({ | ||
signer, | ||
proof = {}, | ||
lifespan | ||
}) { | ||
const signer = ethers.Wallet.createRandom(); | ||
return { | ||
signer, | ||
packet: _extends({}, useLifespan(lifespan), { | ||
code: 'openSession', | ||
session: signer.address, | ||
proof // May be defined server side | ||
}) | ||
}; | ||
return _extends({}, useLifespan(lifespan), { | ||
code: 'openSession', | ||
session: await signer.getAddress(), | ||
proof // May be defined server side | ||
}); | ||
} | ||
@@ -470,7 +467,3 @@ | ||
} | ||
const signerPk = await this.signer.get(); | ||
if (!signerPk) { | ||
throw new Error('No signer'); | ||
} | ||
const signer = new ethers.Wallet(signerPk); | ||
const signer = await this.getSigner(); | ||
const signature = await signPacket(signer, packet); | ||
@@ -486,16 +479,17 @@ return { | ||
} | ||
async signUsingSessionKey(message) { | ||
const signerPk = await this.signer.get(); | ||
async getSigner() { | ||
let signerPk = await this.signer.get(); | ||
if (!signerPk) { | ||
throw new Error('No signer'); | ||
const signer = ethers.Wallet.createRandom(); | ||
signerPk = signer.privateKey; | ||
await this.signer.set(signerPk); | ||
} | ||
const signer = new ethers.Wallet(signerPk); | ||
return new ethers.Wallet(signerPk); | ||
} | ||
async signUsingSessionKey(message) { | ||
const signer = await this.getSigner(); | ||
return signer.signMessage(message); | ||
} | ||
async getSignerAddress() { | ||
const signerPk = await this.signer.get(); | ||
if (!signerPk) { | ||
throw new Error('No signer'); | ||
} | ||
const signer = new ethers.Wallet(signerPk); | ||
const signer = await this.getSigner(); | ||
return signer.address; | ||
@@ -544,10 +538,11 @@ } | ||
} | ||
const result = await openSession({ | ||
const packet = await openSession({ | ||
signer: await this.getSigner(), | ||
proof, | ||
lifespan: DEFAULT_LIFESPAN | ||
}); | ||
await Promise.all([this.status.set('pending'), this.signer.set(result.signer.privateKey)]); | ||
await this.status.set('pending'); | ||
return { | ||
version: this.VERSION, | ||
packet: result.packet, | ||
packet, | ||
// NOTICE: We don't sign the open session packet. | ||
@@ -1054,3 +1049,4 @@ // because the session is not yet open, so it can't be used to sign. | ||
email, | ||
answer | ||
answer, | ||
sessionAddress | ||
}) { | ||
@@ -1064,2 +1060,5 @@ const res = await this.cognito().send(new RespondToAuthChallengeCommand({ | ||
ANSWER: answer | ||
}, | ||
ClientMetadata: { | ||
sessionAddress | ||
} | ||
@@ -1066,0 +1065,0 @@ })); |
@@ -36,2 +36,3 @@ import { GetSessionPacket, OpenSessionPacket, SessionPacketProof, ValidateSessionPacket, FinishValidateSessionPacket } from "./payloads/packets/session.js"; | ||
private buildPayload; | ||
private getSigner; | ||
signUsingSessionKey(message: string | Uint8Array): Promise<string>; | ||
@@ -38,0 +39,0 @@ getSignerAddress(): Promise<string>; |
@@ -16,7 +16,8 @@ import { Identity } from "./auth.js"; | ||
}>; | ||
finalizeAuth({ instance, email, answer }: { | ||
finalizeAuth({ instance, email, answer, sessionAddress }: { | ||
instance: string; | ||
email: string; | ||
answer: string; | ||
sessionAddress: string; | ||
}): Promise<Identity>; | ||
} |
@@ -28,9 +28,7 @@ import { ethers } from 'ethers'; | ||
}; | ||
export declare function openSession({ proof, lifespan }: { | ||
export declare function openSession({ signer, proof, lifespan }: { | ||
signer: ethers.Signer; | ||
proof: SessionPacketProof | undefined; | ||
lifespan: number; | ||
}): Promise<{ | ||
packet: OpenSessionPacket; | ||
signer: ethers.Wallet; | ||
}>; | ||
}): Promise<OpenSessionPacket>; | ||
export type CloseSessionPacket = BasePacketForWallet & { | ||
@@ -37,0 +35,0 @@ code: 'closeSession'; |
{ | ||
"name": "@0xsequence/waas", | ||
"version": "0.0.0-20240123145607", | ||
"version": "0.0.0-20240131180030", | ||
"description": "waas session client", | ||
@@ -12,3 +12,3 @@ "repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/waas", | ||
"dependencies": { | ||
"@0xsequence/network": "0.0.0-20240123145607", | ||
"@0xsequence/network": "0.0.0-20240131180030", | ||
"@aws-sdk/client-cognito-identity-provider": "^3.445.0", | ||
@@ -15,0 +15,0 @@ "@aws-sdk/client-kms": "^3.429.0", |
@@ -123,8 +123,3 @@ import { ethers } from 'ethers' | ||
const signerPk = await this.signer.get() | ||
if (!signerPk) { | ||
throw new Error('No signer') | ||
} | ||
const signer = new ethers.Wallet(signerPk) | ||
const signer = await this.getSigner() | ||
const signature = await signPacket(signer, packet) | ||
@@ -144,9 +139,15 @@ | ||
public async signUsingSessionKey(message: string | Uint8Array) { | ||
const signerPk = await this.signer.get() | ||
private async getSigner() { | ||
let signerPk = await this.signer.get() | ||
if (!signerPk) { | ||
throw new Error('No signer') | ||
const signer = ethers.Wallet.createRandom() | ||
signerPk = signer.privateKey | ||
await this.signer.set(signerPk) | ||
} | ||
const signer = new ethers.Wallet(signerPk) | ||
return new ethers.Wallet(signerPk) | ||
} | ||
public async signUsingSessionKey(message: string | Uint8Array) { | ||
const signer = await this.getSigner() | ||
return signer.signMessage(message) | ||
@@ -156,8 +157,3 @@ } | ||
public async getSignerAddress() { | ||
const signerPk = await this.signer.get() | ||
if (!signerPk) { | ||
throw new Error('No signer') | ||
} | ||
const signer = new ethers.Wallet(signerPk) | ||
const signer = await this.getSigner() | ||
return signer.address | ||
@@ -207,9 +203,13 @@ } | ||
const result = await openSession({ proof, lifespan: DEFAULT_LIFESPAN }) | ||
const packet = await openSession({ | ||
signer: await this.getSigner(), | ||
proof, | ||
lifespan: DEFAULT_LIFESPAN, | ||
}) | ||
await Promise.all([this.status.set('pending'), this.signer.set(result.signer.privateKey)]) | ||
await this.status.set('pending') | ||
return { | ||
version: this.VERSION, | ||
packet: result.packet, | ||
packet, | ||
@@ -216,0 +216,0 @@ // NOTICE: We don't sign the open session packet. |
@@ -80,3 +80,3 @@ | ||
public async finalizeAuth({ instance, email, answer }: { instance: string, email: string, answer: string }): Promise<Identity> { | ||
public async finalizeAuth({ instance, email, answer, sessionAddress }: { instance: string, email: string, answer: string, sessionAddress: string }): Promise<Identity> { | ||
const res = await this.cognito().send(new RespondToAuthChallengeCommand({ | ||
@@ -87,2 +87,3 @@ ClientId: this.clientId, | ||
ChallengeResponses: { USERNAME: email, ANSWER: answer }, | ||
ClientMetadata: { sessionAddress }, | ||
})) | ||
@@ -89,0 +90,0 @@ |
@@ -36,18 +36,16 @@ import { ethers } from 'ethers' | ||
export async function openSession({ | ||
signer, | ||
proof = {}, | ||
lifespan | ||
}: { | ||
signer: ethers.Signer | ||
proof: SessionPacketProof | undefined | ||
lifespan: number | ||
}): Promise<{ packet: OpenSessionPacket; signer: ethers.Wallet }> { | ||
const signer = ethers.Wallet.createRandom() | ||
}): Promise<OpenSessionPacket> { | ||
return { | ||
signer, | ||
packet: { | ||
...useLifespan(lifespan), | ||
code: 'openSession', | ||
session: signer.address, | ||
proof // May be defined server side | ||
} | ||
...useLifespan(lifespan), | ||
code: 'openSession', | ||
session: await signer.getAddress(), | ||
proof // May be defined server side | ||
} | ||
@@ -54,0 +52,0 @@ } |
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
247491
7242
+ Added@0xsequence/abi@0.0.0-20240131180030(transitive)
+ Added@0xsequence/core@0.0.0-20240131180030(transitive)
+ Added@0xsequence/indexer@0.0.0-20240131180030(transitive)
+ Added@0xsequence/network@0.0.0-20240131180030(transitive)
+ Added@0xsequence/relayer@0.0.0-20240131180030(transitive)
+ Added@0xsequence/utils@0.0.0-20240131180030(transitive)
- Removed@0xsequence/abi@0.0.0-20240123145607(transitive)
- Removed@0xsequence/core@0.0.0-20240123145607(transitive)
- Removed@0xsequence/indexer@0.0.0-20240123145607(transitive)
- Removed@0xsequence/network@0.0.0-20240123145607(transitive)
- Removed@0xsequence/relayer@0.0.0-20240123145607(transitive)
- Removed@0xsequence/utils@0.0.0-20240123145607(transitive)