-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathencoded.ts
More file actions
35 lines (32 loc) · 1.24 KB
/
encoded.ts
File metadata and controls
35 lines (32 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import {Checksum256, Name, Struct} from '@wharfkit/antelope'
import {SerializedSession, Session} from './index-module'
/**
* The metadata of an [[AccountCreationPlugin]].
*/
@Struct.type('url_encoded_session')
export class URLEncodedSession extends Struct {
@Struct.field(Checksum256) declare chain: Checksum256
@Struct.field(Name) declare actor: Name
@Struct.field(Name) declare permission: Name
@Struct.field('string') declare walletPlugin: string
@Struct.field('string', {optional: true}) declare data?: string
static fromSession(data: Session | SerializedSession): URLEncodedSession {
const session = data instanceof Session ? data.serialize() : data
return new URLEncodedSession({
chain: session.chain,
actor: session.actor,
permission: session.permission,
walletPlugin: JSON.stringify(session.walletPlugin),
data: JSON.stringify(session.data),
})
}
get serialized(): SerializedSession {
return {
chain: this.chain,
actor: this.actor,
permission: this.permission,
walletPlugin: JSON.parse(this.walletPlugin),
data: this.data ? JSON.parse(this.data) : undefined,
}
}
}