-
Notifications
You must be signed in to change notification settings - Fork 7
Implement native canton driver #225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
PawelBis
wants to merge
23
commits into
main
Choose a base branch
from
canton
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
8694303
CANTON: Wip
PawelBis ed96efc
CANTON: Prepare CreateAccount method
PawelBis 85f6f1f
CANTON: Refactor create account transacction
PawelBis 56f9a4e
CANTON: Improve logging
PawelBis d6f0df1
CANTON: Add GetAccountState method
PawelBis 5c43da5
Add AddressBuilder.AddressRegistrationRequired() method
PawelBis 397efa2
CANTON: Refactor inputs
PawelBis e548a61
CANTON: Fix tx-info lookup
PawelBis 7dc763d
CANTON: Fix tx-info fee report
PawelBis 4a118bc
CANTON: Refactor create account command
PawelBis d6d6f03
CANTON: Fetch synchronizer id
PawelBis 8bce023
CANTON: Remove hardcoded env vars and implement CustomConfig
PawelBis ed36c9f
CANTON: Remove hardcoded username, read deduplication window from config
PawelBis fbfa736
CANTON: Refactor scan api interactions
PawelBis 271876a
CANTON: Test fixes and magic value fix
PawelBis 1caa2fe
CANTON: Fix scan api regression
PawelBis 41a5b3a
CANTON: Remove CustomConfig.validator_party_id
PawelBis 46834f1
CANTON: Add CustomConfig comments
PawelBis f464fbb
canton: drop using secrets for urls
conorpp 67ac7d2
canton: generate protobuf types locally
conorpp e5aefb9
canton: some cleanup
conorpp 09f42ce
Canton: Add upload token standard dars script
PawelBis 2b3b82a
CANTON: Token setup scripts + balance implementation
PawelBis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package builder | ||
|
|
||
| import xc "github.com/cordialsys/crosschain" | ||
|
|
||
| type CreateAccountArgs struct { | ||
| appliedOptions []BuilderOption | ||
| options builderOptions | ||
| chain xc.NativeAsset | ||
| address xc.Address | ||
| publicKey []byte | ||
| } | ||
|
|
||
| var _ TransactionOptions = &CreateAccountArgs{} | ||
|
|
||
| func NewCreateAccountArgs(chain xc.NativeAsset, address xc.Address, publicKey []byte, options ...BuilderOption) (CreateAccountArgs, error) { | ||
| builderOptions := newBuilderOptions() | ||
| args := CreateAccountArgs{ | ||
| appliedOptions: options, | ||
| options: builderOptions, | ||
| chain: chain, | ||
| address: address, | ||
| publicKey: append([]byte(nil), publicKey...), | ||
| } | ||
| for _, opt := range options { | ||
| if err := opt(&args.options); err != nil { | ||
| return args, err | ||
| } | ||
| } | ||
| return args, nil | ||
| } | ||
|
|
||
| func (args *CreateAccountArgs) GetChain() xc.NativeAsset { return args.chain } | ||
| func (args *CreateAccountArgs) GetAddress() xc.Address { return args.address } | ||
| func (args *CreateAccountArgs) PublicKeyBytes() []byte { return append([]byte(nil), args.publicKey...) } | ||
| func (args *CreateAccountArgs) GetMemo() (string, bool) { return args.options.GetMemo() } | ||
| func (args *CreateAccountArgs) GetTimestamp() (int64, bool) { | ||
| return args.options.GetTimestamp() | ||
| } | ||
| func (args *CreateAccountArgs) GetPriority() (xc.GasFeePriority, bool) { | ||
| return args.options.GetPriority() | ||
| } | ||
| func (args *CreateAccountArgs) GetPublicKey() ([]byte, bool) { | ||
| return append([]byte(nil), args.publicKey...), len(args.publicKey) > 0 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # Regenerate protobuf types | ||
| pb: | ||
| rm -rf types/com/daml/ledger/api/v2 types/google/rpc | ||
| cd proto && buf mod update && buf generate | ||
| # Use google.golang.org/genproto/googleapis/rpc/status rather than any local types. | ||
| for file in `rg -l 'github.com/cordialsys/crosschain/chain/canton/types/google/rpc' types/com/daml/ledger/api/v2 -g '*.go'`; do perl -0pi -e 's#github.com/cordialsys/crosschain/chain/canton/types/google/rpc#google.golang.org/genproto/googleapis/rpc/status#g' "$file"; done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| package address | ||
|
|
||
| import ( | ||
| "crypto/sha256" | ||
| "encoding/binary" | ||
| "encoding/hex" | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| xc "github.com/cordialsys/crosschain" | ||
| ) | ||
|
|
||
| // AddressBuilder for Canton | ||
| type AddressBuilder struct{} | ||
|
|
||
| var _ xc.AddressBuilder = AddressBuilder{} | ||
|
|
||
| func NewAddressBuilder(cfgI *xc.ChainBaseConfig) (xc.AddressBuilder, error) { | ||
| return AddressBuilder{}, nil | ||
| } | ||
|
|
||
| // GetAddressFromPublicKey returns a Canton party ID from a raw Ed25519 public key (32 bytes). | ||
| // | ||
| // Canton party IDs have the form: <name>::<fingerprint> | ||
| // | ||
| // Where: | ||
| // - <name> = hex-encoded public key (64 hex chars) | ||
| // - <fingerprint> = "1220" + hex(SHA-256(purposeBytes || rawPubKey)) | ||
| // | ||
| // The purpose prefix is big-endian uint32(12), matching Canton's internal | ||
| // HashPurpose.PublicKeyFingerprint (id=12) in Hash.digest(). | ||
| // | ||
| // The "1220" multihash prefix encodes: | ||
| // - 0x12 = SHA-256 algorithm code (varint) | ||
| // - 0x20 = 32-byte digest length (varint) | ||
| func (ab AddressBuilder) GetAddressFromPublicKey(publicKeyBytes []byte) (xc.Address, error) { | ||
| fingerprint, err := FingerprintFromPublicKey(publicKeyBytes) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| name := hex.EncodeToString(publicKeyBytes) | ||
| addr := xc.Address(name + "::" + fingerprint) | ||
|
|
||
| return addr, nil | ||
| } | ||
|
|
||
| func (ab AddressBuilder) AddressRegistrationRequired(address xc.Address) bool { | ||
| return true | ||
| } | ||
|
|
||
| // FingerprintFromPublicKey returns the Canton key fingerprint for a raw Ed25519 public key. | ||
| func FingerprintFromPublicKey(rawPubKey []byte) (string, error) { | ||
| if len(rawPubKey) != 32 { | ||
| return "", fmt.Errorf("invalid ed25519 public key length: expected 32 bytes, got %d", len(rawPubKey)) | ||
| } | ||
| // HashPurpose.PublicKeyFingerprint id=12 encoded as big-endian int32 (4 bytes) | ||
| var purposeBytes [4]byte | ||
| binary.BigEndian.PutUint32(purposeBytes[:], 12) | ||
|
|
||
| h := sha256.New() | ||
| h.Write(purposeBytes[:]) | ||
| h.Write(rawPubKey) | ||
| digest := h.Sum(nil) | ||
|
|
||
| // Multihash: varint(0x12=SHA-256) || varint(0x20=32) || digest | ||
| return "1220" + hex.EncodeToString(digest), nil | ||
| } | ||
|
|
||
| // FingerprintFromPartyID recomputes the Canton key fingerprint from a party ID | ||
| // whose name segment is the hex-encoded Ed25519 public key produced by AddressBuilder. | ||
| func FingerprintFromPartyID(addr xc.Address) (string, error) { | ||
| name, fingerprint, err := ParsePartyID(addr) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| publicKeyBytes, err := hex.DecodeString(name) | ||
| if err != nil { | ||
| return "", fmt.Errorf("invalid Canton party name %q: expected hex-encoded public key: %w", name, err) | ||
| } | ||
| computed, err := FingerprintFromPublicKey(publicKeyBytes) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| if computed != fingerprint { | ||
| return "", fmt.Errorf("canton party fingerprint mismatch: computed %q from address public key, got %q", computed, fingerprint) | ||
| } | ||
| return computed, nil | ||
| } | ||
|
|
||
| // ParsePartyID splits a Canton party ID into its name and fingerprint components. | ||
| // Expected format: "<name>::<fingerprint>" where fingerprint starts with "1220". | ||
| func ParsePartyID(addr xc.Address) (name string, fingerprint string, err error) { | ||
| s := string(addr) | ||
| idx := strings.Index(s, "::") | ||
| if idx < 0 { | ||
| return "", "", fmt.Errorf("invalid Canton party ID %q: missing '::' separator", s) | ||
| } | ||
| name = s[:idx] | ||
| fingerprint = s[idx+2:] | ||
| if len(fingerprint) < 4 || fingerprint[:4] != "1220" { | ||
| return "", "", fmt.Errorf("invalid Canton fingerprint %q: must start with '1220' (SHA-256 multihash prefix)", fingerprint) | ||
| } | ||
| return name, fingerprint, nil | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be nice to see a defined constant for this "12" purpose and any comment or link to what the purpose means, or if there are others.