Skip to content

Commit

Permalink
chore: adding appName to SerializedSession
Browse files Browse the repository at this point in the history
  • Loading branch information
dafuga committed Apr 29, 2024
1 parent 749881f commit a08ec17
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/kit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export interface RestoreArgs {
actor?: NameType
permission?: NameType
walletPlugin?: Record<string, any>
appName?: string
}

export interface SessionKitArgs {
Expand Down Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export interface SerializedSession {
default?: boolean
permission: NameType
walletPlugin: SerializedWalletPlugin
appName?: string
}

/**
Expand Down Expand Up @@ -602,13 +603,18 @@ export class Session {
return walletResponse.signatures
}

serialize = (): SerializedSession =>
Serializer.objectify({
chain: this.chain.id,
serialize = (): SerializedSession => {
const serializedData: Record<string, any> = {
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) {
Expand Down
6 changes: 6 additions & 0 deletions src/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ export interface SerializedWalletPlugin {
data: WalletPluginData
}

/**
* Serialized form of a [[SerializedLoginContext]] instance.
*/

export type SerializedLoginContext = Record<string, any>

/**
* Interface which all 3rd party wallet plugins must implement.
*/
Expand Down
8 changes: 4 additions & 4 deletions test/tests/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,9 @@ 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({
assert.deepEqual(
serialized,
{
chain: '73e4385a2708e6d7048834fbc1079f2fabb17b3c125b146af438971e90716c4d',
actor: 'wharfkit1111',
permission: 'test',
Expand All @@ -421,7 +421,7 @@ suite('session', function () {
privateKey: 'PVT_K1_25XP1Lt1Rt87hyymouSieBbgnUEAerS1yQHi9wqHC2Uek2mgzH',
},
},
})
}
)
assert.doesNotThrow(() => {
JSON.stringify(serialized)
Expand Down
2 changes: 2 additions & 0 deletions test/tests/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ suite('walletPlugin', function () {
assert.deepEqual(response.session.serialize(), {
chain: '73e4385a2708e6d7048834fbc1079f2fabb17b3c125b146af438971e90716c4d',
actor: 'mock',
appName: 'demo.app',
permission: 'interface',
walletPlugin: {
id: 'MockWalletPluginConfigs',
Expand Down Expand Up @@ -361,6 +362,7 @@ suite('walletPlugin', function () {
assert.deepEqual(response.session.serialize(), {
chain: '73e4385a2708e6d7048834fbc1079f2fabb17b3c125b146af438971e90716c4d',
actor: 'mock',
appName: 'demo.app',
permission: 'interface',
walletPlugin: {
id: 'MockWalletPluginConfigs',
Expand Down

0 comments on commit a08ec17

Please sign in to comment.