diff --git a/contracts/MultiSigFlowToken.cdc b/contracts/MultiSigFlowToken.cdc index 0f293f2..5909139 100644 --- a/contracts/MultiSigFlowToken.cdc +++ b/contracts/MultiSigFlowToken.cdc @@ -74,8 +74,9 @@ pub contract MultiSigFlowToken: FungibleToken { case "configureKey": let pubKey = p.getArg(i: 0)! as? String ?? panic ("cannot downcast public key"); let weight = p.getArg(i: 1)! as? UFix64 ?? panic ("cannot downcast weight"); + let sigAlgo = p.getArg(i: 2)! as? UInt8 ?? panic ("cannot downcast sigAlgo"); destroy(p) - self.multiSigManager.configureKeys(pks: [pubKey], kws: [weight]) + self.multiSigManager.configureKeys(pks: [pubKey], kws: [weight], sa: [sigAlgo]) case "removeKey": let pubKey = p.getArg(i: 0)! as? String ?? panic ("cannot downcast public key"); destroy(p) @@ -139,8 +140,8 @@ pub contract MultiSigFlowToken: FungibleToken { // // These follows the usual account authorization logic // i.e. if it is an account with multiple keys, then the total weight of the signatures must be > 1000 - pub fun addKeys( multiSigPubKeys: [String], multiSigKeyWeights: [UFix64]) { - self.multiSigManager.configureKeys(pks: multiSigPubKeys, kws: multiSigKeyWeights) + pub fun addKeys( multiSigPubKeys: [String], multiSigKeyWeights: [UFix64], multiSigAlgos: [UInt8]) { + self.multiSigManager.configureKeys(pks: multiSigPubKeys, kws: multiSigKeyWeights, sa: multiSigAlgos) } pub fun removeKeys( multiSigPubKeys: [String]) { diff --git a/contracts/OnChainMultiSig.cdc b/contracts/OnChainMultiSig.cdc index 391064d..b7e5077 100644 --- a/contracts/OnChainMultiSig.cdc +++ b/contracts/OnChainMultiSig.cdc @@ -44,7 +44,7 @@ pub contract OnChainMultiSig { /// /// Optional interfaces for owner of the vault to add / remove keys in @Manager. pub resource interface KeyManager { - pub fun addKeys( multiSigPubKeys: [String], multiSigKeyWeights: [UFix64]); + pub fun addKeys( multiSigPubKeys: [String], multiSigKeyWeights: [UFix64], multiSigAlgos: [UInt8]); pub fun removeKeys( multiSigPubKeys: [String]); } @@ -58,7 +58,7 @@ pub contract OnChainMultiSig { pub fun addNewPayload (resourceId: UInt64, payload: @PayloadDetails, publicKey: String, sig: [UInt8]); pub fun addPayloadSignature (resourceId: UInt64, txIndex: UInt64, publicKey: String, sig: [UInt8]); pub fun readyForExecution(txIndex: UInt64): @PayloadDetails?; - pub fun configureKeys (pks: [String], kws: [UFix64]); + pub fun configureKeys (pks: [String], kws: [UFix64], sa: [UInt8]); pub fun removeKeys (pks: [String]); } @@ -126,6 +126,9 @@ pub contract OnChainMultiSig { case Type(): let temp = a as? UFix64; b = temp!.toBigEndianBytes(); + case Type(): + let temp = a as? UInt8; + b = temp!.toBigEndianBytes(); case Type
(): let temp = a as? Address; b = temp!.toBytes(); @@ -270,10 +273,10 @@ pub contract OnChainMultiSig { /// Add / replace stored public keys and respected attributes /// from `keyList` - pub fun configureKeys (pks: [String], kws: [UFix64]) { + pub fun configureKeys (pks: [String], kws: [UFix64], sa: [UInt8]) { var i: Int = 0; while (i < pks.length) { - let a = PubKeyAttr(sa: 1, w: kws[i]) + let a = PubKeyAttr(sa: sa[i], w: kws[i]) self.keyList.insert(key: pks[i], a) i = i + 1; } @@ -411,4 +414,4 @@ pub contract OnChainMultiSig { pub fun createPayload(txIndex: UInt64, method: String, args: [AnyStruct], rsc: @AnyResource?): @PayloadDetails{ return <- create PayloadDetails(txIndex: txIndex, method: method, args: args, rsc: <-rsc) } -} \ No newline at end of file +} diff --git a/lib/go/keys/keys.go b/lib/go/keys/keys.go index 86a3079..0bc9dd1 100644 --- a/lib/go/keys/keys.go +++ b/lib/go/keys/keys.go @@ -60,10 +60,12 @@ func MultiSig_ConfigKey( pkToConfig := cadence.NewString(g.Accounts[acctToConfig].PrivateKey.PublicKey().String()[2:]) weightToConfig, err := cadence.NewUFix64(acctToConfigWeight) + sigAlgoToConfig := cadence.NewUInt8(1) + if err != nil { return } - signable, err := util.GetSignableDataFromScript(g, txIndex, method, pkToConfig, weightToConfig) + signable, err := util.GetSignableDataFromScript(g, txIndex, method, pkToConfig, weightToConfig, sigAlgoToConfig) if err != nil { return } @@ -74,7 +76,7 @@ func MultiSig_ConfigKey( } if newPayload { - args := []cadence.Value{pkToConfig, weightToConfig} + args := []cadence.Value{pkToConfig, weightToConfig, sigAlgoToConfig} return util.MultiSig_VaultNewPayload(g, sig, txIndex, method, args, signerAcct, vaultAcct, "0.0") } else { return util.MultiSig_VaultAddPayloadSignature(g, sig, txIndex, signerAcct, vaultAcct) diff --git a/lib/go/vault/vault.go b/lib/go/vault/vault.go index d6ce2f0..7a5bd59 100644 --- a/lib/go/vault/vault.go +++ b/lib/go/vault/vault.go @@ -37,11 +37,14 @@ func AddVaultToAccount( cadence.String(pk250_2[2:]), } multiSigKeyWeights := []cadence.Value{w1000, w500, w500, w250, w250} + sa := cadence.NewUInt8(1) + multiSigAlgos := []cadence.Value{sa, sa, sa, sa, sa} e, err := g.TransactionFromFile(txFilename, txScript). SignProposeAndPayAs(vaultAcct). Argument(cadence.NewArray(multiSigPubKeys)). Argument(cadence.NewArray(multiSigKeyWeights)). + Argument(cadence.NewArray(multiSigAlgos)). Run() events = util.ParseTestEvents(e) return diff --git a/scripts/calc_signable_data.cdc b/scripts/calc_signable_data.cdc index 24786a7..33bea53 100644 --- a/scripts/calc_signable_data.cdc +++ b/scripts/calc_signable_data.cdc @@ -11,6 +11,9 @@ pub fun main(v: AnyStruct?): [UInt8] { case Type(): let temp = value as? UInt64; return temp!.toBigEndianBytes(); + case Type(): + let temp = value as? UInt8; + return temp!.toBigEndianBytes(); case Type(): let temp = value as? UFix64; return temp!.toBigEndianBytes(); diff --git a/transactions/create_vault.cdc b/transactions/create_vault.cdc index 2641022..82caa76 100644 --- a/transactions/create_vault.cdc +++ b/transactions/create_vault.cdc @@ -5,7 +5,7 @@ import FungibleToken from 0x{{.FungibleToken}} import MultiSigFlowToken from 0x{{.MultiSigFlowToken}} import OnChainMultiSig from 0x{{.OnChainMultiSig}} -transaction(multiSigPubKeys: [String], multiSigKeyWeights: [UFix64]) { +transaction(multiSigPubKeys: [String], multiSigKeyWeights: [UFix64], multiSigAlgos: [UInt8]) { prepare(signer: AuthAccount) { @@ -48,7 +48,7 @@ transaction(multiSigPubKeys: [String], multiSigKeyWeights: [UFix64]) { // The transaction that creates the vault can also add required multiSig public keys to the multiSigManager let s = signer.borrow<&MultiSigFlowToken.Vault>(from: MultiSigFlowToken.VaultStoragePath) ?? panic ("cannot borrow own resource") - s.addKeys(multiSigPubKeys: multiSigPubKeys, multiSigKeyWeights: multiSigKeyWeights) + s.addKeys(multiSigPubKeys: multiSigPubKeys, multiSigKeyWeights: multiSigKeyWeights, multiSigAlgos: multiSigAlgos) } } diff --git a/transactions/ownerUpdateKeyList.cdc b/transactions/ownerUpdateKeyList.cdc index fb6a832..e0f35ef 100644 --- a/transactions/ownerUpdateKeyList.cdc +++ b/transactions/ownerUpdateKeyList.cdc @@ -7,6 +7,6 @@ transaction (multiSigVaultAddr: Address) { prepare(owner: AuthAccount) { let s = owner.borrow<&MultiSigFlowToken.Vault>(from: MultiSigFlowToken.VaultStoragePath) ?? panic ("cannot borrow own resource") let pka = OnChainMultiSig.PubKeyAttr(sa: 1, w: 0.2) - s.multiSigManager.configureKeys(pks: ["1234"], kws: [0.2]) + s.multiSigManager.configureKeys(pks: ["1234"], kws: [0.2], sa: [1]) } } diff --git a/transactions/pubUpdateKeyList.cdc b/transactions/pubUpdateKeyList.cdc index 5ef2043..56f459d 100644 --- a/transactions/pubUpdateKeyList.cdc +++ b/transactions/pubUpdateKeyList.cdc @@ -15,6 +15,6 @@ transaction (multiSigVaultAddr: Address) { .borrow<&MultiSigFlowToken.Vault{OnChainMultiSig.PublicSigner}>() ?? panic("Could not borrow vault pub sig reference") - vaultRef.multiSigManager.configureKeys(pks: ["1234"], kws: [0.2]) + vaultRef.multiSigManager.configureKeys(pks: ["1234"], kws: [0.2], sa: [1]) } }