From 61ebf065bb22ea13562e87a4132fac1d60917fd3 Mon Sep 17 00:00:00 2001 From: rodion Date: Wed, 22 Feb 2023 06:43:54 +0000 Subject: [PATCH 1/2] extension: expose generation of management contract uuid to allow external signing of approval request --- extension/api.go | 60 +++++++++++++++++++++++++++++++++++++ extension/proxy_api.go | 7 +++++ internal/web3ext/web3ext.go | 6 ++++ 3 files changed, 73 insertions(+) diff --git a/extension/api.go b/extension/api.go index bee5bf9186..7d8a065403 100644 --- a/extension/api.go +++ b/extension/api.go @@ -127,6 +127,66 @@ func (api *PrivateExtensionAPI) doMultiTenantChecks(ctx context.Context, address return nil } +// GenerateExtensionApprovalUuid generates a uuid to be used for contract state extension approval when calling doVote within the management contract, +// allowing the approval method to be called with an external signer +func (api *PrivateExtensionAPI) GenerateExtensionApprovalUuid(ctx context.Context, addressToVoteOn common.Address, txa ethapi.SendTxArgs) (string, error) { + err := api.doMultiTenantChecks(ctx, txa.From, txa) + if err != nil { + return "", err + } + + psm, err := api.privacyService.apiBackendHelper.PSMR().ResolveForUserContext(ctx) + if err != nil { + return "", err + } + psi := psm.ID + + // check if the extension has been completed. if yes + // no acceptance required + status, err := api.checkIfExtensionComplete(addressToVoteOn, txa.From, psi) + if err != nil { + return "", err + } + + if status { + return "", errors.New("contract extension process complete. nothing to accept") + } + + if !core.CheckIfAdminAccount(txa.From) { + return "", errors.New("account cannot accept extension") + } + + // get all participants for the contract being extended + participants, err := api.privacyService.GetAllParticipants(api.privacyService.stateFetcher.getCurrentBlockHash(), addressToVoteOn, psi) + if err == nil { + txa.PrivateFor = append(txa.PrivateFor, participants...) + } + + txArgs, err := api.privacyService.GenerateTransactOptions(txa) + if err != nil { + return "", err + } + + psiManagementContractClient := api.privacyService.managementContract(psi) + defer psiManagementContractClient.Close() + voterList, err := psiManagementContractClient.GetAllVoters(addressToVoteOn) + if err != nil { + return "", err + } + if isVoter := checkAddressInList(txArgs.From, voterList); !isVoter { + return "", errNotAcceptor + } + + if api.checkAlreadyVoted(addressToVoteOn, txArgs.From, psi) { + return "", errors.New("already voted") + } + uuid, err := generateUuid(addressToVoteOn, txArgs.PrivateFrom, txArgs.PrivateFor, api.privacyService.ptm) + if err != nil { + return "", err + } + return uuid, nil +} + // ApproveContractExtension submits the vote to the specified extension management contract. The vote indicates whether to extend // a given contract to a new participant or not func (api *PrivateExtensionAPI) ApproveExtension(ctx context.Context, addressToVoteOn common.Address, vote bool, txa ethapi.SendTxArgs) (string, error) { diff --git a/extension/proxy_api.go b/extension/proxy_api.go index c10efa4b97..caa1e81f4d 100644 --- a/extension/proxy_api.go +++ b/extension/proxy_api.go @@ -45,6 +45,13 @@ func (api *PrivateExtensionProxyAPI) ActiveExtensionContracts(ctx context.Contex return extracted } +func (api *PrivateExtensionProxyAPI) GenerateExtensionApprovalUuid(ctx context.Context, addressToVoteOn common.Address, txa ethapi.SendTxArgs) (string, error) { + log.Info("QLight - proxy enabled") + var result string + err := api.proxyClient.CallContext(ctx, &result, "quorumExtension_generateExtensionApprovalUuid", addressToVoteOn, txa) + return result, err +} + // ApproveContractExtension submits the vote to the specified extension management contract. The vote indicates whether to extend // a given contract to a new participant or not func (api *PrivateExtensionProxyAPI) ApproveExtension(ctx context.Context, addressToVoteOn common.Address, vote bool, txa ethapi.SendTxArgs) (string, error) { diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index dff152c194..ffb1a0dae7 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -1251,6 +1251,12 @@ web3._extend({ property: 'quorumExtension', methods: [ + new web3._extend.Method({ + name: 'generateExtensionApprovalUuid', + call: 'quorumExtension_generateExtensionApprovalUuid', + params: 2, + inputFormatter: [web3._extend.formatters.inputAddressFormatter, web3._extend.formatters.inputTransactionFormatter] + }), new web3._extend.Method({ name: 'approveExtension', call: 'quorumExtension_approveExtension', From 6fd55330d86d345755360539b541aae0418f3f03 Mon Sep 17 00:00:00 2001 From: rodion Date: Fri, 24 Mar 2023 08:50:12 +0000 Subject: [PATCH 2/2] extension: external signer address required for validation before generating uuid --- extension/api.go | 12 ++++-------- extension/proxy_api.go | 4 ++-- internal/web3ext/web3ext.go | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/extension/api.go b/extension/api.go index 7d8a065403..17aaa1a289 100644 --- a/extension/api.go +++ b/extension/api.go @@ -129,7 +129,7 @@ func (api *PrivateExtensionAPI) doMultiTenantChecks(ctx context.Context, address // GenerateExtensionApprovalUuid generates a uuid to be used for contract state extension approval when calling doVote within the management contract, // allowing the approval method to be called with an external signer -func (api *PrivateExtensionAPI) GenerateExtensionApprovalUuid(ctx context.Context, addressToVoteOn common.Address, txa ethapi.SendTxArgs) (string, error) { +func (api *PrivateExtensionAPI) GenerateExtensionApprovalUuid(ctx context.Context, addressToVoteOn common.Address, externalSignerAddress common.Address, txa ethapi.SendTxArgs) (string, error) { err := api.doMultiTenantChecks(ctx, txa.From, txa) if err != nil { return "", err @@ -143,7 +143,7 @@ func (api *PrivateExtensionAPI) GenerateExtensionApprovalUuid(ctx context.Contex // check if the extension has been completed. if yes // no acceptance required - status, err := api.checkIfExtensionComplete(addressToVoteOn, txa.From, psi) + status, err := api.checkIfExtensionComplete(addressToVoteOn, externalSignerAddress, psi) if err != nil { return "", err } @@ -152,10 +152,6 @@ func (api *PrivateExtensionAPI) GenerateExtensionApprovalUuid(ctx context.Contex return "", errors.New("contract extension process complete. nothing to accept") } - if !core.CheckIfAdminAccount(txa.From) { - return "", errors.New("account cannot accept extension") - } - // get all participants for the contract being extended participants, err := api.privacyService.GetAllParticipants(api.privacyService.stateFetcher.getCurrentBlockHash(), addressToVoteOn, psi) if err == nil { @@ -173,11 +169,11 @@ func (api *PrivateExtensionAPI) GenerateExtensionApprovalUuid(ctx context.Contex if err != nil { return "", err } - if isVoter := checkAddressInList(txArgs.From, voterList); !isVoter { + if isVoter := checkAddressInList(externalSignerAddress, voterList); !isVoter { return "", errNotAcceptor } - if api.checkAlreadyVoted(addressToVoteOn, txArgs.From, psi) { + if api.checkAlreadyVoted(addressToVoteOn, externalSignerAddress, psi) { return "", errors.New("already voted") } uuid, err := generateUuid(addressToVoteOn, txArgs.PrivateFrom, txArgs.PrivateFor, api.privacyService.ptm) diff --git a/extension/proxy_api.go b/extension/proxy_api.go index caa1e81f4d..2314eb4b5b 100644 --- a/extension/proxy_api.go +++ b/extension/proxy_api.go @@ -45,10 +45,10 @@ func (api *PrivateExtensionProxyAPI) ActiveExtensionContracts(ctx context.Contex return extracted } -func (api *PrivateExtensionProxyAPI) GenerateExtensionApprovalUuid(ctx context.Context, addressToVoteOn common.Address, txa ethapi.SendTxArgs) (string, error) { +func (api *PrivateExtensionProxyAPI) GenerateExtensionApprovalUuid(ctx context.Context, addressToVoteOn common.Address, externalSignerAddress common.Address, txa ethapi.SendTxArgs) (string, error) { log.Info("QLight - proxy enabled") var result string - err := api.proxyClient.CallContext(ctx, &result, "quorumExtension_generateExtensionApprovalUuid", addressToVoteOn, txa) + err := api.proxyClient.CallContext(ctx, &result, "quorumExtension_generateExtensionApprovalUuid", addressToVoteOn, externalSignerAddress, txa) return result, err } diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index ffb1a0dae7..ee4ca56a8c 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -1255,7 +1255,7 @@ web3._extend({ name: 'generateExtensionApprovalUuid', call: 'quorumExtension_generateExtensionApprovalUuid', params: 2, - inputFormatter: [web3._extend.formatters.inputAddressFormatter, web3._extend.formatters.inputTransactionFormatter] + inputFormatter: [web3._extend.formatters.inputAddressFormatter, web3._extend.formatters.inputAddressFormatter, web3._extend.formatters.inputTransactionFormatter] }), new web3._extend.Method({ name: 'approveExtension',