From 4a89c75558e1e8c2bec5fa8743eb1d9bf3d09c85 Mon Sep 17 00:00:00 2001 From: dafuga Date: Mon, 29 Apr 2024 15:46:18 -0700 Subject: [PATCH] chore: adding appName to SerializedSession --- src/kit.ts | 2 ++ src/session.ts | 14 ++++++++++---- test/tests/session.ts | 23 ++++++++++------------- test/tests/wallet.ts | 2 ++ 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/kit.ts b/src/kit.ts index 7c993e6..8a3f305 100644 --- a/src/kit.ts +++ b/src/kit.ts @@ -58,6 +58,7 @@ export interface RestoreArgs { actor?: NameType permission?: NameType walletPlugin?: Record + appName?: string } export interface SessionKitArgs { @@ -584,6 +585,7 @@ export class SessionKit { id: args.walletPlugin.id, data: args.walletPlugin.data, }, + appName: this.appName, } } else { // Otherwise throw an error since we can't establish the session data diff --git a/src/session.ts b/src/session.ts index 42127ee..c58d865 100644 --- a/src/session.ts +++ b/src/session.ts @@ -81,6 +81,7 @@ export interface SerializedSession { default?: boolean permission: NameType walletPlugin: SerializedWalletPlugin + appName?: string } /** @@ -602,13 +603,18 @@ export class Session { return walletResponse.signatures } - serialize = (): SerializedSession => - Serializer.objectify({ - chain: this.chain.id, + serialize = (): SerializedSession => { + const serializedData: Record = { actor: this.permissionLevel.actor, + chain: this.chain.id, permission: this.permissionLevel.permission, walletPlugin: this.walletPlugin.serialize(), - }) + } + if (this.appName) { + serializedData.appName = this.appName + } + return Serializer.objectify(serializedData) + } getPluginTranslations(transactPlugin: TransactPlugin | WalletPlugin): LocaleDefinitions { if (!transactPlugin.translations) { diff --git a/test/tests/session.ts b/test/tests/session.ts index e2eae98..a1af6f3 100644 --- a/test/tests/session.ts +++ b/test/tests/session.ts @@ -409,20 +409,17 @@ suite('session', function () { test('returns valid json string', function () { const original = new Session(mockSessionArgs, mockSessionOptions) const serialized = original.serialize() - assert.equal( - JSON.stringify(serialized), - JSON.stringify({ - chain: '73e4385a2708e6d7048834fbc1079f2fabb17b3c125b146af438971e90716c4d', - actor: 'wharfkit1111', - permission: 'test', - walletPlugin: { - id: 'wallet-plugin-privatekey', - data: { - privateKey: 'PVT_K1_25XP1Lt1Rt87hyymouSieBbgnUEAerS1yQHi9wqHC2Uek2mgzH', - }, + assert.deepEqual(serialized, { + chain: '73e4385a2708e6d7048834fbc1079f2fabb17b3c125b146af438971e90716c4d', + actor: 'wharfkit1111', + permission: 'test', + walletPlugin: { + id: 'wallet-plugin-privatekey', + data: { + privateKey: 'PVT_K1_25XP1Lt1Rt87hyymouSieBbgnUEAerS1yQHi9wqHC2Uek2mgzH', }, - }) - ) + }, + }) assert.doesNotThrow(() => { JSON.stringify(serialized) }) diff --git a/test/tests/wallet.ts b/test/tests/wallet.ts index 1299a0d..a3f980d 100644 --- a/test/tests/wallet.ts +++ b/test/tests/wallet.ts @@ -333,6 +333,7 @@ suite('walletPlugin', function () { assert.deepEqual(response.session.serialize(), { chain: '73e4385a2708e6d7048834fbc1079f2fabb17b3c125b146af438971e90716c4d', actor: 'mock', + appName: 'demo.app', permission: 'interface', walletPlugin: { id: 'MockWalletPluginConfigs', @@ -361,6 +362,7 @@ suite('walletPlugin', function () { assert.deepEqual(response.session.serialize(), { chain: '73e4385a2708e6d7048834fbc1079f2fabb17b3c125b146af438971e90716c4d', actor: 'mock', + appName: 'demo.app', permission: 'interface', walletPlugin: { id: 'MockWalletPluginConfigs',