From f6d5a77803fc0acd13d450649befe0f52ee52b56 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 22 Feb 2024 17:59:03 +0000 Subject: [PATCH 1/2] index unlocks by public key rather than address key --- builder/transaction_builder.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/builder/transaction_builder.go b/builder/transaction_builder.go index bf8ee9282..76cc8b4e6 100644 --- a/builder/transaction_builder.go +++ b/builder/transaction_builder.go @@ -681,25 +681,27 @@ func (b *TransactionBuilder) Build(signer iotago.AddressSigner) (*iotago.SignedT for i, inputRef := range b.transaction.TransactionEssence.Inputs { //nolint:forcetypeassert // we can safely assume that this is an UTXOInput addr := b.inputOwner[inputRef.(*iotago.UTXOInput).OutputID()] - addrKey := addr.Key() - pos, unlocked := unlockPos[addrKey] + // produce signature + var signature iotago.Signature + signature, err = signer.Sign(addr, txEssenceData) + if err != nil { + return nil, ierrors.Wrapf(err, "failed to sign tx transaction: %s", txEssenceData) + } + ed25519Sig, is := signature.(*iotago.Ed25519Signature) + if !is { + return nil, ierrors.Errorf("signature is not an Ed25519Signature") + } + pubKeyString := string(ed25519Sig.PublicKey[:]) + pos, unlocked := unlockPos[pubKeyString] if !unlocked { // the output's owning chain address must have been unlocked already if _, is := addr.(iotago.ChainAddress); is { return nil, ierrors.Errorf("input %d's owning chain is not unlocked, chainID %s, type %s", i, addr, addr.Type()) } - - // produce signature - var signature iotago.Signature - signature, err = signer.Sign(addr, txEssenceData) - if err != nil { - return nil, ierrors.Wrapf(err, "failed to sign tx transaction: %s", txEssenceData) - } - unlocks = append(unlocks, &iotago.SignatureUnlock{Signature: signature}) addChainAsUnlocked(inputs[i], i, unlockPos) - unlockPos[addrKey] = i + unlockPos[pubKeyString] = i continue } From f304abf3efa0758011a5c23f4a45971cb0828d5b Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 23 Feb 2024 11:00:58 +0000 Subject: [PATCH 2/2] use address bytes without type denotation as address Key() --- address_ed25519.gen.go | 2 +- address_implicit_account_creation.gen.go | 2 +- builder/transaction_builder.go | 24 +++++++++++------------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/address_ed25519.gen.go b/address_ed25519.gen.go index e8d9ca3a2..f3c259331 100644 --- a/address_ed25519.gen.go +++ b/address_ed25519.gen.go @@ -43,7 +43,7 @@ func (addr *Ed25519Address) ID() []byte { } func (addr *Ed25519Address) Key() string { - return string(addr.ID()) + return string(addr.ID()[serializer.SmallTypeDenotationByteSize:]) } func (addr *Ed25519Address) Unlock(msg []byte, sig Signature) error { diff --git a/address_implicit_account_creation.gen.go b/address_implicit_account_creation.gen.go index a008edfc1..9cb93c0aa 100644 --- a/address_implicit_account_creation.gen.go +++ b/address_implicit_account_creation.gen.go @@ -39,7 +39,7 @@ func (addr *ImplicitAccountCreationAddress) ID() []byte { } func (addr *ImplicitAccountCreationAddress) Key() string { - return string(addr.ID()) + return string(addr.ID()[serializer.SmallTypeDenotationByteSize:]) } func (addr *ImplicitAccountCreationAddress) Unlock(msg []byte, sig Signature) error { diff --git a/builder/transaction_builder.go b/builder/transaction_builder.go index 76cc8b4e6..bf8ee9282 100644 --- a/builder/transaction_builder.go +++ b/builder/transaction_builder.go @@ -681,27 +681,25 @@ func (b *TransactionBuilder) Build(signer iotago.AddressSigner) (*iotago.SignedT for i, inputRef := range b.transaction.TransactionEssence.Inputs { //nolint:forcetypeassert // we can safely assume that this is an UTXOInput addr := b.inputOwner[inputRef.(*iotago.UTXOInput).OutputID()] + addrKey := addr.Key() - // produce signature - var signature iotago.Signature - signature, err = signer.Sign(addr, txEssenceData) - if err != nil { - return nil, ierrors.Wrapf(err, "failed to sign tx transaction: %s", txEssenceData) - } - ed25519Sig, is := signature.(*iotago.Ed25519Signature) - if !is { - return nil, ierrors.Errorf("signature is not an Ed25519Signature") - } - pubKeyString := string(ed25519Sig.PublicKey[:]) - pos, unlocked := unlockPos[pubKeyString] + pos, unlocked := unlockPos[addrKey] if !unlocked { // the output's owning chain address must have been unlocked already if _, is := addr.(iotago.ChainAddress); is { return nil, ierrors.Errorf("input %d's owning chain is not unlocked, chainID %s, type %s", i, addr, addr.Type()) } + + // produce signature + var signature iotago.Signature + signature, err = signer.Sign(addr, txEssenceData) + if err != nil { + return nil, ierrors.Wrapf(err, "failed to sign tx transaction: %s", txEssenceData) + } + unlocks = append(unlocks, &iotago.SignatureUnlock{Signature: signature}) addChainAsUnlocked(inputs[i], i, unlockPos) - unlockPos[pubKeyString] = i + unlockPos[addrKey] = i continue }