Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Goshimmer_without_tipselection
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
COLLET Ismael
Goshimmer_without_tipselection
Commits
0f53d5b7
Commit
0f53d5b7
authored
5 years ago
by
Wolfgang Welz
Browse files
Options
Downloads
Patches
Plain Diff
Add simple validator plugin to validate bundle signatures
parent
b5ec7827
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
plugins/validator/plugin.go
+90
-0
90 additions, 0 deletions
plugins/validator/plugin.go
with
90 additions
and
0 deletions
plugins/validator/plugin.go
0 → 100644
+
90
−
0
View file @
0f53d5b7
package
validator
import
(
"github.com/iotaledger/goshimmer/packages/events"
"github.com/iotaledger/goshimmer/packages/model/bundle"
"github.com/iotaledger/goshimmer/packages/model/value_transaction"
"github.com/iotaledger/goshimmer/packages/node"
"github.com/iotaledger/goshimmer/plugins/bundleprocessor"
"github.com/iotaledger/iota.go/address"
.
"github.com/iotaledger/iota.go/consts"
"github.com/iotaledger/iota.go/signing"
.
"github.com/iotaledger/iota.go/trinary"
)
var
PLUGIN
=
node
.
NewPlugin
(
"Validator"
,
configure
,
run
)
// Creates bundle signature fragments and the corresponding address to validate against.
// Each signature fragment after the first must go into its own meta transaction with value = 0.
func
demoSign
(
seed
Trytes
,
index
uint64
,
sec
SecurityLevel
,
bundleHash
Hash
)
(
Hash
,
[]
Trytes
)
{
addr
,
_
:=
address
.
GenerateAddress
(
seed
,
index
,
sec
)
// compute seed based on address index
subseed
,
_
:=
signing
.
Subseed
(
seed
,
index
)
// generate the private key
prvKey
,
_
:=
signing
.
Key
(
subseed
,
sec
)
normalizedBundleHash
:=
signing
.
NormalizedBundleHash
(
bundleHash
)
signatureFragments
:=
make
([]
Trytes
,
sec
)
for
i
:=
0
;
i
<
int
(
sec
);
i
++
{
// each security level signs one third of the (normalized) bundle hash
signedFragTrits
,
_
:=
signing
.
SignatureFragment
(
normalizedBundleHash
[
i
*
HashTrytesSize
/
3
:
(
i
+
1
)
*
HashTrytesSize
/
3
],
prvKey
[
i
*
KeyFragmentLength
:
(
i
+
1
)
*
KeyFragmentLength
],
)
signatureFragments
[
i
]
=
MustTritsToTrytes
(
signedFragTrits
)
}
return
addr
,
signatureFragments
}
func
validateSignatures
(
bundleHash
Hash
,
txs
[]
*
value_transaction
.
ValueTransaction
)
(
bool
,
error
)
{
for
i
,
tx
:=
range
txs
{
// ignore all non-input transactions
if
tx
.
GetValue
()
>=
0
{
continue
}
address
:=
tx
.
GetAddress
()
// it is unknown how many fragments there will be
fragments
:=
[]
Trytes
{
tx
.
GetSignatureMessageFragment
()}
// each consecutive meta transaction with the same address contains another signature fragment
for
j
:=
i
;
j
<
len
(
txs
)
-
1
;
j
++
{
otherTx
:=
txs
[
j
+
1
]
if
otherTx
.
GetValue
()
!=
0
||
otherTx
.
GetAddress
()
!=
address
{
break
}
fragments
=
append
(
fragments
,
otherTx
.
GetSignatureMessageFragment
())
}
// validate all the fragments against the address using Kerl
valid
,
err
:=
signing
.
ValidateSignatures
(
address
,
fragments
,
bundleHash
,
signing
.
NewKerl
)
if
err
!=
nil
{
return
false
,
err
}
if
!
valid
{
return
false
,
nil
}
}
return
true
,
nil
}
func
configure
(
plugin
*
node
.
Plugin
)
{
bundleprocessor
.
Events
.
ValueBundleReceived
.
Attach
(
events
.
NewClosure
(
func
(
b
*
bundle
.
Bundle
,
txs
[]
*
value_transaction
.
ValueTransaction
)
{
// signature are verified against the bundle hash
valid
,
_
:=
validateSignatures
(
b
.
GetBundleEssenceHash
(),
txs
)
if
!
valid
{
plugin
.
LogFailure
(
"Invalid signature"
)
}
}))
}
func
run
(
*
node
.
Plugin
)
{
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment