forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wallet-ext: add hasPermissions and requestPermissions to dapp interface
- Loading branch information
1 parent
1c6eae3
commit b2d9e8d
Showing
10 changed files
with
206 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
wallet/src/shared/messaging/messages/payloads/permissions/AcquirePermissionsRequest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { isBasePayload } from '_payloads'; | ||
|
||
import type { PermissionType } from './PermissionType'; | ||
import type { BasePayload, Payload } from '_payloads'; | ||
|
||
export interface AcquirePermissionsRequest extends BasePayload { | ||
type: 'acquire-permissions-request'; | ||
permissions: readonly PermissionType[]; | ||
} | ||
|
||
export function isAcquirePermissionsRequest( | ||
payload: Payload | ||
): payload is AcquirePermissionsRequest { | ||
return ( | ||
isBasePayload(payload) && payload.type === 'acquire-permissions-request' | ||
); | ||
} |
20 changes: 20 additions & 0 deletions
20
wallet/src/shared/messaging/messages/payloads/permissions/AcquirePermissionsResponse.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { isBasePayload } from '_payloads'; | ||
|
||
import type { BasePayload, Payload } from '_payloads'; | ||
|
||
export interface AcquirePermissionsResponse extends BasePayload { | ||
type: 'acquire-permissions-response'; | ||
result: boolean; | ||
} | ||
|
||
export function isAcquirePermissionsResponse( | ||
payload: Payload | ||
): payload is AcquirePermissionsResponse { | ||
return ( | ||
isBasePayload(payload) && | ||
payload.type === 'acquire-permissions-response' | ||
); | ||
} |
18 changes: 18 additions & 0 deletions
18
wallet/src/shared/messaging/messages/payloads/permissions/HasPermissionsRequest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { isBasePayload } from '_payloads'; | ||
|
||
import type { PermissionType } from './PermissionType'; | ||
import type { BasePayload, Payload } from '_payloads'; | ||
|
||
export interface HasPermissionsRequest extends BasePayload { | ||
type: 'has-permissions-request'; | ||
permissions: readonly PermissionType[]; | ||
} | ||
|
||
export function isHasPermissionRequest( | ||
payload: Payload | ||
): payload is HasPermissionsRequest { | ||
return isBasePayload(payload) && payload.type === 'has-permissions-request'; | ||
} |
19 changes: 19 additions & 0 deletions
19
wallet/src/shared/messaging/messages/payloads/permissions/HasPermissionsResponse.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { isBasePayload } from '_payloads'; | ||
|
||
import type { BasePayload, Payload } from '_payloads'; | ||
|
||
export interface HasPermissionsResponse extends BasePayload { | ||
type: 'has-permissions-response'; | ||
result: boolean; | ||
} | ||
|
||
export function isHasPermissionResponse( | ||
payload: Payload | ||
): payload is HasPermissionsResponse { | ||
return ( | ||
isBasePayload(payload) && payload.type === 'has-permissions-response' | ||
); | ||
} |
7 changes: 6 additions & 1 deletion
7
wallet/src/shared/messaging/messages/payloads/permissions/PermissionType.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export type PermissionType = 'viewAccount' | 'suggestTransactions'; | ||
export const ALL_PERMISSION_TYPES = [ | ||
'viewAccount', | ||
'suggestTransactions', | ||
] as const; | ||
type AllPermissionsType = typeof ALL_PERMISSION_TYPES; | ||
export type PermissionType = AllPermissionsType[number]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters