|
1 | 1 | import { createHash } from 'crypto'; |
| 2 | +import { buildBtdWalletBtdSupportProjection } from '@bitcode/btd'; |
2 | 3 |
|
3 | 4 | export const AUXILLARY_FLOW_STEPS = ['wallet', 'externals', 'profile', 'interfaces'] as const; |
4 | 5 | export const AUXILLARIES_CONTRACT_VERSION = 'v31-draft-auxillaries-contracts' as const; |
@@ -85,6 +86,9 @@ export interface AuxillaryBtdAssetPackSummary { |
85 | 86 | label?: string; |
86 | 87 | rangeStart?: number; |
87 | 88 | rangeEndExclusive?: number; |
| 89 | + readRightState?: 'owner_read' | 'licensed_read' | 'pending_settlement' | 'denied' | 'unknown'; |
| 90 | + accessPolicyHash?: string | null; |
| 91 | + sourceSafePreviewRoot?: string | null; |
88 | 92 | acquiredAt?: string | null; |
89 | 93 | } |
90 | 94 |
|
@@ -234,24 +238,50 @@ export interface AuxillariesWalletBtdPaneState { |
234 | 238 | provider: string | null; |
235 | 239 | address: string | null; |
236 | 240 | verificationState: string | null; |
| 241 | + network: string | null; |
237 | 242 | noCustody: true; |
| 243 | + serverCustody: false; |
| 244 | + capabilities: Array<'message_sign' | 'psbt_sign' | 'rights_transfer'>; |
| 245 | + walletCapabilityRoot: string; |
238 | 246 | }; |
239 | 247 | signerPosture: { |
240 | 248 | ready: boolean; |
241 | 249 | state: 'verified' | 'manual' | 'pending' | 'missing' | 'invalid'; |
242 | 250 | requiredAction: 'none' | 'connect_wallet' | 'verify_wallet_signature' | 'repair_wallet_binding'; |
| 251 | + canSignPsbt: boolean; |
| 252 | + canSignRightsTransfer: boolean; |
| 253 | + serverCustody: false; |
| 254 | + }; |
| 255 | + networkReadiness: { |
| 256 | + state: AuxillariesReadinessState; |
| 257 | + network: string | null; |
| 258 | + requiredAction: 'none' | 'connect_wallet' | 'verify_network' | 'repair_wallet_binding'; |
| 259 | + blocker: string | null; |
243 | 260 | }; |
244 | 261 | btdReadRightSummary: { |
245 | 262 | aggregateBtd: number; |
246 | 263 | assetPackCount: number; |
247 | 264 | recentAssetPackIds: string[]; |
| 265 | + rangeCount: number; |
| 266 | + totalRangeCells: number; |
| 267 | + ownerReadCount: number; |
| 268 | + licensedReadCount: number; |
| 269 | + pendingSettlementCount: number; |
| 270 | + deniedCount: number; |
| 271 | + unknownCount: number; |
| 272 | + protectedSourceVisible: false; |
| 273 | + sourceSafePreviewRoots: string[]; |
248 | 274 | }; |
249 | 275 | treasurySummary: { |
250 | 276 | btcFeeBalance: number | null; |
251 | 277 | feeAsset: 'BTC'; |
252 | 278 | noCustody: true; |
| 279 | + treasuryScope: 'account'; |
| 280 | + organizationTreasurySeparated: true; |
| 281 | + exchangeMarketState: 'not_exchange_market_state'; |
253 | 282 | }; |
254 | 283 | settlementReadiness: AuxillariesReadinessState; |
| 284 | + settlementBlockers: string[]; |
255 | 285 | sourceSafetyClass: AuxillariesSourceSafetyClass; |
256 | 286 | btdSupportRoot: string; |
257 | 287 | } |
@@ -1118,61 +1148,40 @@ export function buildAuxillariesWalletBtdPaneState(input: { |
1118 | 1148 | const verificationState = readString(walletStatus?.verificationState) ?? binding?.status ?? null; |
1119 | 1149 | const connected = readBoolean(walletStatus?.connected) ?? Boolean(address); |
1120 | 1150 | const valid = readBoolean(walletStatus?.valid) ?? verificationState === 'verified'; |
1121 | | - const signerState: AuxillariesWalletBtdPaneState['signerPosture']['state'] = !address |
1122 | | - ? 'missing' |
1123 | | - : valid || verificationState === 'verified' |
1124 | | - ? 'verified' |
1125 | | - : verificationState === 'pending' |
1126 | | - ? 'pending' |
1127 | | - : verificationState === 'manual' |
1128 | | - ? 'manual' |
1129 | | - : connected |
1130 | | - ? 'invalid' |
1131 | | - : 'missing'; |
1132 | | - const recentAssetPacks = Array.isArray(input.recentBtdAssetPacks) ? input.recentBtdAssetPacks : []; |
1133 | | - const aggregateBtd = typeof input.btdBalance === 'number' && Number.isFinite(input.btdBalance) |
1134 | | - ? input.btdBalance |
1135 | | - : 0; |
1136 | | - const withoutRoot = { |
1137 | | - kind: 'AuxillariesWalletBtdPaneState' as const, |
1138 | | - walletCapability: { |
1139 | | - hasBinding: Boolean(address), |
1140 | | - provider, |
| 1151 | + const walletMetadata = asRecord(walletStatus?.metadata); |
| 1152 | + const projection = buildBtdWalletBtdSupportProjection({ |
| 1153 | + wallet: { |
1141 | 1154 | address, |
| 1155 | + provider, |
1142 | 1156 | verificationState, |
1143 | | - noCustody: true as const, |
1144 | | - }, |
1145 | | - signerPosture: { |
1146 | | - ready: signerState === 'verified', |
1147 | | - state: signerState, |
1148 | | - requiredAction: |
1149 | | - signerState === 'verified' |
1150 | | - ? 'none' as const |
1151 | | - : signerState === 'missing' |
1152 | | - ? 'connect_wallet' as const |
1153 | | - : signerState === 'manual' || signerState === 'pending' |
1154 | | - ? 'verify_wallet_signature' as const |
1155 | | - : 'repair_wallet_binding' as const, |
| 1157 | + connected, |
| 1158 | + valid, |
| 1159 | + network: |
| 1160 | + readString(walletStatus?.network) ?? |
| 1161 | + readString(walletMetadata?.network) ?? |
| 1162 | + null, |
1156 | 1163 | }, |
1157 | | - btdReadRightSummary: { |
1158 | | - aggregateBtd, |
1159 | | - assetPackCount: recentAssetPacks.length, |
1160 | | - recentAssetPackIds: recentAssetPacks.map((assetPack) => assetPack.assetPackId).filter(Boolean), |
1161 | | - }, |
1162 | | - treasurySummary: { |
1163 | | - btcFeeBalance: typeof input.btcFeeBalance === 'number' && Number.isFinite(input.btcFeeBalance) |
1164 | | - ? input.btcFeeBalance |
1165 | | - : null, |
1166 | | - feeAsset: 'BTC' as const, |
1167 | | - noCustody: true as const, |
1168 | | - }, |
1169 | | - settlementReadiness: signerState === 'verified' ? 'ready' as const : 'degraded' as const, |
| 1164 | + aggregateBtd: input.btdBalance, |
| 1165 | + btcFeeBalance: input.btcFeeBalance, |
| 1166 | + recentAssetPacks: Array.isArray(input.recentBtdAssetPacks) |
| 1167 | + ? input.recentBtdAssetPacks |
| 1168 | + : [], |
| 1169 | + }); |
| 1170 | + const withoutRoot: Omit<AuxillariesWalletBtdPaneState, 'btdSupportRoot'> = { |
| 1171 | + kind: 'AuxillariesWalletBtdPaneState' as const, |
| 1172 | + walletCapability: projection.walletCapability, |
| 1173 | + signerPosture: projection.signerPosture, |
| 1174 | + networkReadiness: projection.networkReadiness, |
| 1175 | + btdReadRightSummary: projection.btdReadRightSummary, |
| 1176 | + treasurySummary: projection.treasurySummary, |
| 1177 | + settlementReadiness: projection.settlementReadiness, |
| 1178 | + settlementBlockers: projection.settlementBlockers, |
1170 | 1179 | sourceSafetyClass: 'source_safe' as AuxillariesSourceSafetyClass, |
1171 | 1180 | }; |
1172 | 1181 |
|
1173 | 1182 | return { |
1174 | 1183 | ...withoutRoot, |
1175 | | - btdSupportRoot: stableProofRoot('auxillaries-wallet-btd-pane-state', withoutRoot), |
| 1184 | + btdSupportRoot: projection.btdSupportRoot, |
1176 | 1185 | }; |
1177 | 1186 | } |
1178 | 1187 |
|
|
0 commit comments