From 749b19c9a7193ff71b96cf0ce7a49eb7cb16cc8a Mon Sep 17 00:00:00 2001 From: Marcin Gorzynski Date: Tue, 16 Jan 2024 10:45:01 +0100 Subject: [PATCH] waas: replace tenant / secret with AccessKey --- packages/waas/src/auth.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/waas/src/auth.ts b/packages/waas/src/auth.ts index 7529b7401..3eb6a19bd 100644 --- a/packages/waas/src/auth.ts +++ b/packages/waas/src/auth.ts @@ -34,12 +34,13 @@ import { SignMessageArgs } from './payloads/packets/messages' import { SimpleNetwork, WithSimpleNetwork } from './networks' import { TEMPLATE_LOCAL } from './defaults' import { EmailAuth } from './email' +import { base64 } from "ethers/lib/utils"; +import { BigNumber } from "ethers"; export type Sessions = (Session & { isThis: boolean })[] export type SequenceExplicitConfig = { - secret: string - tenant: number + accessKey: string emailClientId?: string identityPoolId: string @@ -109,12 +110,8 @@ export function defaultArgsOrFail( preconfig.network = 1 } - if (preconfig.tenant === undefined) { - throw new Error('Missing tenant') - } - - if (preconfig.secret === undefined) { - throw new Error('Missing secret') + if (preconfig.accessKey === undefined) { + throw new Error('Missing access key') } if (preconfig.identityPoolId === undefined) { @@ -255,8 +252,7 @@ export class Sequence { return { headers: { - 'X-Sequence-Tenant': this.config.tenant - // 'X-Sequence-Secret': this.config.secret, + 'X-Access-Key': this.config.accessKey }, args: { encryptedPayloadKey, payloadCiphertext, payloadSig } } @@ -294,8 +290,12 @@ export class Sequence { await this.saveCypherKey(kmsClient) + const projectId = BigNumber.from( + base64.decode(this.config.accessKey).slice(-8) + ) + const payload: RegisterSessionPayload = { - projectId: this.config.tenant, + projectId: projectId.toNumber(), idToken: creds.idToken, sessionAddress: waaspayload.packet.session, friendlyName: name,