@mysten-incubation/dev-wallet 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +250 -0
- package/dist/_virtual/_@oxc-project_runtime@0.107.0/helpers/decorate.mjs +10 -0
- package/dist/adapters/base-adapter.d.mts +33 -0
- package/dist/adapters/base-adapter.d.mts.map +1 -0
- package/dist/adapters/base-adapter.mjs +77 -0
- package/dist/adapters/base-adapter.mjs.map +1 -0
- package/dist/adapters/browser.d.mts +8 -0
- package/dist/adapters/browser.mjs +8 -0
- package/dist/adapters/build-managed-account.d.mts +12 -0
- package/dist/adapters/build-managed-account.d.mts.map +1 -0
- package/dist/adapters/build-managed-account.mjs +30 -0
- package/dist/adapters/build-managed-account.mjs.map +1 -0
- package/dist/adapters/idb-store.mjs +73 -0
- package/dist/adapters/idb-store.mjs.map +1 -0
- package/dist/adapters/in-memory-adapter.d.mts +16 -0
- package/dist/adapters/in-memory-adapter.d.mts.map +1 -0
- package/dist/adapters/in-memory-adapter.mjs +44 -0
- package/dist/adapters/in-memory-adapter.mjs.map +1 -0
- package/dist/adapters/passkey-adapter.d.mts +31 -0
- package/dist/adapters/passkey-adapter.d.mts.map +1 -0
- package/dist/adapters/passkey-adapter.mjs +87 -0
- package/dist/adapters/passkey-adapter.mjs.map +1 -0
- package/dist/adapters/remote-cli-adapter.d.mts +65 -0
- package/dist/adapters/remote-cli-adapter.d.mts.map +1 -0
- package/dist/adapters/remote-cli-adapter.mjs +299 -0
- package/dist/adapters/remote-cli-adapter.mjs.map +1 -0
- package/dist/adapters/webcrypto-adapter.d.mts +20 -0
- package/dist/adapters/webcrypto-adapter.d.mts.map +1 -0
- package/dist/adapters/webcrypto-adapter.mjs +68 -0
- package/dist/adapters/webcrypto-adapter.mjs.map +1 -0
- package/dist/bin/cli.d.mts +1 -0
- package/dist/bin/cli.mjs +183 -0
- package/dist/bin/cli.mjs.map +1 -0
- package/dist/client/dev-wallet-client.d.mts +57 -0
- package/dist/client/dev-wallet-client.d.mts.map +1 -0
- package/dist/client/dev-wallet-client.mjs +223 -0
- package/dist/client/dev-wallet-client.mjs.map +1 -0
- package/dist/client/index.d.mts +3 -0
- package/dist/client/index.mjs +4 -0
- package/dist/client/request-handler.d.mts +42 -0
- package/dist/client/request-handler.d.mts.map +1 -0
- package/dist/client/request-handler.mjs +115 -0
- package/dist/client/request-handler.mjs.map +1 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.mjs +4 -0
- package/dist/react/components.d.mts +32 -0
- package/dist/react/components.d.mts.map +1 -0
- package/dist/react/components.mjs +53 -0
- package/dist/react/components.mjs.map +1 -0
- package/dist/react/context.d.mts +22 -0
- package/dist/react/context.d.mts.map +1 -0
- package/dist/react/context.mjs +25 -0
- package/dist/react/context.mjs.map +1 -0
- package/dist/react/index.d.mts +4 -0
- package/dist/react/index.mjs +5 -0
- package/dist/react/useDevWallet.d.mts +38 -0
- package/dist/react/useDevWallet.d.mts.map +1 -0
- package/dist/react/useDevWallet.mjs +89 -0
- package/dist/react/useDevWallet.mjs.map +1 -0
- package/dist/server/cli-signing-middleware.d.mts +22 -0
- package/dist/server/cli-signing-middleware.d.mts.map +1 -0
- package/dist/server/cli-signing-middleware.mjs +117 -0
- package/dist/server/cli-signing-middleware.mjs.map +1 -0
- package/dist/server/index.d.mts +2 -0
- package/dist/server/index.mjs +3 -0
- package/dist/standalone/assets/in-memory-adapter-CBF4h2KD.js +1 -0
- package/dist/standalone/assets/main-VE4olb-Q.js +2841 -0
- package/dist/standalone/assets/webcrypto-adapter-DysAubFb.js +1 -0
- package/dist/standalone/bookmarklet.js +5 -0
- package/dist/standalone/index.html +48 -0
- package/dist/types.d.mts +55 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/ui/copy-controller.mjs +43 -0
- package/dist/ui/copy-controller.mjs.map +1 -0
- package/dist/ui/dev-wallet-account-selector.d.mts +24 -0
- package/dist/ui/dev-wallet-account-selector.d.mts.map +1 -0
- package/dist/ui/dev-wallet-account-selector.mjs +268 -0
- package/dist/ui/dev-wallet-account-selector.mjs.map +1 -0
- package/dist/ui/dev-wallet-accounts.d.mts +29 -0
- package/dist/ui/dev-wallet-accounts.d.mts.map +1 -0
- package/dist/ui/dev-wallet-accounts.mjs +524 -0
- package/dist/ui/dev-wallet-accounts.mjs.map +1 -0
- package/dist/ui/dev-wallet-balances.d.mts +26 -0
- package/dist/ui/dev-wallet-balances.d.mts.map +1 -0
- package/dist/ui/dev-wallet-balances.mjs +130 -0
- package/dist/ui/dev-wallet-balances.mjs.map +1 -0
- package/dist/ui/dev-wallet-connect.d.mts +31 -0
- package/dist/ui/dev-wallet-connect.d.mts.map +1 -0
- package/dist/ui/dev-wallet-connect.mjs +225 -0
- package/dist/ui/dev-wallet-connect.mjs.map +1 -0
- package/dist/ui/dev-wallet-dropdown.d.mts +27 -0
- package/dist/ui/dev-wallet-dropdown.d.mts.map +1 -0
- package/dist/ui/dev-wallet-dropdown.mjs +121 -0
- package/dist/ui/dev-wallet-dropdown.mjs.map +1 -0
- package/dist/ui/dev-wallet-network-badge.d.mts +21 -0
- package/dist/ui/dev-wallet-network-badge.d.mts.map +1 -0
- package/dist/ui/dev-wallet-network-badge.mjs +121 -0
- package/dist/ui/dev-wallet-network-badge.mjs.map +1 -0
- package/dist/ui/dev-wallet-new-account.d.mts +31 -0
- package/dist/ui/dev-wallet-new-account.d.mts.map +1 -0
- package/dist/ui/dev-wallet-new-account.mjs +577 -0
- package/dist/ui/dev-wallet-new-account.mjs.map +1 -0
- package/dist/ui/dev-wallet-objects.d.mts +26 -0
- package/dist/ui/dev-wallet-objects.d.mts.map +1 -0
- package/dist/ui/dev-wallet-objects.mjs +276 -0
- package/dist/ui/dev-wallet-objects.mjs.map +1 -0
- package/dist/ui/dev-wallet-panel.d.mts +22 -0
- package/dist/ui/dev-wallet-panel.d.mts.map +1 -0
- package/dist/ui/dev-wallet-panel.mjs +192 -0
- package/dist/ui/dev-wallet-panel.mjs.map +1 -0
- package/dist/ui/dev-wallet-popup.d.mts +36 -0
- package/dist/ui/dev-wallet-popup.d.mts.map +1 -0
- package/dist/ui/dev-wallet-popup.mjs +137 -0
- package/dist/ui/dev-wallet-popup.mjs.map +1 -0
- package/dist/ui/dev-wallet-settings.d.mts +33 -0
- package/dist/ui/dev-wallet-settings.d.mts.map +1 -0
- package/dist/ui/dev-wallet-settings.mjs +635 -0
- package/dist/ui/dev-wallet-settings.mjs.map +1 -0
- package/dist/ui/dev-wallet-signing-modal.d.mts +32 -0
- package/dist/ui/dev-wallet-signing-modal.d.mts.map +1 -0
- package/dist/ui/dev-wallet-signing-modal.mjs +115 -0
- package/dist/ui/dev-wallet-signing-modal.mjs.map +1 -0
- package/dist/ui/dev-wallet-signing.d.mts +25 -0
- package/dist/ui/dev-wallet-signing.d.mts.map +1 -0
- package/dist/ui/dev-wallet-signing.mjs +544 -0
- package/dist/ui/dev-wallet-signing.mjs.map +1 -0
- package/dist/ui/dev-wallet-standalone.d.mts +23 -0
- package/dist/ui/dev-wallet-standalone.d.mts.map +1 -0
- package/dist/ui/dev-wallet-standalone.mjs +129 -0
- package/dist/ui/dev-wallet-standalone.mjs.map +1 -0
- package/dist/ui/dev-wallet-tab-bar.d.mts +19 -0
- package/dist/ui/dev-wallet-tab-bar.d.mts.map +1 -0
- package/dist/ui/dev-wallet-tab-bar.mjs +143 -0
- package/dist/ui/dev-wallet-tab-bar.mjs.map +1 -0
- package/dist/ui/index.d.mts +17 -0
- package/dist/ui/index.mjs +18 -0
- package/dist/ui/mount.d.mts +11 -0
- package/dist/ui/mount.d.mts.map +1 -0
- package/dist/ui/mount.mjs +17 -0
- package/dist/ui/mount.mjs.map +1 -0
- package/dist/ui/styles.mjs +250 -0
- package/dist/ui/styles.mjs.map +1 -0
- package/dist/ui/transaction-analyzer.mjs +58 -0
- package/dist/ui/transaction-analyzer.mjs.map +1 -0
- package/dist/ui/utils.mjs +98 -0
- package/dist/ui/utils.mjs.map +1 -0
- package/dist/ui/wallet-controller.mjs +275 -0
- package/dist/ui/wallet-controller.mjs.map +1 -0
- package/dist/wallet/constants.mjs +11 -0
- package/dist/wallet/constants.mjs.map +1 -0
- package/dist/wallet/dev-wallet.d.mts +118 -0
- package/dist/wallet/dev-wallet.d.mts.map +1 -0
- package/dist/wallet/dev-wallet.mjs +424 -0
- package/dist/wallet/dev-wallet.mjs.map +1 -0
- package/dist/wallet/initializer.d.mts +63 -0
- package/dist/wallet/initializer.d.mts.map +1 -0
- package/dist/wallet/initializer.mjs +75 -0
- package/dist/wallet/initializer.mjs.map +1 -0
- package/dist/wallet/signing.d.mts +35 -0
- package/dist/wallet/signing.d.mts.map +1 -0
- package/dist/wallet/signing.mjs +69 -0
- package/dist/wallet/signing.mjs.map +1 -0
- package/package.json +124 -0
- package/src/adapters/base-adapter.ts +93 -0
- package/src/adapters/browser.ts +15 -0
- package/src/adapters/build-managed-account.ts +33 -0
- package/src/adapters/idb-store.ts +87 -0
- package/src/adapters/in-memory-adapter.ts +51 -0
- package/src/adapters/passkey-adapter.ts +120 -0
- package/src/adapters/remote-cli-adapter.ts +388 -0
- package/src/adapters/webcrypto-adapter.ts +96 -0
- package/src/app/bookmarklet-entry.ts +77 -0
- package/src/app/index.html +48 -0
- package/src/app/main.ts +245 -0
- package/src/app/tsconfig.json +3 -0
- package/src/bin/cli.ts +214 -0
- package/src/client/dev-wallet-client.ts +280 -0
- package/src/client/index.ts +7 -0
- package/src/client/request-handler.ts +161 -0
- package/src/index.ts +19 -0
- package/src/react/components.ts +64 -0
- package/src/react/context.ts +38 -0
- package/src/react/index.ts +16 -0
- package/src/react/useDevWallet.ts +118 -0
- package/src/server/cli-signing-middleware.ts +146 -0
- package/src/server/index.ts +8 -0
- package/src/types.ts +58 -0
- package/src/ui/copy-controller.ts +49 -0
- package/src/ui/dev-wallet-account-selector.ts +283 -0
- package/src/ui/dev-wallet-accounts.ts +578 -0
- package/src/ui/dev-wallet-balances.ts +171 -0
- package/src/ui/dev-wallet-connect.ts +259 -0
- package/src/ui/dev-wallet-dropdown.ts +138 -0
- package/src/ui/dev-wallet-network-badge.ts +128 -0
- package/src/ui/dev-wallet-new-account.ts +662 -0
- package/src/ui/dev-wallet-objects.ts +336 -0
- package/src/ui/dev-wallet-panel.ts +207 -0
- package/src/ui/dev-wallet-popup.ts +169 -0
- package/src/ui/dev-wallet-settings.ts +692 -0
- package/src/ui/dev-wallet-signing-modal.ts +137 -0
- package/src/ui/dev-wallet-signing.ts +624 -0
- package/src/ui/dev-wallet-standalone.ts +136 -0
- package/src/ui/dev-wallet-tab-bar.ts +151 -0
- package/src/ui/index.ts +26 -0
- package/src/ui/mount.ts +21 -0
- package/src/ui/styles.ts +252 -0
- package/src/ui/transaction-analyzer.ts +60 -0
- package/src/ui/utils.ts +118 -0
- package/src/ui/wallet-controller.ts +340 -0
- package/src/wallet/constants.ts +17 -0
- package/src/wallet/dev-wallet.ts +597 -0
- package/src/wallet/initializer.ts +124 -0
- package/src/wallet/signing.ts +85 -0
|
@@ -0,0 +1,624 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { bcs } from '@mysten/sui/bcs';
|
|
5
|
+
import type { ClientWithCoreApi } from '@mysten/sui/client';
|
|
6
|
+
import type { AnalyzedCommand } from '@mysten/wallet-sdk';
|
|
7
|
+
import { css, html, LitElement, nothing } from 'lit';
|
|
8
|
+
import { customElement, property, state } from 'lit/decorators.js';
|
|
9
|
+
|
|
10
|
+
import type { PendingSigningRequest } from '../wallet/dev-wallet.js';
|
|
11
|
+
import { CopyController } from './copy-controller.js';
|
|
12
|
+
import { actionButtonStyles, sharedStyles } from './styles.js';
|
|
13
|
+
import type { TransactionAnalysis } from './transaction-analyzer.js';
|
|
14
|
+
import { analyzeTransaction } from './transaction-analyzer.js';
|
|
15
|
+
import { emitEvent, formatAddress, formatCoinBalance, getCoinSymbol } from './utils.js';
|
|
16
|
+
|
|
17
|
+
const REQUEST_TYPE_LABELS: Record<PendingSigningRequest['type'], string> = {
|
|
18
|
+
'sign-personal-message': 'Sign Message',
|
|
19
|
+
'sign-transaction': 'Sign Transaction',
|
|
20
|
+
'sign-and-execute-transaction': 'Sign & Execute Transaction',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
@customElement('dev-wallet-signing')
|
|
24
|
+
export class DevWalletSigning extends LitElement {
|
|
25
|
+
static override styles = [
|
|
26
|
+
sharedStyles,
|
|
27
|
+
actionButtonStyles,
|
|
28
|
+
css`
|
|
29
|
+
:host {
|
|
30
|
+
display: flex;
|
|
31
|
+
flex-direction: column;
|
|
32
|
+
overflow: hidden;
|
|
33
|
+
min-height: 0;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.signing-content {
|
|
37
|
+
flex: 1;
|
|
38
|
+
overflow-y: auto;
|
|
39
|
+
padding: 16px;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.signing-footer {
|
|
43
|
+
padding: 12px 16px;
|
|
44
|
+
border-top: 1px solid var(--dev-wallet-border);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.signing-header {
|
|
48
|
+
display: flex;
|
|
49
|
+
align-items: center;
|
|
50
|
+
gap: 8px;
|
|
51
|
+
margin-bottom: 12px;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.signing-badge {
|
|
55
|
+
display: inline-block;
|
|
56
|
+
width: 8px;
|
|
57
|
+
height: 8px;
|
|
58
|
+
border-radius: 50%;
|
|
59
|
+
background: var(--dev-wallet-warning);
|
|
60
|
+
animation: pulse 2s infinite;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@keyframes pulse {
|
|
64
|
+
0%,
|
|
65
|
+
100% {
|
|
66
|
+
opacity: 1;
|
|
67
|
+
}
|
|
68
|
+
50% {
|
|
69
|
+
opacity: 0.5;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.signing-title {
|
|
74
|
+
font-size: 14px;
|
|
75
|
+
font-weight: var(--dev-wallet-font-weight-semibold);
|
|
76
|
+
color: var(--dev-wallet-foreground);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.request-type {
|
|
80
|
+
font-size: 13px;
|
|
81
|
+
color: var(--dev-wallet-primary);
|
|
82
|
+
font-weight: var(--dev-wallet-font-weight-medium);
|
|
83
|
+
margin-bottom: 8px;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.request-detail {
|
|
87
|
+
display: flex;
|
|
88
|
+
justify-content: space-between;
|
|
89
|
+
padding: 6px 0;
|
|
90
|
+
font-size: 12px;
|
|
91
|
+
border-bottom: 1px solid var(--dev-wallet-border);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.request-detail:last-of-type {
|
|
95
|
+
border-bottom: none;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.detail-label {
|
|
99
|
+
color: var(--dev-wallet-muted-foreground);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.detail-value {
|
|
103
|
+
color: var(--dev-wallet-foreground);
|
|
104
|
+
font-family: var(--dev-wallet-font-mono);
|
|
105
|
+
max-width: 220px;
|
|
106
|
+
overflow: hidden;
|
|
107
|
+
text-overflow: ellipsis;
|
|
108
|
+
white-space: nowrap;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.detail-value.copyable-addr {
|
|
112
|
+
cursor: pointer;
|
|
113
|
+
border-radius: var(--dev-wallet-radius-2xs);
|
|
114
|
+
padding: 1px 3px;
|
|
115
|
+
transition: background 0.15s;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.detail-value.copyable-addr:hover {
|
|
119
|
+
background: color-mix(in oklab, var(--dev-wallet-primary) 15%, transparent);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.detail-value.copied {
|
|
123
|
+
color: var(--dev-wallet-positive);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.detail-secondary {
|
|
127
|
+
color: var(--dev-wallet-muted-foreground);
|
|
128
|
+
font-size: 0.85em;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.request-data {
|
|
132
|
+
margin: 12px 0;
|
|
133
|
+
padding: 8px;
|
|
134
|
+
border-radius: var(--dev-wallet-radius-xs);
|
|
135
|
+
background: var(--dev-wallet-background);
|
|
136
|
+
font-family: var(--dev-wallet-font-mono);
|
|
137
|
+
font-size: 11px;
|
|
138
|
+
color: var(--dev-wallet-muted-foreground);
|
|
139
|
+
max-height: 80px;
|
|
140
|
+
overflow-y: auto;
|
|
141
|
+
word-break: break-all;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.section-label {
|
|
145
|
+
font-size: 11px;
|
|
146
|
+
font-weight: var(--dev-wallet-font-weight-semibold);
|
|
147
|
+
color: var(--dev-wallet-muted-foreground);
|
|
148
|
+
text-transform: uppercase;
|
|
149
|
+
letter-spacing: 0.5px;
|
|
150
|
+
margin: 12px 0 6px;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.coin-flows {
|
|
154
|
+
display: flex;
|
|
155
|
+
flex-direction: column;
|
|
156
|
+
gap: 4px;
|
|
157
|
+
margin-bottom: 4px;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
.coin-flow-item {
|
|
161
|
+
display: flex;
|
|
162
|
+
justify-content: space-between;
|
|
163
|
+
align-items: center;
|
|
164
|
+
padding: 8px;
|
|
165
|
+
border-radius: var(--dev-wallet-radius-xs);
|
|
166
|
+
background: var(--dev-wallet-background);
|
|
167
|
+
font-size: 12px;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.coin-flow-type {
|
|
171
|
+
color: var(--dev-wallet-muted-foreground);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
.coin-flow-amount {
|
|
175
|
+
font-family: var(--dev-wallet-font-mono);
|
|
176
|
+
font-weight: var(--dev-wallet-font-weight-semibold);
|
|
177
|
+
color: var(--dev-wallet-destructive);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
.commands-list {
|
|
181
|
+
display: flex;
|
|
182
|
+
flex-direction: column;
|
|
183
|
+
gap: 4px;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
.command-item {
|
|
187
|
+
padding: 8px;
|
|
188
|
+
border-radius: var(--dev-wallet-radius-xs);
|
|
189
|
+
background: var(--dev-wallet-background);
|
|
190
|
+
font-size: 12px;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
.command-kind {
|
|
194
|
+
font-weight: var(--dev-wallet-font-weight-semibold);
|
|
195
|
+
color: var(--dev-wallet-primary);
|
|
196
|
+
margin-bottom: 2px;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
.command-detail {
|
|
200
|
+
color: var(--dev-wallet-muted-foreground);
|
|
201
|
+
font-family: var(--dev-wallet-font-mono);
|
|
202
|
+
font-size: 11px;
|
|
203
|
+
overflow: hidden;
|
|
204
|
+
text-overflow: ellipsis;
|
|
205
|
+
white-space: nowrap;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
.command-args {
|
|
209
|
+
margin-top: 4px;
|
|
210
|
+
padding-left: 8px;
|
|
211
|
+
border-left: 2px solid var(--dev-wallet-border);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
.command-arg {
|
|
215
|
+
font-size: 11px;
|
|
216
|
+
color: var(--dev-wallet-muted-foreground);
|
|
217
|
+
font-family: var(--dev-wallet-font-mono);
|
|
218
|
+
padding: 1px 0;
|
|
219
|
+
overflow: hidden;
|
|
220
|
+
text-overflow: ellipsis;
|
|
221
|
+
white-space: nowrap;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
.arg-access {
|
|
225
|
+
font-size: 10px;
|
|
226
|
+
padding: 1px 4px;
|
|
227
|
+
border-radius: var(--dev-wallet-radius-2xs);
|
|
228
|
+
font-weight: var(--dev-wallet-font-weight-medium);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
.arg-access-read {
|
|
232
|
+
background: color-mix(in oklab, var(--dev-wallet-primary) 20%, transparent);
|
|
233
|
+
color: var(--dev-wallet-primary);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
.arg-access-mutate {
|
|
237
|
+
background: color-mix(in oklab, var(--dev-wallet-warning) 20%, transparent);
|
|
238
|
+
color: var(--dev-wallet-warning);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
.arg-access-transfer {
|
|
242
|
+
background: color-mix(in oklab, var(--dev-wallet-destructive) 20%, transparent);
|
|
243
|
+
color: var(--dev-wallet-destructive);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
.error-state {
|
|
247
|
+
padding: 10px;
|
|
248
|
+
border-radius: var(--dev-wallet-radius-xs);
|
|
249
|
+
background: color-mix(in oklab, var(--dev-wallet-destructive) 10%, transparent);
|
|
250
|
+
color: var(--dev-wallet-destructive);
|
|
251
|
+
font-size: 12px;
|
|
252
|
+
word-break: break-word;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
.section-label-error {
|
|
256
|
+
color: var(--dev-wallet-destructive);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
.error-title {
|
|
260
|
+
font-weight: var(--dev-wallet-font-weight-semibold);
|
|
261
|
+
margin-bottom: 4px;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
.error-body {
|
|
265
|
+
margin-bottom: 6px;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
.error-hint {
|
|
269
|
+
font-size: 11px;
|
|
270
|
+
opacity: 0.8;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
.no-request {
|
|
274
|
+
text-align: center;
|
|
275
|
+
padding: 20px;
|
|
276
|
+
color: var(--dev-wallet-muted-foreground);
|
|
277
|
+
font-size: 13px;
|
|
278
|
+
}
|
|
279
|
+
`,
|
|
280
|
+
];
|
|
281
|
+
|
|
282
|
+
@property({ attribute: false })
|
|
283
|
+
request: PendingSigningRequest | null = null;
|
|
284
|
+
|
|
285
|
+
@property({ attribute: false })
|
|
286
|
+
client: ClientWithCoreApi | null = null;
|
|
287
|
+
|
|
288
|
+
@state()
|
|
289
|
+
private _analysis: TransactionAnalysis | null = null;
|
|
290
|
+
|
|
291
|
+
@state()
|
|
292
|
+
private _analysisError: string | null = null;
|
|
293
|
+
|
|
294
|
+
@state()
|
|
295
|
+
private _analyzing = false;
|
|
296
|
+
|
|
297
|
+
#copy = new CopyController(this);
|
|
298
|
+
#analysisGeneration = 0;
|
|
299
|
+
#coinDecimalsCache = new Map<string, number>();
|
|
300
|
+
|
|
301
|
+
override willUpdate(changedProperties: Map<string, unknown>) {
|
|
302
|
+
if (changedProperties.has('request')) {
|
|
303
|
+
this._analysis = null;
|
|
304
|
+
this._analysisError = null;
|
|
305
|
+
this._analyzing = false;
|
|
306
|
+
if (this.request && this.request.type !== 'sign-personal-message') {
|
|
307
|
+
this.#analyzeTransaction();
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
async #analyzeTransaction() {
|
|
313
|
+
if (!this.request || typeof this.request.data !== 'string') return;
|
|
314
|
+
|
|
315
|
+
this._analyzing = true;
|
|
316
|
+
const generation = ++this.#analysisGeneration;
|
|
317
|
+
|
|
318
|
+
const result = await analyzeTransaction(this.request.data, this.client);
|
|
319
|
+
if (generation !== this.#analysisGeneration) return;
|
|
320
|
+
|
|
321
|
+
if (result.kind === 'rich') {
|
|
322
|
+
this._analysis = result.analysis;
|
|
323
|
+
// Fetch coin metadata for all coin types in flows
|
|
324
|
+
if (this.client && result.analysis.coinFlows?.length) {
|
|
325
|
+
const coinTypes = [...new Set(result.analysis.coinFlows.map((f) => f.coinType))];
|
|
326
|
+
await Promise.all(
|
|
327
|
+
coinTypes
|
|
328
|
+
.filter((ct) => !this.#coinDecimalsCache.has(ct))
|
|
329
|
+
.map(async (ct) => {
|
|
330
|
+
try {
|
|
331
|
+
const { coinMetadata } = await this.client!.core.getCoinMetadata({
|
|
332
|
+
coinType: ct,
|
|
333
|
+
});
|
|
334
|
+
if (coinMetadata) {
|
|
335
|
+
this.#coinDecimalsCache.set(ct, coinMetadata.decimals);
|
|
336
|
+
}
|
|
337
|
+
} catch {
|
|
338
|
+
// leave uncached — will use 0 as fallback
|
|
339
|
+
}
|
|
340
|
+
}),
|
|
341
|
+
);
|
|
342
|
+
if (generation !== this.#analysisGeneration) return;
|
|
343
|
+
this.requestUpdate();
|
|
344
|
+
}
|
|
345
|
+
} else {
|
|
346
|
+
this._analysisError = result.message;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
this._analyzing = false;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
override render() {
|
|
353
|
+
if (!this.request) {
|
|
354
|
+
return html`<div class="no-request" part="empty-state">No pending requests</div>`;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
const typeLabel = REQUEST_TYPE_LABELS[this.request.type];
|
|
358
|
+
|
|
359
|
+
// For transactions: only allow approval after successful analysis
|
|
360
|
+
// For personal messages: always allow (no analysis needed)
|
|
361
|
+
const isTransaction = this.request.type !== 'sign-personal-message';
|
|
362
|
+
const canApprove = isTransaction
|
|
363
|
+
? this._analysis !== null && !this._analysisError && !this._analyzing
|
|
364
|
+
: true;
|
|
365
|
+
|
|
366
|
+
return html`
|
|
367
|
+
<div class="signing-content">
|
|
368
|
+
<div class="signing-header">
|
|
369
|
+
<span class="signing-badge"></span>
|
|
370
|
+
<span class="signing-title">Approval Required</span>
|
|
371
|
+
</div>
|
|
372
|
+
|
|
373
|
+
<div class="request-type" part="request-type">${typeLabel}</div>
|
|
374
|
+
|
|
375
|
+
<div class="request-detail">
|
|
376
|
+
<span class="detail-label">Account</span>
|
|
377
|
+
<span
|
|
378
|
+
class="detail-value copyable-addr ${this.#copy.isCopied(this.request.account.address)
|
|
379
|
+
? 'copied'
|
|
380
|
+
: ''}"
|
|
381
|
+
title="Click to copy"
|
|
382
|
+
role="button"
|
|
383
|
+
tabindex="0"
|
|
384
|
+
aria-label="Copy account address"
|
|
385
|
+
@click=${() => this.#copy.copy(this.request!.account.address)}
|
|
386
|
+
@keydown=${(e: KeyboardEvent) => {
|
|
387
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
388
|
+
e.preventDefault();
|
|
389
|
+
this.#copy.copy(this.request!.account.address);
|
|
390
|
+
}
|
|
391
|
+
}}
|
|
392
|
+
>
|
|
393
|
+
${this.#copy.isCopied(this.request.account.address)
|
|
394
|
+
? 'Copied!'
|
|
395
|
+
: this.request.account.label
|
|
396
|
+
? html`${this.request.account.label}
|
|
397
|
+
<span class="detail-secondary"
|
|
398
|
+
>${formatAddress(this.request.account.address)}</span
|
|
399
|
+
>`
|
|
400
|
+
: formatAddress(this.request.account.address)}
|
|
401
|
+
</span>
|
|
402
|
+
</div>
|
|
403
|
+
${isTransaction
|
|
404
|
+
? html`<div class="request-detail">
|
|
405
|
+
<span class="detail-label">Chain</span>
|
|
406
|
+
<span class="detail-value">${this.request.chain}</span>
|
|
407
|
+
</div>`
|
|
408
|
+
: nothing}
|
|
409
|
+
${this.#renderTransactionPreview()}
|
|
410
|
+
</div>
|
|
411
|
+
<div class="signing-footer" part="footer">
|
|
412
|
+
<div class="actions">
|
|
413
|
+
<button class="btn btn-reject" part="reject-button" @click=${this.#reject}>Reject</button>
|
|
414
|
+
${canApprove
|
|
415
|
+
? html`<button class="btn btn-approve" part="approve-button" @click=${this.#approve}>
|
|
416
|
+
Approve
|
|
417
|
+
</button>`
|
|
418
|
+
: nothing}
|
|
419
|
+
</div>
|
|
420
|
+
</div>
|
|
421
|
+
`;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
#renderTransactionPreview() {
|
|
425
|
+
if (this._analyzing) {
|
|
426
|
+
return html`<div class="section-label">Analyzing transaction...</div>`;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
if (this._analysisError) {
|
|
430
|
+
return html`
|
|
431
|
+
<div class="section-label section-label-error">Analysis Failed</div>
|
|
432
|
+
<div class="error-state" part="error-message">
|
|
433
|
+
<div class="error-title">Unable to analyze this transaction</div>
|
|
434
|
+
<div class="error-body">${this._analysisError}</div>
|
|
435
|
+
<div class="error-hint">
|
|
436
|
+
The transaction cannot be approved without successful analysis. Check that the network
|
|
437
|
+
is reachable and the transaction is well-formed.
|
|
438
|
+
</div>
|
|
439
|
+
</div>
|
|
440
|
+
`;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
if (this._analysis) {
|
|
444
|
+
return html`
|
|
445
|
+
${this.#renderCoinFlows()} ${this.#renderAnalyzedCommands(this._analysis.commands)}
|
|
446
|
+
`;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
const dataPreview = this.#getDataPreview();
|
|
450
|
+
return dataPreview ? html`<div class="request-data">${dataPreview}</div>` : nothing;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
#renderCoinFlows() {
|
|
454
|
+
const flows = this._analysis?.coinFlows;
|
|
455
|
+
if (!flows || flows.length === 0) return nothing;
|
|
456
|
+
|
|
457
|
+
return html`
|
|
458
|
+
<div class="section-label">Estimated Cost</div>
|
|
459
|
+
<div class="coin-flows">
|
|
460
|
+
${flows.map((flow) => {
|
|
461
|
+
const decimals = this.#coinDecimalsCache.get(flow.coinType) ?? 0;
|
|
462
|
+
const formatted = formatCoinBalance(flow.amount, decimals);
|
|
463
|
+
return html`
|
|
464
|
+
<div class="coin-flow-item">
|
|
465
|
+
<span class="coin-flow-type">${getCoinSymbol(flow.coinType)}</span>
|
|
466
|
+
<span class="coin-flow-amount"> -${formatted} </span>
|
|
467
|
+
</div>
|
|
468
|
+
`;
|
|
469
|
+
})}
|
|
470
|
+
</div>
|
|
471
|
+
`;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
#renderAnalyzedCommands(commands: AnalyzedCommand[]) {
|
|
475
|
+
return html`
|
|
476
|
+
<div class="section-label">Commands</div>
|
|
477
|
+
<div class="commands-list">${commands.map((cmd) => this.#renderAnalyzedCommand(cmd))}</div>
|
|
478
|
+
`;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
#renderAnalyzedCommand(cmd: AnalyzedCommand) {
|
|
482
|
+
switch (cmd.$kind) {
|
|
483
|
+
case 'MoveCall':
|
|
484
|
+
return html`
|
|
485
|
+
<div class="command-item">
|
|
486
|
+
<div class="command-kind">MoveCall</div>
|
|
487
|
+
<div class="command-detail">
|
|
488
|
+
${cmd.function.packageId}::${cmd.function.moduleName}::${cmd.function.name}
|
|
489
|
+
</div>
|
|
490
|
+
${cmd.arguments.length > 0 ? this.#renderArgs(cmd.arguments) : nothing}
|
|
491
|
+
</div>
|
|
492
|
+
`;
|
|
493
|
+
case 'TransferObjects':
|
|
494
|
+
return html`
|
|
495
|
+
<div class="command-item">
|
|
496
|
+
<div class="command-kind">TransferObjects</div>
|
|
497
|
+
<div class="command-detail">
|
|
498
|
+
${cmd.objects.length} object${cmd.objects.length !== 1 ? 's' : ''}
|
|
499
|
+
${cmd.address.$kind === 'Pure'
|
|
500
|
+
? html` → ${formatAddress(this.#decodePureAddress(cmd.address))}`
|
|
501
|
+
: nothing}
|
|
502
|
+
</div>
|
|
503
|
+
</div>
|
|
504
|
+
`;
|
|
505
|
+
case 'SplitCoins':
|
|
506
|
+
return html`
|
|
507
|
+
<div class="command-item">
|
|
508
|
+
<div class="command-kind">SplitCoins</div>
|
|
509
|
+
<div class="command-detail">
|
|
510
|
+
${cmd.amounts.length} split${cmd.amounts.length !== 1 ? 's' : ''} from
|
|
511
|
+
${cmd.coin.$kind === 'GasCoin' ? 'gas coin' : 'coin'}
|
|
512
|
+
</div>
|
|
513
|
+
</div>
|
|
514
|
+
`;
|
|
515
|
+
case 'MergeCoins':
|
|
516
|
+
return html`
|
|
517
|
+
<div class="command-item">
|
|
518
|
+
<div class="command-kind">MergeCoins</div>
|
|
519
|
+
<div class="command-detail">
|
|
520
|
+
${cmd.sources.length} source${cmd.sources.length !== 1 ? 's' : ''}
|
|
521
|
+
</div>
|
|
522
|
+
</div>
|
|
523
|
+
`;
|
|
524
|
+
case 'Publish':
|
|
525
|
+
return html`
|
|
526
|
+
<div class="command-item">
|
|
527
|
+
<div class="command-kind">Publish</div>
|
|
528
|
+
<div class="command-detail">New package</div>
|
|
529
|
+
</div>
|
|
530
|
+
`;
|
|
531
|
+
case 'Upgrade':
|
|
532
|
+
return html`
|
|
533
|
+
<div class="command-item">
|
|
534
|
+
<div class="command-kind">Upgrade</div>
|
|
535
|
+
<div class="command-detail">Package upgrade</div>
|
|
536
|
+
</div>
|
|
537
|
+
`;
|
|
538
|
+
default:
|
|
539
|
+
return html`
|
|
540
|
+
<div class="command-item">
|
|
541
|
+
<div class="command-kind">${cmd.$kind}</div>
|
|
542
|
+
</div>
|
|
543
|
+
`;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
#renderArgs(args: import('@mysten/wallet-sdk').AnalyzedCommandArgument[]) {
|
|
548
|
+
return html`
|
|
549
|
+
<div class="command-args">
|
|
550
|
+
${args.map(
|
|
551
|
+
(arg) => html`
|
|
552
|
+
<div class="command-arg">
|
|
553
|
+
<span class="arg-access arg-access-${arg.accessLevel}">${arg.accessLevel}</span>
|
|
554
|
+
${this.#describeArg(arg)}
|
|
555
|
+
</div>
|
|
556
|
+
`,
|
|
557
|
+
)}
|
|
558
|
+
</div>
|
|
559
|
+
`;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
#describeArg(arg: import('@mysten/wallet-sdk').AnalyzedCommandArgument): string {
|
|
563
|
+
switch (arg.$kind) {
|
|
564
|
+
case 'GasCoin':
|
|
565
|
+
return 'Gas Coin';
|
|
566
|
+
case 'Result':
|
|
567
|
+
return `Result [${arg.index[0]}, ${arg.index[1]}]`;
|
|
568
|
+
case 'Pure':
|
|
569
|
+
return `${arg.bytes.slice(0, 16)}${arg.bytes.length > 16 ? '...' : ''}`;
|
|
570
|
+
case 'Object':
|
|
571
|
+
return formatAddress(arg.object.objectId);
|
|
572
|
+
case 'Unknown':
|
|
573
|
+
return 'unknown';
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
#decodePureAddress(arg: import('@mysten/wallet-sdk').AnalyzedCommandArgument): string {
|
|
578
|
+
if (arg.$kind === 'Pure') {
|
|
579
|
+
try {
|
|
580
|
+
return bcs.Address.fromBase64(arg.bytes);
|
|
581
|
+
} catch {
|
|
582
|
+
// fall through
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
return '?';
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
#getDataPreview(): string | null {
|
|
589
|
+
if (!this.request) return null;
|
|
590
|
+
|
|
591
|
+
if (this.request.type === 'sign-personal-message') {
|
|
592
|
+
const data = this.request.data;
|
|
593
|
+
if (data instanceof Uint8Array) {
|
|
594
|
+
try {
|
|
595
|
+
return new TextDecoder().decode(data);
|
|
596
|
+
} catch {
|
|
597
|
+
return `[${data.length} bytes]`;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
if (typeof this.request.data === 'string') {
|
|
603
|
+
return this.request.data.length > 200
|
|
604
|
+
? this.request.data.slice(0, 200) + '...'
|
|
605
|
+
: this.request.data;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
return null;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
#approve() {
|
|
612
|
+
emitEvent(this, 'approve');
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
#reject() {
|
|
616
|
+
emitEvent(this, 'reject');
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
declare global {
|
|
621
|
+
interface HTMLElementTagNameMap {
|
|
622
|
+
'dev-wallet-signing': DevWalletSigning;
|
|
623
|
+
}
|
|
624
|
+
}
|