├── .github
└── workflows
│ ├── codeql-analysis.yml
│ ├── golangci-lint.yml
│ ├── md_links.yml
│ └── tests.yml
├── .gitignore
├── CODE_OF_CONDUCT.md
├── DEVELOPMENT.md
├── LICENSE
├── MAINTAINERS.md
├── Makefile
├── README.md
├── SECURITY.md
├── checks.mk
├── ci
└── scripts
│ ├── cleanup_softhsm.sh
│ ├── download_fabric.sh
│ ├── install_softhsm.sh
│ └── setup_softhsm.sh
├── cmd
└── tokengen
│ ├── README.md
│ ├── cobra
│ ├── artifactgen
│ │ ├── gen
│ │ │ └── gen.go
│ │ └── utils.go
│ ├── certfier
│ │ └── keypairgen.go
│ ├── pp
│ │ ├── cc
│ │ │ ├── cc.go
│ │ │ └── params.go
│ │ ├── common
│ │ │ └── common.go
│ │ ├── dlog
│ │ │ ├── gen.go
│ │ │ └── update.go
│ │ ├── fabtoken
│ │ │ └── gen.go
│ │ ├── gen.go
│ │ ├── idemix
│ │ │ └── idemix.go
│ │ ├── printpp
│ │ │ └── print.go
│ │ ├── update.go
│ │ └── utils.go
│ └── version
│ │ └── version.go
│ ├── main.go
│ ├── main_test.go
│ ├── samples
│ └── topology
│ │ ├── fungible.go
│ │ └── fungible.yaml
│ └── testdata
│ ├── auditors
│ └── msp
│ │ └── signcerts
│ │ └── auditor.Orgauditor.example.com-cert.pem
│ ├── idemix
│ ├── ca
│ │ ├── IssuerPublicKey
│ │ ├── IssuerSecretKey
│ │ └── RevocationKey
│ └── msp
│ │ ├── IssuerPublicKey
│ │ └── RevocationPublicKey
│ ├── issuers
│ └── msp
│ │ └── signcerts
│ │ └── issuer.Orgissuer.example.com-cert.pem
│ └── zkatdlog_pp.json
├── deps.go
├── docs
├── apis
│ ├── driver-api.md
│ └── token-api.md
├── core-token.md
├── deployment
│ └── deployment.md
├── design.md
├── drivers
│ ├── drivers.md
│ ├── fabtoken.md
│ └── zkat-dlog.md
├── imgs
│ ├── commit_process.png
│ ├── deployment.png
│ ├── driver_api.png
│ ├── fabric_ttx_lifecycle.png
│ ├── orion_ttx_lifecycle.png
│ ├── stack.png
│ ├── token_api.png
│ ├── token_processing.png
│ ├── token_request.png
│ ├── token_request_translation.png
│ ├── token_request_translator.png
│ └── token_vault.png
├── itests.md
└── services
│ ├── auditor.md
│ ├── identity.md
│ ├── interop.md
│ ├── network.md
│ ├── selector.md
│ ├── selector
│ └── sherdlock.md
│ ├── services.md
│ ├── storage.md
│ ├── ttx.md
│ └── vault.md
├── fungible.mk
├── go.mod
├── go.sum
├── integration
├── nwo
│ ├── runner
│ │ ├── metrics.go
│ │ ├── nwo
│ │ │ ├── executor.go
│ │ │ └── user_provider.go
│ │ ├── rpc
│ │ │ ├── executor.go
│ │ │ └── user_provider.go
│ │ ├── view_runner.go
│ │ └── view_user.go
│ ├── token
│ │ ├── commands
│ │ │ └── tokengen.go
│ │ ├── common
│ │ │ ├── ca.go
│ │ │ ├── io.go
│ │ │ ├── ne.go
│ │ │ ├── ppmgen.go
│ │ │ ├── template.go
│ │ │ └── utils.go
│ │ ├── fabric
│ │ │ ├── cc
│ │ │ │ └── tcc.go
│ │ │ ├── fabric.go
│ │ │ ├── opts.go
│ │ │ ├── template.go
│ │ │ └── topology.go
│ │ ├── factory.go
│ │ ├── generators
│ │ │ ├── commands
│ │ │ │ └── idemixgen.go
│ │ │ ├── components
│ │ │ │ └── components.go
│ │ │ ├── dlog
│ │ │ │ ├── dlog.go
│ │ │ │ ├── dlog_test.go
│ │ │ │ └── mock
│ │ │ │ │ └── token_platform.go
│ │ │ ├── fabtoken
│ │ │ │ └── fabtoken.go
│ │ │ └── generators.go
│ │ ├── options.go
│ │ ├── orion
│ │ │ ├── cmd
│ │ │ │ └── main.go
│ │ │ ├── orion.go
│ │ │ ├── rwset.go
│ │ │ ├── template.go
│ │ │ └── topology.go
│ │ ├── platform.go
│ │ ├── template.go
│ │ ├── topology.go
│ │ └── topology
│ │ │ ├── options.go
│ │ │ ├── topology.go
│ │ │ └── wallet.go
│ └── txgen
│ │ ├── executor.go
│ │ ├── model
│ │ ├── api
│ │ │ ├── error.go
│ │ │ └── types.go
│ │ ├── config.go
│ │ ├── constants
│ │ │ └── constants.go
│ │ └── distribution.go
│ │ └── service
│ │ ├── config
│ │ ├── reader.go
│ │ └── resources
│ │ │ └── config.yaml
│ │ ├── logging
│ │ └── logger.go
│ │ ├── metrics
│ │ ├── collector.go
│ │ ├── metrics.go
│ │ ├── provider.go
│ │ ├── reporter.go
│ │ └── types.go
│ │ ├── runner
│ │ ├── base_runner.go
│ │ ├── customer_state.go
│ │ ├── rest_runner.go
│ │ └── test_case.go
│ │ └── user
│ │ ├── intermediary_client.go
│ │ ├── rest
│ │ ├── intermediary_api.go
│ │ ├── provider.go
│ │ └── user.go
│ │ └── types.go
├── ports.go
└── token
│ ├── common
│ ├── sdk
│ │ ├── fall
│ │ │ ├── sdk.go
│ │ │ └── sdk_test.go
│ │ ├── fdlog
│ │ │ └── sdk.go
│ │ ├── ffabtoken
│ │ │ └── sdk.go
│ │ ├── fodlog
│ │ │ └── sdk.go
│ │ ├── fofabtoken
│ │ │ └── sdk.go
│ │ ├── identity
│ │ │ └── provider.go
│ │ ├── odlog
│ │ │ └── sdk.go
│ │ └── ofabtoken
│ │ │ └── sdk.go
│ ├── support.go
│ ├── topology.go
│ └── views
│ │ └── finality.go
│ ├── dvp
│ ├── README.md
│ ├── dlog
│ │ ├── dlog_suite_test.go
│ │ └── dlog_test.go
│ ├── fabtoken
│ │ ├── fabtoken_suite_test.go
│ │ └── fabtoken_test.go
│ ├── tests.go
│ ├── topology.go
│ └── views
│ │ ├── auditor.go
│ │ ├── balance.go
│ │ ├── buyer.go
│ │ ├── cash
│ │ ├── accept.go
│ │ ├── history.go
│ │ ├── issue.go
│ │ └── list.go
│ │ ├── house
│ │ ├── accept.go
│ │ ├── house.go
│ │ ├── issue.go
│ │ └── list.go
│ │ └── seller.go
│ ├── fungible
│ ├── dlog
│ │ ├── dlog_suite_test.go
│ │ └── dlog_test.go
│ ├── dloghsm
│ │ ├── dlog_suite_test.go
│ │ └── dlog_test.go
│ ├── dlogstress
│ │ ├── dlog_suite_test.go
│ │ ├── dlog_test.go
│ │ └── support
│ │ │ └── worker.go
│ ├── fabtoken
│ │ ├── fabtoken_suite_test.go
│ │ └── fabtoken_test.go
│ ├── mixed
│ │ ├── mixed_suite_test.go
│ │ ├── mixed_test.go
│ │ └── topology.go
│ ├── odlog
│ │ ├── dlog_suite_test.go
│ │ └── dlog_test.go
│ ├── ofabtoken
│ │ ├── fabtoken_suite_test.go
│ │ └── fabtoken_test.go
│ ├── sdk
│ │ ├── auditor
│ │ │ ├── sdk.go
│ │ │ └── sdk_test.go
│ │ ├── custodian
│ │ │ ├── sdk.go
│ │ │ └── sdk_test.go
│ │ ├── endorser
│ │ │ ├── sdk.go
│ │ │ └── sdk_test.go
│ │ ├── issuer
│ │ │ ├── sdk.go
│ │ │ └── sdk_test.go
│ │ └── party
│ │ │ ├── sdk.go
│ │ │ └── sdk_test.go
│ ├── support.go
│ ├── tests.go
│ ├── topology
│ │ └── topology.go
│ ├── update
│ │ ├── update_suite_test.go
│ │ └── update_test.go
│ ├── views
│ │ ├── accept.go
│ │ ├── auditor.go
│ │ ├── balance.go
│ │ ├── binding.go
│ │ ├── certifier.go
│ │ ├── checks.go
│ │ ├── history.go
│ │ ├── info.go
│ │ ├── issue.go
│ │ ├── list.go
│ │ ├── logger.go
│ │ ├── multisig.go
│ │ ├── owner.go
│ │ ├── redeem.go
│ │ ├── revoke.go
│ │ ├── swap.go
│ │ ├── transfer.go
│ │ ├── upgrade.go
│ │ ├── utils.go
│ │ ├── wallets.go
│ │ └── withdraw.go
│ └── wmp.go
│ ├── interop
│ ├── dlog
│ │ ├── dlog_suite_test.go
│ │ └── dlog_test.go
│ ├── fabtoken
│ │ ├── fabtoken_suite_test.go
│ │ └── fabtoken_test.go
│ ├── support.go
│ ├── tests.go
│ ├── topology.go
│ └── views
│ │ ├── accept.go
│ │ ├── auditor.go
│ │ ├── balance.go
│ │ ├── htlc
│ │ ├── claim.go
│ │ ├── exchange.go
│ │ ├── lock.go
│ │ ├── reclaim.go
│ │ └── scan.go
│ │ ├── issue.go
│ │ └── logger.go
│ ├── nft
│ ├── dlog
│ │ ├── dlog_suite_test.go
│ │ └── dlog_test.go
│ ├── fabtoken
│ │ ├── fabtoken_suite_test.go
│ │ └── fabtoken_test.go
│ ├── odlog
│ │ ├── dlog_suite_test.go
│ │ └── dlog_test.go
│ ├── ofabtoken
│ │ ├── fabtoken_suite_test.go
│ │ └── fabtoken_test.go
│ ├── tests.go
│ ├── topology.go
│ └── views
│ │ ├── accept.go
│ │ ├── auditor.go
│ │ ├── house.go
│ │ ├── issue.go
│ │ ├── list.go
│ │ └── transfer.go
│ └── test_utils.go
├── interop.mk
├── staticcheck.conf
├── token
├── actions.go
├── actions_test.go
├── authorization.go
├── certification.go
├── certification_test.go
├── config.go
├── core
│ ├── common
│ │ ├── authrorization.go
│ │ ├── backend.go
│ │ ├── deserializer.go
│ │ ├── encoding
│ │ │ ├── asn1
│ │ │ │ ├── asn1.go
│ │ │ │ └── asn1_test.go
│ │ │ ├── json
│ │ │ │ └── json.go
│ │ │ └── pp
│ │ │ │ ├── pp.go
│ │ │ │ └── pp_test.go
│ │ ├── loaders.go
│ │ ├── meta
│ │ │ └── metadata.go
│ │ ├── metrics
│ │ │ ├── metrics.go
│ │ │ └── provider.go
│ │ ├── ppm.go
│ │ ├── tms.go
│ │ ├── tracing
│ │ │ └── tracing.go
│ │ ├── validator.go
│ │ ├── validator_auditing.go
│ │ └── validator_auditing_test.go
│ ├── fabtoken
│ │ ├── protos-go
│ │ │ ├── actions
│ │ │ │ └── ftactions.pb.go
│ │ │ └── pp
│ │ │ │ └── ftpp.pb.go
│ │ ├── protos
│ │ │ ├── ftactions.proto
│ │ │ ├── ftpp.proto
│ │ │ └── generate.go
│ │ └── v1
│ │ │ ├── actions
│ │ │ ├── issue.go
│ │ │ ├── issue_test.go
│ │ │ ├── output.go
│ │ │ ├── transfer.go
│ │ │ └── transfer_test.go
│ │ │ ├── auditor.go
│ │ │ ├── driver
│ │ │ ├── base.go
│ │ │ ├── deserializer.go
│ │ │ ├── driver.go
│ │ │ ├── ppm_factory.go
│ │ │ └── ws_factory.go
│ │ │ ├── issue.go
│ │ │ ├── service.go
│ │ │ ├── setup
│ │ │ ├── setup.go
│ │ │ └── setup_test.go
│ │ │ ├── tokens.go
│ │ │ ├── transfer.go
│ │ │ └── validator
│ │ │ ├── validator.go
│ │ │ ├── validator_issue.go
│ │ │ └── validator_transfer.go
│ ├── service.go
│ ├── tms.go
│ └── zkatdlog
│ │ └── nogh
│ │ ├── protos-go
│ │ ├── actions
│ │ │ └── noghactions.pb.go
│ │ ├── math
│ │ │ └── noghmath.pb.go
│ │ ├── pp
│ │ │ └── noghpp.pb.go
│ │ └── utils
│ │ │ └── proto.go
│ │ ├── protos
│ │ ├── generate.go
│ │ ├── noghactions.proto
│ │ ├── noghmath.proto
│ │ └── noghpp.proto
│ │ └── v1
│ │ ├── audit
│ │ ├── audit_suite_test.go
│ │ ├── auditor.go
│ │ ├── auditor_test.go
│ │ ├── mock
│ │ │ └── signing_identity.go
│ │ └── testdata
│ │ │ └── idemix
│ │ │ ├── msp
│ │ │ ├── IssuerPublicKey
│ │ │ └── RevocationPublicKey
│ │ │ └── user
│ │ │ └── SignerConfig
│ │ ├── auditor.go
│ │ ├── crypto
│ │ ├── common
│ │ │ ├── array.go
│ │ │ └── identity.go
│ │ ├── math
│ │ │ ├── math.go
│ │ │ └── math_test.go
│ │ ├── rp
│ │ │ ├── bulletproof.go
│ │ │ ├── bulletproof_test.go
│ │ │ ├── ipa.go
│ │ │ ├── ipa_test.go
│ │ │ ├── rangecorrectness.go
│ │ │ └── rp_suite_test.go
│ │ └── upgrade
│ │ │ ├── mock
│ │ │ ├── des.go
│ │ │ └── ip.go
│ │ │ ├── proof.go
│ │ │ ├── proof_test.go
│ │ │ ├── service.go
│ │ │ └── service_test.go
│ │ ├── driver
│ │ ├── base.go
│ │ ├── deserializer.go
│ │ ├── driver.go
│ │ ├── ppm_factory.go
│ │ └── ws_factory.go
│ │ ├── issue.go
│ │ ├── issue
│ │ ├── action.go
│ │ ├── action_test.go
│ │ ├── issue_test.go
│ │ ├── issuer.go
│ │ ├── prover.go
│ │ ├── sametype.go
│ │ ├── sametype_test.go
│ │ └── verifier.go
│ │ ├── metrics.go
│ │ ├── service.go
│ │ ├── setup
│ │ ├── setup.go
│ │ ├── setup_test.go
│ │ └── testdata
│ │ │ └── idemix
│ │ │ └── msp
│ │ │ ├── IssuerPublicKey
│ │ │ └── RevocationPublicKey
│ │ ├── token
│ │ ├── fabtoken.go
│ │ ├── service.go
│ │ ├── token.go
│ │ └── token_test.go
│ │ ├── transfer.go
│ │ ├── transfer
│ │ ├── action.go
│ │ ├── action_test.go
│ │ ├── mock
│ │ │ └── signing_identity.go
│ │ ├── sender.go
│ │ ├── sender_test.go
│ │ ├── transfer.go
│ │ ├── transfer_suite_test.go
│ │ ├── transfer_test.go
│ │ ├── typeandsum.go
│ │ └── typeandsum_test.go
│ │ └── validator
│ │ ├── ledger.go
│ │ ├── mock
│ │ └── ledger.go
│ │ ├── testdata
│ │ └── idemix
│ │ │ ├── msp
│ │ │ ├── IssuerPublicKey
│ │ │ └── RevocationPublicKey
│ │ │ └── user
│ │ │ └── SignerConfig
│ │ ├── validator.go
│ │ ├── validator_issue.go
│ │ ├── validator_suite_test.go
│ │ ├── validator_test.go
│ │ └── validator_transfer.go
├── driver
│ ├── action.go
│ ├── auditor.go
│ ├── certfication.go
│ ├── config.go
│ ├── driver.go
│ ├── identity.go
│ ├── issue.go
│ ├── marshaller.go
│ ├── marshaller_test.go
│ ├── mock
│ │ ├── cc.go
│ │ ├── certification_storage.go
│ │ ├── cs.go
│ │ ├── deserializer.go
│ │ ├── ia.go
│ │ ├── ip.go
│ │ ├── pp.go
│ │ ├── ppm.go
│ │ ├── qe.go
│ │ ├── signature_provider.go
│ │ ├── signer.go
│ │ ├── ta.go
│ │ ├── ts.go
│ │ ├── tss.go
│ │ ├── uti.go
│ │ ├── validator.go
│ │ ├── validator_ledger.go
│ │ ├── verifier.go
│ │ └── ws.go
│ ├── protos-go
│ │ ├── pp
│ │ │ └── pp.pb.go
│ │ ├── request
│ │ │ └── request.pb.go
│ │ └── utils
│ │ │ └── proto.go
│ ├── protos
│ │ ├── generate.go
│ │ ├── pp.proto
│ │ └── request.proto
│ ├── publicparams.go
│ ├── request.go
│ ├── request_test.go
│ ├── sig.go
│ ├── tms.go
│ ├── tokens.go
│ ├── transfer.go
│ ├── validator.go
│ ├── vault.go
│ └── wallet.go
├── hashable.go
├── metadata.go
├── metadata_test.go
├── opts.go
├── provider.go
├── publicparams.go
├── publicparams_test.go
├── request.go
├── request_test.go
├── sdk
│ ├── db
│ │ ├── checks.go
│ │ └── config.go
│ ├── dig
│ │ ├── checks.go
│ │ ├── providers.go
│ │ ├── sdk.go
│ │ └── sdk_test.go
│ ├── identity
│ │ └── provider.go
│ ├── network
│ │ ├── certifier.go
│ │ └── selector.go
│ ├── tms
│ │ └── tms.go
│ └── vault
│ │ ├── pps.go
│ │ ├── provider.go
│ │ └── vault.go
├── selector.go
├── services
│ ├── auditdb
│ │ ├── filter.go
│ │ └── store.go
│ ├── auditor
│ │ ├── auditor.go
│ │ └── manager.go
│ ├── certifier
│ │ ├── client.go
│ │ ├── driver.go
│ │ ├── driver
│ │ │ └── driver.go
│ │ ├── dummy
│ │ │ └── driver.go
│ │ ├── interactive
│ │ │ ├── client.go
│ │ │ ├── driver.go
│ │ │ ├── metrics.go
│ │ │ └── service.go
│ │ ├── service.go
│ │ └── views
│ │ │ └── register.go
│ ├── config
│ │ ├── config.go
│ │ ├── config_test.go
│ │ └── testdata
│ │ │ └── token0
│ │ │ └── core.yaml
│ ├── db
│ │ ├── common
│ │ │ ├── checks.go
│ │ │ ├── retry.go
│ │ │ └── status.go
│ │ ├── dbtest
│ │ │ ├── identity.go
│ │ │ ├── notifier.go
│ │ │ ├── tokenlock.go
│ │ │ ├── tokens.go
│ │ │ ├── transactions.go
│ │ │ └── wallet.go
│ │ ├── driver
│ │ │ ├── audit.go
│ │ │ ├── common.go
│ │ │ ├── config.go
│ │ │ ├── driver.go
│ │ │ ├── identity.go
│ │ │ ├── token.go
│ │ │ └── ttx.go
│ │ ├── manager.go
│ │ └── sql
│ │ │ ├── common
│ │ │ ├── common.go
│ │ │ ├── identity.go
│ │ │ ├── init.go
│ │ │ ├── init_test.go
│ │ │ ├── query.go
│ │ │ ├── query_test.go
│ │ │ ├── querybuilder_test.go
│ │ │ ├── tcondition.go
│ │ │ ├── tokenlock.go
│ │ │ ├── tokens.go
│ │ │ ├── transactions.go
│ │ │ └── wallet.go
│ │ │ ├── memory
│ │ │ ├── driver.go
│ │ │ └── memory_test.go
│ │ │ ├── multiplexed
│ │ │ └── driver.go
│ │ │ ├── postgres
│ │ │ ├── driver.go
│ │ │ ├── identity.go
│ │ │ ├── postgres_test.go
│ │ │ ├── tokenlock.go
│ │ │ ├── tokens.go
│ │ │ ├── transactions.go
│ │ │ └── wallet.go
│ │ │ └── sqlite
│ │ │ ├── driver.go
│ │ │ ├── identity.go
│ │ │ ├── sqlite_test.go
│ │ │ ├── tokenlock.go
│ │ │ ├── tokenlock_test.go
│ │ │ ├── tokens.go
│ │ │ ├── transactions.go
│ │ │ └── wallet.go
│ ├── identity
│ │ ├── config
│ │ │ ├── identity.go
│ │ │ ├── identity_test.go
│ │ │ └── testdata
│ │ │ │ ├── invalid
│ │ │ │ └── core.yaml
│ │ │ │ └── token0
│ │ │ │ └── core.yaml
│ │ ├── deserializer
│ │ │ ├── deserializer.go
│ │ │ └── typed.go
│ │ ├── driver
│ │ │ ├── common.go
│ │ │ ├── config.go
│ │ │ ├── driver.go
│ │ │ ├── identity.go
│ │ │ ├── role.go
│ │ │ └── storage.go
│ │ ├── idemix
│ │ │ ├── cache
│ │ │ │ ├── cache.go
│ │ │ │ └── cache_test.go
│ │ │ ├── crypto
│ │ │ │ ├── audit.go
│ │ │ │ ├── bccsp.go
│ │ │ │ ├── config.go
│ │ │ │ ├── deserializer.go
│ │ │ │ ├── id.go
│ │ │ │ ├── protos-go
│ │ │ │ │ └── config
│ │ │ │ │ │ └── idemix_config.pb.go
│ │ │ │ └── protos
│ │ │ │ │ ├── generate.go
│ │ │ │ │ └── idemix_config.proto
│ │ │ ├── deserializer.go
│ │ │ ├── deserializer_test.go
│ │ │ ├── km.go
│ │ │ ├── km_test.go
│ │ │ ├── kmp.go
│ │ │ ├── kmp_test.go
│ │ │ └── testdata
│ │ │ │ ├── bls12_381_bbs
│ │ │ │ ├── idemix
│ │ │ │ │ ├── msp
│ │ │ │ │ │ ├── IssuerPublicKey
│ │ │ │ │ │ └── RevocationPublicKey
│ │ │ │ │ └── user
│ │ │ │ │ │ └── SignerConfig
│ │ │ │ └── idemix2
│ │ │ │ │ ├── msp
│ │ │ │ │ ├── IssuerPublicKey
│ │ │ │ │ └── RevocationPublicKey
│ │ │ │ │ └── user
│ │ │ │ │ └── SignerConfig
│ │ │ │ ├── fp256bn_amcl
│ │ │ │ ├── charlie.ExtraId2
│ │ │ │ │ ├── IssuerPublicKey
│ │ │ │ │ ├── IssuerRevocationPublicKey
│ │ │ │ │ ├── cacerts
│ │ │ │ │ │ └── localhost-7054-default-testchannel-token-chaincode-example-com.pem
│ │ │ │ │ └── user
│ │ │ │ │ │ └── SignerConfig
│ │ │ │ ├── idemix
│ │ │ │ │ ├── msp
│ │ │ │ │ │ ├── IssuerPublicKey
│ │ │ │ │ │ └── RevocationPublicKey
│ │ │ │ │ └── user
│ │ │ │ │ │ └── SignerConfig
│ │ │ │ ├── idemix2
│ │ │ │ │ ├── msp
│ │ │ │ │ │ ├── IssuerPublicKey
│ │ │ │ │ │ └── RevocationPublicKey
│ │ │ │ │ └── user
│ │ │ │ │ │ └── SignerConfig
│ │ │ │ └── sameissuer
│ │ │ │ │ ├── idemix
│ │ │ │ │ ├── msp
│ │ │ │ │ │ ├── IssuerPublicKey
│ │ │ │ │ │ └── RevocationPublicKey
│ │ │ │ │ └── user
│ │ │ │ │ │ └── SignerConfig
│ │ │ │ │ └── idemix2
│ │ │ │ │ ├── msp
│ │ │ │ │ ├── IssuerPublicKey
│ │ │ │ │ └── RevocationPublicKey
│ │ │ │ │ └── user
│ │ │ │ │ └── SignerConfig
│ │ │ │ └── generate.go
│ │ ├── interop
│ │ │ └── htlc
│ │ │ │ ├── deserializer.go
│ │ │ │ ├── info.go
│ │ │ │ └── validator.go
│ │ ├── membership
│ │ │ ├── identity.go
│ │ │ └── lm.go
│ │ ├── multisig
│ │ │ ├── deserializer.go
│ │ │ ├── deserializer_test.go
│ │ │ ├── identity.go
│ │ │ ├── identity_test.go
│ │ │ └── sig.go
│ │ ├── provider.go
│ │ ├── role
│ │ │ ├── factory.go
│ │ │ └── role.go
│ │ ├── roles.go
│ │ ├── sig
│ │ │ ├── deserializer.go
│ │ │ └── sigservice.go
│ │ ├── storage
│ │ │ └── kvs
│ │ │ │ ├── hashicorp
│ │ │ │ ├── go.mod
│ │ │ │ ├── go.sum
│ │ │ │ ├── identitydb_test.go
│ │ │ │ ├── vault_kvs.go
│ │ │ │ ├── vault_kvs_test.go
│ │ │ │ └── vault_kvs_test_utils.go
│ │ │ │ ├── identitydb.go
│ │ │ │ ├── kvs.go
│ │ │ │ ├── memory.go
│ │ │ │ ├── tracker.go
│ │ │ │ ├── tracker_test.go
│ │ │ │ └── walletdb.go
│ │ ├── typed.go
│ │ ├── typed_test.go
│ │ ├── wallet
│ │ │ ├── cache.go
│ │ │ ├── db
│ │ │ │ ├── registry.go
│ │ │ │ └── registry_test.go
│ │ │ ├── factory.go
│ │ │ ├── roles.go
│ │ │ ├── service.go
│ │ │ └── wallets.go
│ │ └── x509
│ │ │ ├── audit.go
│ │ │ ├── crypto
│ │ │ ├── bccsp.go
│ │ │ ├── config.go
│ │ │ ├── configbuilder.go
│ │ │ ├── csp
│ │ │ │ ├── csp.go
│ │ │ │ ├── ecdsa.go
│ │ │ │ ├── ecdsakey.go
│ │ │ │ ├── hash.go
│ │ │ │ ├── keyderiv.go
│ │ │ │ ├── keygen.go
│ │ │ │ ├── keyimport.go
│ │ │ │ ├── keys.go
│ │ │ │ └── kvsks.go
│ │ │ ├── deserializer.go
│ │ │ ├── ecdsa.go
│ │ │ ├── eidrh.go
│ │ │ ├── io.go
│ │ │ ├── mocks
│ │ │ │ ├── bccsp.go
│ │ │ │ └── key.go
│ │ │ ├── msp.go
│ │ │ ├── pkcs11
│ │ │ │ ├── disabled.go
│ │ │ │ └── pkcs11.go
│ │ │ ├── protos-go
│ │ │ │ └── config
│ │ │ │ │ └── x509_config.pb.go
│ │ │ ├── protos
│ │ │ │ ├── generate.go
│ │ │ │ └── x509_config.proto
│ │ │ ├── setup.go
│ │ │ ├── signer.go
│ │ │ └── signer_test.go
│ │ │ ├── deserializer.go
│ │ │ ├── km.go
│ │ │ ├── km_test.go
│ │ │ ├── kmp.go
│ │ │ └── testdata
│ │ │ ├── msp
│ │ │ ├── keystore
│ │ │ │ └── priv_sk
│ │ │ └── signcerts
│ │ │ │ └── auditor.org1.example.com-cert.pem
│ │ │ ├── msp1
│ │ │ └── signcerts
│ │ │ │ └── auditor.org1.example.com-cert.pem
│ │ │ └── msp2
│ │ │ ├── keystoreFull
│ │ │ └── priv_sk
│ │ │ └── signcerts
│ │ │ └── auditor.org1.example.com-cert.pem
│ ├── identitydb
│ │ ├── store.go
│ │ ├── store_test.go
│ │ └── testdata
│ │ │ └── sqlite
│ │ │ └── core.yaml
│ ├── interop
│ │ ├── encoding
│ │ │ ├── encoding.go
│ │ │ ├── encoding_test.go
│ │ │ └── logger.go
│ │ └── htlc
│ │ │ ├── accept.go
│ │ │ ├── audit.go
│ │ │ ├── distribute.go
│ │ │ ├── endorsement.go
│ │ │ ├── finality.go
│ │ │ ├── keys.go
│ │ │ ├── logger.go
│ │ │ ├── ordering.go
│ │ │ ├── recipients.go
│ │ │ ├── scanner.go
│ │ │ ├── script.go
│ │ │ ├── signer.go
│ │ │ ├── stream.go
│ │ │ ├── transaction.go
│ │ │ ├── wallet.go
│ │ │ └── wallet_filter.go
│ ├── logging
│ │ ├── logger.go
│ │ ├── mock.go
│ │ └── types.go
│ ├── network
│ │ ├── common
│ │ │ ├── fetcher.go
│ │ │ ├── filter.go
│ │ │ ├── finality.go
│ │ │ ├── finalitymanager.go
│ │ │ ├── normalizer.go
│ │ │ └── rws
│ │ │ │ ├── keys
│ │ │ │ └── keys.go
│ │ │ │ └── translator
│ │ │ │ ├── action.go
│ │ │ │ ├── issuer.go
│ │ │ │ ├── mock
│ │ │ │ ├── action_with_inputs.go
│ │ │ │ ├── issue_action.go
│ │ │ │ ├── rwset.go
│ │ │ │ └── transfer_action.go
│ │ │ │ ├── rwset.go
│ │ │ │ ├── translator.go
│ │ │ │ ├── translator_suite_test.go
│ │ │ │ └── translator_test.go
│ │ ├── driver
│ │ │ ├── driver.go
│ │ │ ├── envelope.go
│ │ │ ├── ledger.go
│ │ │ ├── lm.go
│ │ │ ├── network.go
│ │ │ ├── tokens.go
│ │ │ └── vault.go
│ │ ├── fabric
│ │ │ ├── config
│ │ │ │ └── config.go
│ │ │ ├── driver.go
│ │ │ ├── endorsement
│ │ │ │ ├── approval.go
│ │ │ │ ├── chaincode.go
│ │ │ │ ├── fsc.go
│ │ │ │ └── provider.go
│ │ │ ├── finality
│ │ │ │ ├── committerflm.go
│ │ │ │ ├── delivery.go
│ │ │ │ ├── deliveryflm.go
│ │ │ │ ├── deliveryqs.go
│ │ │ │ └── listenermanager.go
│ │ │ ├── lookup
│ │ │ │ ├── channelllm.go
│ │ │ │ ├── deliveryllm.go
│ │ │ │ ├── deliveryqs.go
│ │ │ │ └── manager.go
│ │ │ ├── network.go
│ │ │ ├── ppfetcher.go
│ │ │ ├── processor.go
│ │ │ ├── rws.go
│ │ │ ├── tcc
│ │ │ │ ├── certifier.go
│ │ │ │ ├── chaincode_suite_test.go
│ │ │ │ ├── main
│ │ │ │ │ └── main.go
│ │ │ │ ├── mock
│ │ │ │ │ ├── chaincode_stub_interface.go
│ │ │ │ │ ├── public_parameters_manager.go
│ │ │ │ │ └── validator.go
│ │ │ │ ├── params.go
│ │ │ │ ├── rwset.go
│ │ │ │ ├── shim.go
│ │ │ │ ├── tcc.go
│ │ │ │ └── tcc_test.go
│ │ │ └── tokenfetcher.go
│ │ ├── network.go
│ │ └── orion
│ │ │ ├── approval.go
│ │ │ ├── broadcast.go
│ │ │ ├── committerflm.go
│ │ │ ├── config.go
│ │ │ ├── driver.go
│ │ │ ├── lm.go
│ │ │ ├── lookupkey.go
│ │ │ ├── network.go
│ │ │ ├── processor.go
│ │ │ ├── publicparams.go
│ │ │ ├── querytokens.go
│ │ │ ├── rwset.go
│ │ │ ├── session.go
│ │ │ ├── spenttokens.go
│ │ │ ├── statusfetcher.go
│ │ │ ├── tms.go
│ │ │ ├── tokenfetcher.go
│ │ │ ├── txstatus.go
│ │ │ └── views.go
│ ├── nfttx
│ │ ├── filter.go
│ │ ├── marshaller
│ │ │ └── marshaller.go
│ │ ├── options.go
│ │ ├── qe.go
│ │ ├── qe_test.go
│ │ ├── recipient.go
│ │ ├── state.go
│ │ ├── streams.go
│ │ ├── transaction.go
│ │ ├── uniqueness
│ │ │ └── uniqueness.go
│ │ ├── uuid.go
│ │ ├── views.go
│ │ └── wallet.go
│ ├── selector
│ │ ├── README.md
│ │ ├── benchmark_test.go
│ │ ├── config
│ │ │ └── driver.go
│ │ ├── driver
│ │ │ └── driver.go
│ │ ├── sherdlock
│ │ │ ├── fetcher.go
│ │ │ ├── inmemory
│ │ │ │ └── locker.go
│ │ │ ├── manager.go
│ │ │ ├── manager_test.go
│ │ │ ├── metrics.go
│ │ │ ├── selector.go
│ │ │ └── service.go
│ │ ├── simple
│ │ │ ├── inmemory
│ │ │ │ ├── locker.go
│ │ │ │ └── locker_test.go
│ │ │ ├── manager.go
│ │ │ ├── selector.go
│ │ │ └── service.go
│ │ └── testutils
│ │ │ ├── test_cases.go
│ │ │ └── testutils.go
│ ├── tokendb
│ │ ├── store.go
│ │ ├── store_test.go
│ │ └── testdata
│ │ │ └── sqlite
│ │ │ └── core.yaml
│ ├── tokenlockdb
│ │ └── store.go
│ ├── tokens
│ │ ├── core
│ │ │ ├── comm
│ │ │ │ └── token.go
│ │ │ └── fabtoken
│ │ │ │ └── token.go
│ │ ├── driver
│ │ │ └── token.go
│ │ ├── manager.go
│ │ ├── storage.go
│ │ ├── tokens.go
│ │ ├── tokens_test.go
│ │ ├── typed.go
│ │ └── typed_test.go
│ ├── ttx
│ │ ├── accept.go
│ │ ├── auditor.go
│ │ ├── collect.go
│ │ ├── db.go
│ │ ├── endorse.go
│ │ ├── endorse_opts.go
│ │ ├── external.go
│ │ ├── finality.go
│ │ ├── info.go
│ │ ├── logger.go
│ │ ├── manager.go
│ │ ├── marshaller.go
│ │ ├── metrics.go
│ │ ├── multisig
│ │ │ ├── auth.go
│ │ │ ├── finality.go
│ │ │ ├── recipients.go
│ │ │ ├── spend.go
│ │ │ ├── tx.go
│ │ │ └── wallet.go
│ │ ├── opts.go
│ │ ├── ordering.go
│ │ ├── owner.go
│ │ ├── random.go
│ │ ├── recipients.go
│ │ ├── session.go
│ │ ├── status.go
│ │ ├── support.go
│ │ ├── transaction.go
│ │ ├── transfer_opts.go
│ │ ├── upgrade.go
│ │ ├── wallet.go
│ │ └── withdrawal.go
│ ├── ttxdb
│ │ ├── README.md
│ │ ├── store.go
│ │ ├── store_test.go
│ │ └── testdata
│ │ │ └── sqlite
│ │ │ └── core.yaml
│ ├── utils
│ │ ├── closer.go
│ │ ├── drivers
│ │ │ └── holder.go
│ │ ├── functions.go
│ │ ├── hashable.go
│ │ ├── json
│ │ │ ├── decoder.go
│ │ │ ├── decoder_test.go
│ │ │ └── session
│ │ │ │ └── json.go
│ │ ├── protos
│ │ │ └── protos.go
│ │ ├── slices
│ │ │ └── slices.go
│ │ ├── types
│ │ │ └── transaction
│ │ │ │ └── types.go
│ │ └── view
│ │ │ └── view.go
│ └── walletdb
│ │ ├── store.go
│ │ ├── store_test.go
│ │ └── testdata
│ │ └── sqlite
│ │ └── core.yaml
├── sig.go
├── sig_test.go
├── stream.go
├── stream_test.go
├── tms.go
├── token
│ ├── quantity.go
│ ├── quantity_test.go
│ └── token.go
├── tokens.go
├── validator.go
├── validator_test.go
├── vault.go
├── vault_test.go
└── wallet.go
└── tools
├── go.mod
├── go.sum
└── tools.go
/.github/workflows/codeql-analysis.yml:
--------------------------------------------------------------------------------
1 | name: "CodeQL"
2 |
3 | on:
4 | push:
5 | branches: [ "main" ]
6 | pull_request:
7 | branches: [ "main" ]
8 | schedule:
9 | - cron: '39 22 * * 5'
10 |
11 | jobs:
12 | analyze:
13 | name: Analyze
14 | runs-on: 'ubuntu-latest'
15 | timeout-minutes: 60
16 | permissions:
17 | security-events: write
18 | packages: read
19 | actions: read
20 | contents: read
21 |
22 | steps:
23 | - name: Checkout repository
24 | uses: actions/checkout@v4
25 |
26 | - name: Initialize CodeQL
27 | uses: github/codeql-action/init@v3
28 | with:
29 | languages: go
30 | build-mode: manual
31 |
32 | - name: Build manually
33 | shell: bash
34 | run: |
35 | go build -o tokengen ./cmd/tokengen
36 |
37 | - name: Perform CodeQL Analysis
38 | uses: github/codeql-action/analyze@v3
39 | with:
40 | category: "/language:go"
41 |
--------------------------------------------------------------------------------
/.github/workflows/golangci-lint.yml:
--------------------------------------------------------------------------------
1 | name: golangci-lint
2 |
3 | on:
4 | push:
5 | branches:
6 | - master
7 | - main
8 | pull_request:
9 | # The branches below must be a subset of the branches above
10 | branches: [ main ]
11 |
12 | permissions:
13 | contents: read
14 | # Optional: allow read access to pull request. Use with `only-new-issues` option.
15 | # pull-requests: read
16 |
17 | jobs:
18 | golangci:
19 | name: lint
20 | runs-on: ubuntu-latest
21 | steps:
22 | - uses: actions/checkout@v4
23 | - uses: actions/setup-go@v5
24 | with:
25 | go-version-file: "go.mod"
26 | cache: false
27 | - name: golangci-lint
28 | uses: golangci/golangci-lint-action@v7
29 | with:
30 | version: v2.0
31 | args: --timeout=30m
--------------------------------------------------------------------------------
/.github/workflows/md_links.yml:
--------------------------------------------------------------------------------
1 | name: Check Markdown links
2 |
3 | on:
4 | push:
5 | branches: [ main ]
6 | pull_request:
7 | branches: [ main ]
8 |
9 | jobs:
10 | check-links:
11 | name: runner / linkspector
12 | runs-on: ubuntu-latest
13 | steps:
14 | - uses: actions/checkout@v4
15 | - name: Run linkspector
16 | uses: umbrelladocs/action-linkspector@v1
17 | with:
18 | github_token: ${{ secrets.github_token }}
19 | reporter: github-pr-review
20 | fail_on_error: true
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /.idea/
2 | .DS_Store
3 | *.iml
4 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | Code of Conduct Guidelines
2 | ==========================
3 |
4 | Please review the Hyperledger [Code of
5 | Conduct](https://lf-decentralized-trust.github.io/governance/governing-documents/code-of-conduct.html#code-of-conduct)
6 | before participating. It is important that we keep things civil.
7 |
8 | 
This work is licensed under a Creative Commons Attribution 4.0 International License.
9 |
--------------------------------------------------------------------------------
/SECURITY.md:
--------------------------------------------------------------------------------
1 | # Hyperledger Security Policy
2 |
3 | ## Reporting a Security Bug
4 |
5 | If you think you have discovered a security issue in any of the Hyperledger projects, we'd love to hear from you. We will take all security bugs seriously and if confirmed upon investigation we will patch it within a reasonable amount of time and release a public security bulletin discussing the impact and credit the discoverer.
6 |
7 | The easiest is to email a description of the flaw and any related information (e.g. reproduction steps, version) to [security at hyperledger dot org](mailto:security@hyperledger.org).
8 |
9 | The process by which the Hyperledger Security Team handles security bugs is documented further in our [Defect Response page](https://wiki.hyperledger.org/display/SEC/Defect+Response) on our [wiki](https://wiki.hyperledger.org).
10 |
--------------------------------------------------------------------------------
/ci/scripts/cleanup_softhsm.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | LABEL_TO_DELETE="ForFSC"
4 |
5 | # Get all slot numbers
6 | slots=$(softhsm2-util --show-slots | grep "Slot " | awk '{print $2}')
7 |
8 | for slot in $slots
9 | do
10 | # Check if the token in this slot has the label we want to delete
11 | label=$(softhsm2-util --show-slots | grep -A 2 "Slot $slot" | grep "Label:" | awk '{print $2}')
12 | if [ "$label" == "$LABEL_TO_DELETE" ]; then
13 | echo "Deleting token in slot $slot with label $LABEL_TO_DELETE"
14 | softhsm2-util --delete-token --token "$LABEL_TO_DELETE"
15 | fi
16 | done
--------------------------------------------------------------------------------
/ci/scripts/install_softhsm.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Copyright the Hyperledger Fabric contributors. All rights reserved.
3 | #
4 | # SPDX-License-Identifier: Apache-2.0
5 | set -euo pipefail
6 |
7 | #Install softhsm
8 | if [[ "$OSTYPE" == "darwin"* ]]; then
9 | brew install softhsm
10 | else
11 | sudo apt-get install -y softhsm2
12 | fi
--------------------------------------------------------------------------------
/ci/scripts/setup_softhsm.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Copyright the Hyperledger Fabric contributors. All rights reserved.
3 | #
4 | # SPDX-License-Identifier: Apache-2.0
5 | set -euo pipefail
6 |
7 | CONFIGPATH=$HOME/.config/softhsm2
8 |
9 | mkdir -p $CONFIGPATH
10 |
11 | if [[ "$OSTYPE" == "darwin"* ]]; then
12 |
13 | # Move softhsm config file inside config path
14 | export SOFTHSM2_CONF=$CONFIGPATH/softhsm2.conf
15 |
16 | # Create tokens inside tmp folder
17 | echo directories.tokendir = /tmp > $CONFIGPATH/softhsm2.conf
18 |
19 | echo "Initializing tokens..."
20 | softhsm2-util --init-token --free --label "ForFSC" --so-pin 1234 --pin 98765432
21 |
22 | else
23 |
24 | #Create directory to store hsm tokens
25 | sudo mkdir -p /var/lib/softhsm/tokens
26 |
27 | echo "Initializing tokens..."
28 | sudo softhsm2-util --init-token --slot 0 --label "ForFSC" --so-pin 1234 --pin 98765432
29 |
30 | sudo chmod -R 777 /var/lib/softhsm
31 | cp /usr/share/softhsm/softhsm2.conf $CONFIGPATH
32 |
33 | fi
34 |
--------------------------------------------------------------------------------
/cmd/tokengen/cobra/artifactgen/utils.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package artifactgen
8 |
9 | import (
10 | "io/fs"
11 | "os"
12 |
13 | "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/api"
14 | "github.com/pkg/errors"
15 | "gopkg.in/yaml.v2"
16 | )
17 |
18 | type Topologies struct {
19 | Topologies []api.Topology `yaml:"topologies,omitempty"`
20 | }
21 |
22 | func WriteTopologies(fileName string, topologies []api.Topology, perm fs.FileMode) error {
23 | raw, err := yaml.Marshal(&Topologies{Topologies: topologies})
24 | if err != nil {
25 | return errors.Wrap(err, "failed to marshal topologies")
26 | }
27 | if err := os.WriteFile(fileName, raw, perm); err != nil {
28 | return errors.Wrapf(err, "failed to write to [%s]", fileName)
29 | }
30 | return nil
31 | }
32 |
--------------------------------------------------------------------------------
/cmd/tokengen/cobra/pp/cc/params.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package cc
8 |
9 | // DefaultParams defines the template for the public parameters burned into
10 | // the token chaincode.
11 | const DefaultParams = `
12 | package tcc
13 |
14 | const Params = "{{ Params }}"
15 | `
16 |
--------------------------------------------------------------------------------
/cmd/tokengen/cobra/pp/gen.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package pp
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-token-sdk/cmd/tokengen/cobra/pp/dlog"
11 | "github.com/hyperledger-labs/fabric-token-sdk/cmd/tokengen/cobra/pp/fabtoken"
12 | "github.com/spf13/cobra"
13 | )
14 |
15 | // GenCmd returns the Cobra Command for Public Params Generation
16 | func GenCmd() *cobra.Command {
17 | genCobraCommand.AddCommand(fabtoken.Cmd())
18 | genCobraCommand.AddCommand(dlog.Cmd())
19 |
20 | return genCobraCommand
21 | }
22 |
23 | var genCobraCommand = &cobra.Command{
24 | Use: "gen",
25 | Short: "Gen public parameters.",
26 | Long: `Generates public parameters.`,
27 | }
28 |
--------------------------------------------------------------------------------
/cmd/tokengen/cobra/pp/idemix/idemix.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package idemix
8 |
9 | import (
10 | "os"
11 | "path/filepath"
12 |
13 | "github.com/IBM/idemix"
14 | "github.com/pkg/errors"
15 | )
16 |
17 | // LoadIssuerPublicKey reads the issuer public key from the config file
18 | func LoadIssuerPublicKey(idemixMSPDir string) (string, []byte, error) {
19 | // Load Idemix Issuer Public Key
20 | path := filepath.Join(idemixMSPDir, idemix.IdemixConfigDirMsp, idemix.IdemixConfigFileIssuerPublicKey)
21 | ipkBytes, err := os.ReadFile(path)
22 | if err != nil {
23 | return "", nil, errors.Wrapf(err, "failed reading idemix issuer public key [%s]", path)
24 | }
25 |
26 | return path, ipkBytes, nil
27 | }
28 |
--------------------------------------------------------------------------------
/cmd/tokengen/cobra/pp/update.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package pp
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-token-sdk/cmd/tokengen/cobra/pp/dlog"
11 | "github.com/spf13/cobra"
12 | )
13 |
14 | // UpdateCmd returns the Cobra Command for updating the config file
15 | func UpdateCmd() *cobra.Command {
16 | // not implemented for fabtoken
17 | updateCobraCommand.AddCommand(dlog.UpdateCmd())
18 |
19 | return updateCobraCommand
20 | }
21 |
22 | var updateCobraCommand = &cobra.Command{
23 | Use: "update",
24 | Short: "Update certs in the public parameters file.",
25 | Long: "Update auditor and issuer certs in the public parameters file without changing the parameters themselves.",
26 | }
27 |
--------------------------------------------------------------------------------
/cmd/tokengen/cobra/pp/utils.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package pp
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-token-sdk/cmd/tokengen/cobra/pp/printpp"
11 | "github.com/spf13/cobra"
12 | )
13 |
14 | // UtilsCmd returns the Cobra Command for Public Params Utils command
15 | func UtilsCmd() *cobra.Command {
16 | utilsCobraCommand.AddCommand(printpp.Cmd())
17 |
18 | return utilsCobraCommand
19 | }
20 |
21 | var utilsCobraCommand = &cobra.Command{
22 | Use: "pp",
23 | Short: "Public parameters utils.",
24 | Long: `Public parameters utility commands`,
25 | }
26 |
--------------------------------------------------------------------------------
/cmd/tokengen/testdata/auditors/msp/signcerts/auditor.Orgauditor.example.com-cert.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIICrTCCAlOgAwIBAgIRAJPBld/0Ufm+0SKjD3aaWtEwCgYIKoZIzj0EAwIwfzEL
3 | MAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG
4 | cmFuY2lzY28xHzAdBgNVBAoTFk9yZ2F1ZGl0b3IuZXhhbXBsZS5jb20xIjAgBgNV
5 | BAMTGWNhLk9yZ2F1ZGl0b3IuZXhhbXBsZS5jb20wHhcNMjIwNzE4MTUwMzAwWhcN
6 | MzIwNzE1MTUwMzAwWjBjMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5p
7 | YTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzEnMCUGA1UEAxMeYXVkaXRvci5Pcmdh
8 | dWRpdG9yLmV4YW1wbGUuY29tMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHbPv
9 | /8z5yLR8PTyNGWr7xAbFoYm8RruxCwDJWn9TB8QAuxh3jiizJn0c3FdL/lYagXGF
10 | Vbr2u09HN45VSFhmeaOByzCByDAOBgNVHQ8BAf8EBAMCB4AwDAYDVR0TAQH/BAIw
11 | ADArBgNVHSMEJDAigCCLXgxScbI8RZ1Hk/lYz9sDORf9fhcpOxz1BuSaGtrENDB7
12 | BggqAwQFBgcIAQRveyJhdHRycyI6eyJoZi5BZmZpbGlhdGlvbiI6IiIsImhmLkVu
13 | cm9sbG1lbnRJRCI6ImF1ZGl0b3IuT3JnYXVkaXRvci5leGFtcGxlLmNvbSIsImhm
14 | LlR5cGUiOiIiLCJyZWxheSI6ImZhbHNlIn19MAoGCCqGSM49BAMCA0gAMEUCIQDd
15 | I4ykdDPKDQAZP2NibXK9YTKwKSf/irXtBTy2WzoJnwIgUwWACGO0VaYidrft+As3
16 | OcxRRb1faC4kYUzx6/2ahxg=
17 | -----END CERTIFICATE-----
18 |
--------------------------------------------------------------------------------
/cmd/tokengen/testdata/idemix/ca/IssuerPublicKey:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/cmd/tokengen/testdata/idemix/ca/IssuerPublicKey
--------------------------------------------------------------------------------
/cmd/tokengen/testdata/idemix/ca/IssuerSecretKey:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/cmd/tokengen/testdata/idemix/ca/IssuerSecretKey
--------------------------------------------------------------------------------
/cmd/tokengen/testdata/idemix/ca/RevocationKey:
--------------------------------------------------------------------------------
1 | -----BEGIN PRIVATE KEY-----
2 | MIGkAgEBBDCJyYgTvcBn2lVT1S8IiX8ghy7bHohIpc6UPNQ7yocIZACgoSVWwkqy
3 | 6gVMj5CnlUGgBwYFK4EEACKhZANiAASn7upO2IQY7JWYrAY4I1pFynTUT9U7T+bn
4 | 1e+oYMccLbFOebMeORJwAGVf/MhfywJ2wBV9QiXnzfKgpI4wcllddPX9cOwEkKyG
5 | iGf7ynMEcFxQJGh4e8h29AhPQDZgEfA=
6 | -----END PRIVATE KEY-----
7 |
--------------------------------------------------------------------------------
/cmd/tokengen/testdata/idemix/msp/IssuerPublicKey:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/cmd/tokengen/testdata/idemix/msp/IssuerPublicKey
--------------------------------------------------------------------------------
/cmd/tokengen/testdata/idemix/msp/RevocationPublicKey:
--------------------------------------------------------------------------------
1 | -----BEGIN PUBLIC KEY-----
2 | MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEp+7qTtiEGOyVmKwGOCNaRcp01E/VO0/m
3 | 59XvqGDHHC2xTnmzHjkScABlX/zIX8sCdsAVfUIl583yoKSOMHJZXXT1/XDsBJCs
4 | hohn+8pzBHBcUCRoeHvIdvQIT0A2YBHw
5 | -----END PUBLIC KEY-----
6 |
--------------------------------------------------------------------------------
/cmd/tokengen/testdata/issuers/msp/signcerts/issuer.Orgissuer.example.com-cert.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIICpTCCAk2gAwIBAgIRAO4DgC8ieilTsP9CGVW0qhgwCgYIKoZIzj0EAwIwfTEL
3 | MAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBG
4 | cmFuY2lzY28xHjAcBgNVBAoTFU9yZ2lzc3Vlci5leGFtcGxlLmNvbTEhMB8GA1UE
5 | AxMYY2EuT3JnaXNzdWVyLmV4YW1wbGUuY29tMB4XDTIyMDcxODE1MDMwMFoXDTMy
6 | MDcxNTE1MDMwMFowYTELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWEx
7 | FjAUBgNVBAcTDVNhbiBGcmFuY2lzY28xJTAjBgNVBAMTHGlzc3Vlci5Pcmdpc3N1
8 | ZXIuZXhhbXBsZS5jb20wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAARZq2YrNYdk
9 | lQczxLGfHuN2ULQ8q1Mz/z6JFpRCLTfgkdJGNWTSsVvobs9D5mtBiq42Zm7NMxM/
10 | eIOod5get56/o4HJMIHGMA4GA1UdDwEB/wQEAwIHgDAMBgNVHRMBAf8EAjAAMCsG
11 | A1UdIwQkMCKAIFGK7uw45Dz1N2LizaICHQk9j9NNQY/QuEBGnFDz5a+WMHkGCCoD
12 | BAUGBwgBBG17ImF0dHJzIjp7ImhmLkFmZmlsaWF0aW9uIjoiIiwiaGYuRW5yb2xs
13 | bWVudElEIjoiaXNzdWVyLk9yZ2lzc3Vlci5leGFtcGxlLmNvbSIsImhmLlR5cGUi
14 | OiIiLCJyZWxheSI6ImZhbHNlIn19MAoGCCqGSM49BAMCA0YAMEMCIDtNjglkoDcK
15 | hTcYQHq05Wikw/cdgaE2mjPFLA9OmumgAh96lb9ppHXC7Z3FaSMXeaQ0d8OqsEZn
16 | UYd7hAfyik0e
17 | -----END CERTIFICATE-----
18 |
--------------------------------------------------------------------------------
/deps.go:
--------------------------------------------------------------------------------
1 | //go:build deps
2 |
3 | /*
4 | Copyright IBM Corp. All Rights Reserved.
5 |
6 | SPDX-License-Identifier: Apache-2.0
7 | */
8 |
9 | package deps
10 |
11 | import (
12 | _ "github.com/IBM/idemix/tools/idemixgen"
13 | )
14 |
--------------------------------------------------------------------------------
/docs/drivers/drivers.md:
--------------------------------------------------------------------------------
1 | # Drivers
2 |
3 | The Token SDK comes equipped with two driver implementations:
4 | - [`FabToken`](fabtoken.md): This is a simple implementation of the Driver API that does not support privacy.
5 | - [`ZKAT DLog`](zkat-dlog.md): This driver supports privacy via Zero Knowledge. We follow
6 | a simplified version of the blueprint described in the paper
7 | [`Privacy-preserving auditable token payments in a permissioned blockchain system`]('https://eprint.iacr.org/2019/1058.pdf')
8 | by Androulaki et al.
--------------------------------------------------------------------------------
/docs/imgs/commit_process.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/docs/imgs/commit_process.png
--------------------------------------------------------------------------------
/docs/imgs/deployment.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/docs/imgs/deployment.png
--------------------------------------------------------------------------------
/docs/imgs/driver_api.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/docs/imgs/driver_api.png
--------------------------------------------------------------------------------
/docs/imgs/fabric_ttx_lifecycle.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/docs/imgs/fabric_ttx_lifecycle.png
--------------------------------------------------------------------------------
/docs/imgs/orion_ttx_lifecycle.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/docs/imgs/orion_ttx_lifecycle.png
--------------------------------------------------------------------------------
/docs/imgs/stack.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/docs/imgs/stack.png
--------------------------------------------------------------------------------
/docs/imgs/token_api.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/docs/imgs/token_api.png
--------------------------------------------------------------------------------
/docs/imgs/token_processing.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/docs/imgs/token_processing.png
--------------------------------------------------------------------------------
/docs/imgs/token_request.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/docs/imgs/token_request.png
--------------------------------------------------------------------------------
/docs/imgs/token_request_translation.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/docs/imgs/token_request_translation.png
--------------------------------------------------------------------------------
/docs/imgs/token_request_translator.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/docs/imgs/token_request_translator.png
--------------------------------------------------------------------------------
/docs/imgs/token_vault.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/docs/imgs/token_vault.png
--------------------------------------------------------------------------------
/docs/itests.md:
--------------------------------------------------------------------------------
1 | # Integration tests
2 |
3 | Integration tests are useful to show how multiple components work together.
4 | The Fabric Smart Client comes equipped with some of them to show the main features.
5 | To run the integration tests, you need to have Docker installed and ready to be used.
6 |
7 | Each integration test bootstraps the FSC and Fabric networks as needed, and initiate the
8 | business processes by invoking the `initiator view` on the specific FSC nodes.
9 |
10 | All integration tests can be executed by executing `make integration-tests`
11 | from the folder `$GOPATH/github.com/hyperledger-labs/fabric-token-sdk`.
12 | Each test can be executed either using your preferred IDE or by executing `go test` from
13 | the folder that contains the test you want to try.
14 |
15 | Here is a list of available examples:
16 |
17 | - [`DvP`](../integration/token/dvp/README.md): In this example, we see how to orchestrate a Delivery vs Payment use-case
18 |
19 | ## Further information
20 |
21 | Almost all the samples and integration tests require the fabric binaries to be downloaded and the environment variable `FAB_BINS` set to point to the directory where these binaries are stored. One way to ensure this is to execute the following in the root of the fabric-smart-client project
22 |
23 | ```shell
24 | make download-fabric
25 | export FAB_BINS=$PWD/../fabric/bin
26 | ```
27 |
--------------------------------------------------------------------------------
/integration/nwo/token/commands/tokengen.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | package commands
7 |
8 | type CertifierKeygen struct {
9 | Driver string
10 | PPPath string
11 | Output string
12 | }
13 |
14 | func (c CertifierKeygen) SessionName() string {
15 | return "tokengen-certifier-keygen"
16 | }
17 |
18 | func (c CertifierKeygen) Args() []string {
19 | return []string{
20 | "certifier-keygen",
21 | "--driver", c.Driver,
22 | "--pppath", c.PPPath,
23 | "--output", c.Output,
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/integration/nwo/token/common/io.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package common
8 |
9 | import (
10 | "io"
11 | "os"
12 | "path/filepath"
13 |
14 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/utils"
15 | )
16 |
17 | func CopyFile(src, dst string) error {
18 | cleanSrc := filepath.Clean(src)
19 | cleanDst := filepath.Clean(dst)
20 | if cleanSrc == cleanDst {
21 | return nil
22 | }
23 | sf, err := os.Open(cleanSrc)
24 | if err != nil {
25 | return err
26 | }
27 | defer utils.IgnoreError(sf.Close)
28 | df, err := os.Create(cleanDst)
29 | if err != nil {
30 | return err
31 | }
32 | defer utils.IgnoreError(df.Close)
33 | _, err = io.Copy(df, sf)
34 | return err
35 | }
36 |
37 | func CopyDir(srcDir, destDir string) error {
38 | entries, err := os.ReadDir(srcDir)
39 | if err != nil {
40 | return err
41 | }
42 | if err := os.MkdirAll(destDir, os.ModePerm); err != nil {
43 | return err
44 | }
45 | for _, entry := range entries {
46 | srcPath := filepath.Join(srcDir, entry.Name())
47 | destPath := filepath.Join(destDir, entry.Name())
48 | if entry.IsDir() {
49 | if err := CopyDir(srcPath, destPath); err != nil {
50 | return err
51 | }
52 | } else {
53 | if err := CopyFile(srcPath, destPath); err != nil {
54 | return err
55 | }
56 | }
57 | }
58 | return nil
59 | }
60 |
--------------------------------------------------------------------------------
/integration/nwo/token/fabric/topology.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package fabric
8 |
9 | import "github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token/topology"
10 |
11 | func SetOrgs(tms *topology.TMS, orgs ...string) *topology.TMS {
12 | tms.BackendParams["fabric.orgs"] = orgs
13 | return tms
14 | }
15 |
--------------------------------------------------------------------------------
/integration/nwo/token/factory.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package token
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/api"
11 | fabric2 "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/fabric"
12 | "github.com/hyperledger-labs/fabric-smart-client/integration/nwo/orion"
13 | "github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token/fabric"
14 | "github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token/fabric/cc"
15 | orion2 "github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token/orion"
16 | )
17 |
18 | type platformFactory struct{}
19 |
20 | func NewPlatformFactory() *platformFactory {
21 | return &platformFactory{}
22 | }
23 |
24 | func (p *platformFactory) Name() string {
25 | return "token"
26 | }
27 |
28 | func (p *platformFactory) New(ctx api.Context, t api.Topology, builder api.Builder) api.Platform {
29 | tp := NewPlatform(ctx, t, builder)
30 | tp.AddNetworkHandler(fabric2.TopologyName, fabric.NewNetworkHandler(tp, builder, cc.NewDefaultGenericBackend(tp)))
31 | tp.AddNetworkHandler(orion.TopologyName, orion2.NewNetworkHandler(tp, builder))
32 | return tp
33 | }
34 |
--------------------------------------------------------------------------------
/integration/nwo/token/generators/components/components.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package components
8 |
9 | type BuilderClient interface {
10 | Build(path string) string
11 | }
12 |
13 | type Builder struct {
14 | client BuilderClient
15 | }
16 |
17 | func NewBuilder(client BuilderClient) *Builder {
18 | return &Builder{client: client}
19 | }
20 |
21 | func (c *Builder) Build(path string) string {
22 | return c.client.Build(path)
23 | }
24 |
25 | func (c *Builder) FSCCLI() string {
26 | return c.Build("github.com/hyperledger-labs/fabric-smart-client/cmd/fsccli")
27 | }
28 |
--------------------------------------------------------------------------------
/integration/nwo/token/orion/topology.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package orion
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/token/topology"
11 | )
12 |
13 | const (
14 | Custodian = "orion.custodian"
15 | )
16 |
17 | func SetCustodian(tms *topology.TMS, custodian string) *topology.TMS {
18 | tms.BackendParams[Custodian] = custodian
19 | return tms
20 | }
21 |
--------------------------------------------------------------------------------
/integration/nwo/token/template.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package token
8 |
9 | const Extension = `
10 | token:
11 | version: v1
12 | enabled: true
13 | selector:
14 | driver: {{ TokenSelector }}
15 | finality:
16 | type: {{ FinalityType }}
17 | delivery:
18 | mapperParallelism: 10
19 | lruSize: 100
20 | lruBuffer: 50
21 | listenerTimeout: 30s
22 | `
23 |
--------------------------------------------------------------------------------
/integration/nwo/token/topology/wallet.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package topology
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/identity/x509/crypto"
11 | )
12 |
13 | type Identity struct {
14 | ID string
15 | Type string
16 | Path string
17 | Default bool
18 | Opts *crypto.BCCSP
19 | Raw []byte
20 | }
21 |
22 | type Wallets struct {
23 | Certifiers []Identity
24 | Issuers []Identity
25 | Owners []Identity
26 | Auditors []Identity
27 | }
28 |
--------------------------------------------------------------------------------
/integration/nwo/txgen/model/api/types.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package api
8 |
9 | type Amount = int64
10 | type UUID [16]byte
11 |
12 | func (u UUID) String() string {
13 | return string(u[:])
14 | }
15 |
--------------------------------------------------------------------------------
/integration/nwo/txgen/service/logging/logger.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package logging
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-smart-client/platform/common/services/logging"
11 | "github.com/hyperledger-labs/fabric-smart-client/platform/common/utils"
12 | )
13 |
14 | type Logger = logging.Logger
15 |
16 | // MustGetLogger Get a logger.
17 | func MustGetLogger(params ...string) Logger {
18 | return utils.MustGet(GetLogger(params...))
19 | }
20 |
21 | func GetLogger(params ...string) (Logger, error) {
22 | return logging.GetLoggerWithReplacements(map[string]string{"github.com.hyperledger-labs.fabric-token-sdk.integration": "fts"}, params)
23 | }
24 |
--------------------------------------------------------------------------------
/integration/nwo/txgen/service/metrics/types.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package metrics
8 |
9 | import (
10 | "time"
11 |
12 | c "github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/txgen/model/constants"
13 | )
14 |
15 | type Reporter interface {
16 | GetTotalRequests() string
17 | GetActiveRequests() string
18 | Summary() string
19 | }
20 |
21 | type Collector interface {
22 | IncrementRequests()
23 | DecrementRequests()
24 | AddDuration(millisDuration time.Duration, requestType c.ApiRequestType, success bool)
25 | }
26 |
--------------------------------------------------------------------------------
/integration/nwo/txgen/service/runner/customer_state.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package runner
8 |
9 | import (
10 | "sync/atomic"
11 |
12 | "github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/txgen/model"
13 | "github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/txgen/model/api"
14 | )
15 |
16 | type customerState struct {
17 | Name model.UserAlias
18 | PaidAmount api.Amount
19 | ReceivedAmount api.Amount
20 | StartingAmount api.Amount
21 | WithdrawnAmount api.Amount
22 | //Transactions map[string]int // TODO think better how to store transactions
23 | }
24 |
25 | func (p *customerState) AddWithdrawn(m api.Amount) {
26 | atomic.AddInt64(&p.WithdrawnAmount, m)
27 | }
28 |
29 | func (p *customerState) AddPaidMount(m api.Amount) {
30 | atomic.AddInt64(&p.PaidAmount, m)
31 | }
32 |
33 | func (p *customerState) AddReceivedMount(m api.Amount) {
34 | atomic.AddInt64(&p.ReceivedAmount, m)
35 | }
36 |
--------------------------------------------------------------------------------
/integration/nwo/txgen/service/user/rest/intermediary_api.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package rest
8 |
9 | type LoginRequest struct {
10 | Username string `json:"username"`
11 | Password string `json:"password"`
12 | }
13 |
14 | type LoginResponse struct {
15 | Token string `json:"token"`
16 | }
17 |
18 | type BalanceResponse struct {
19 | Balance struct {
20 | Type string `json:"type"`
21 | Quantity string `json:"quantity"`
22 | } `json:"balance"`
23 | }
24 |
--------------------------------------------------------------------------------
/integration/nwo/txgen/service/user/types.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package user
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/txgen/model"
11 | txgen "github.com/hyperledger-labs/fabric-token-sdk/integration/nwo/txgen/model/api"
12 | )
13 |
14 | type Provider interface {
15 | Get(alias model.UserAlias) User
16 | }
17 |
18 | type User interface {
19 | Username() model.Username
20 | InitiateTransfer(value txgen.Amount, nonce txgen.UUID) txgen.Error
21 | Transfer(value txgen.Amount, recipient model.Username, nonce txgen.UUID) txgen.Error
22 | Withdraw(value txgen.Amount) txgen.Error
23 | GetBalance() (txgen.Amount, txgen.Error)
24 | }
25 |
--------------------------------------------------------------------------------
/integration/token/common/sdk/fall/sdk.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package fall
8 |
9 | import (
10 | "errors"
11 |
12 | "github.com/hyperledger-labs/fabric-smart-client/pkg/node"
13 | dig2 "github.com/hyperledger-labs/fabric-smart-client/platform/common/sdk/dig"
14 | fabtoken "github.com/hyperledger-labs/fabric-token-sdk/token/core/fabtoken/v1/driver"
15 | dlog "github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/driver"
16 | tokensdk "github.com/hyperledger-labs/fabric-token-sdk/token/sdk/dig"
17 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/network/fabric"
18 | "go.uber.org/dig"
19 | )
20 |
21 | type SDK struct {
22 | dig2.SDK
23 | }
24 |
25 | func NewSDK(registry node.Registry) *SDK {
26 | return &SDK{SDK: tokensdk.NewSDK(registry)}
27 | }
28 |
29 | func NewFrom(sdk dig2.SDK) *SDK {
30 | return &SDK{SDK: sdk}
31 | }
32 |
33 | func (p *SDK) Install() error {
34 | err := errors.Join(
35 | p.Container().Provide(fabric.NewGenericDriver, dig.Group("network-drivers")),
36 | p.Container().Provide(fabtoken.NewDriver, dig.Group("token-drivers")),
37 | p.Container().Provide(dlog.NewDriver, dig.Group("token-drivers")),
38 | )
39 | if err != nil {
40 | return err
41 | }
42 |
43 | return p.SDK.Install()
44 | }
45 |
--------------------------------------------------------------------------------
/integration/token/common/sdk/fall/sdk_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package fall
8 |
9 | import (
10 | "testing"
11 |
12 | dig2 "github.com/hyperledger-labs/fabric-smart-client/platform/common/sdk/dig"
13 | fabricsdk "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/sdk/dig"
14 | orionsdk "github.com/hyperledger-labs/fabric-smart-client/platform/orion/sdk/dig"
15 | sdk "github.com/hyperledger-labs/fabric-smart-client/platform/view/sdk/dig"
16 | tokensdk "github.com/hyperledger-labs/fabric-token-sdk/token/sdk/dig"
17 | "github.com/stretchr/testify/assert"
18 | )
19 |
20 | func TestAllWiring(t *testing.T) {
21 | assert.NoError(t, sdk.DryRunWiring(
22 | func(sdk dig2.SDK) *SDK { return NewFrom(tokensdk.NewFrom(orionsdk.NewFrom(fabricsdk.NewFrom(sdk)))) },
23 | sdk.WithBool("token.enabled", true),
24 | sdk.WithBool("orion.enabled", true),
25 | sdk.WithBool("fabric.enabled", true),
26 | ))
27 | }
28 |
--------------------------------------------------------------------------------
/integration/token/common/sdk/fdlog/sdk.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package fdlog
8 |
9 | import (
10 | "errors"
11 |
12 | "github.com/hyperledger-labs/fabric-smart-client/pkg/node"
13 | dlog "github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/driver"
14 | tokensdk "github.com/hyperledger-labs/fabric-token-sdk/token/sdk/dig"
15 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/network/fabric"
16 | "go.uber.org/dig"
17 | )
18 |
19 | type SDK struct {
20 | *tokensdk.SDK
21 | }
22 |
23 | func NewSDK(registry node.Registry) *SDK {
24 | return &SDK{SDK: tokensdk.NewSDK(registry)}
25 | }
26 |
27 | func (p *SDK) Install() error {
28 | err := errors.Join(
29 | p.Container().Provide(fabric.NewGenericDriver, dig.Group("network-drivers")),
30 | p.Container().Provide(dlog.NewDriver, dig.Group("token-drivers")),
31 | )
32 | if err != nil {
33 | return err
34 | }
35 |
36 | return p.SDK.Install()
37 | }
38 |
--------------------------------------------------------------------------------
/integration/token/common/sdk/ffabtoken/sdk.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package ffabtoken
8 |
9 | import (
10 | "errors"
11 |
12 | "github.com/hyperledger-labs/fabric-smart-client/pkg/node"
13 | fabtoken "github.com/hyperledger-labs/fabric-token-sdk/token/core/fabtoken/v1/driver"
14 | tokensdk "github.com/hyperledger-labs/fabric-token-sdk/token/sdk/dig"
15 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/network/fabric"
16 | "go.uber.org/dig"
17 | )
18 |
19 | type SDK struct {
20 | *tokensdk.SDK
21 | }
22 |
23 | func NewSDK(registry node.Registry) *SDK {
24 | return &SDK{SDK: tokensdk.NewSDK(registry)}
25 | }
26 |
27 | func (p *SDK) Install() error {
28 | err := errors.Join(
29 | p.Container().Provide(fabric.NewGenericDriver, dig.Group("network-drivers")),
30 | p.Container().Provide(fabtoken.NewDriver, dig.Group("token-drivers")),
31 | )
32 | if err != nil {
33 | return err
34 | }
35 |
36 | return p.SDK.Install()
37 | }
38 |
--------------------------------------------------------------------------------
/integration/token/common/sdk/identity/provider.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package identity
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-token-sdk/token"
11 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/db/driver"
12 | driver2 "github.com/hyperledger-labs/fabric-token-sdk/token/services/identity/driver"
13 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/identity/storage/kvs"
14 | )
15 |
16 | type KVSStorageProvider struct {
17 | kvs kvs.KVS
18 | }
19 |
20 | func NewKVSStorageProvider(kvs kvs.KVS) *KVSStorageProvider {
21 | return &KVSStorageProvider{kvs: kvs}
22 | }
23 |
24 | func (s *KVSStorageProvider) WalletStore(tmsID token.TMSID) (driver.WalletStore, error) {
25 | return kvs.NewWalletStore(s.kvs, tmsID), nil
26 | }
27 |
28 | func (s *KVSStorageProvider) IdentityStore(tmsID token.TMSID) (driver.IdentityStore, error) {
29 | return kvs.NewIdentityStore(s.kvs, tmsID), nil
30 | }
31 |
32 | func (s *KVSStorageProvider) Keystore() (driver2.Keystore, error) {
33 | return kvs.Keystore(s.kvs), nil
34 | }
35 |
--------------------------------------------------------------------------------
/integration/token/common/sdk/ofabtoken/sdk.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package ofabtoken
8 |
9 | import (
10 | "errors"
11 |
12 | "github.com/hyperledger-labs/fabric-smart-client/pkg/node"
13 | orionsdk "github.com/hyperledger-labs/fabric-smart-client/platform/orion/sdk/dig"
14 | fabtoken "github.com/hyperledger-labs/fabric-token-sdk/token/core/fabtoken/v1/driver"
15 | tokensdk "github.com/hyperledger-labs/fabric-token-sdk/token/sdk/dig"
16 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/network/orion"
17 | "go.uber.org/dig"
18 | )
19 |
20 | type SDK struct {
21 | *tokensdk.SDK
22 | }
23 |
24 | func NewSDK(registry node.Registry) *SDK {
25 | return &SDK{SDK: tokensdk.NewFrom(orionsdk.NewSDK(registry))}
26 | }
27 |
28 | func (p *SDK) Install() error {
29 | err := errors.Join(
30 | p.Container().Provide(orion.NewOrionDriver, dig.Group("network-drivers")),
31 | p.Container().Provide(fabtoken.NewDriver, dig.Group("token-drivers")),
32 | )
33 | if err != nil {
34 | return err
35 | }
36 |
37 | return p.SDK.Install()
38 | }
39 |
--------------------------------------------------------------------------------
/integration/token/dvp/README.md:
--------------------------------------------------------------------------------
1 | # Delivery Versus Payment
2 |
3 | To be continued
--------------------------------------------------------------------------------
/integration/token/dvp/dlog/dlog_suite_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package dlog
8 |
9 | import (
10 | "testing"
11 |
12 | . "github.com/onsi/ginkgo/v2"
13 | . "github.com/onsi/gomega"
14 |
15 | "github.com/hyperledger-labs/fabric-token-sdk/integration"
16 | )
17 |
18 | func TestEndToEnd(t *testing.T) {
19 | if testing.Short() {
20 | t.Skip("skipping test in short mode.")
21 | }
22 |
23 | RegisterFailHandler(Fail)
24 | RunSpecs(t, "EndToEnd DVP (DLog) Suite")
25 | }
26 |
27 | func StartPort() int {
28 | return integration.ZKATDLogDVP.StartPortForNode()
29 | }
30 |
--------------------------------------------------------------------------------
/integration/token/dvp/fabtoken/fabtoken_suite_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package fabtoken
8 |
9 | import (
10 | "testing"
11 |
12 | . "github.com/onsi/ginkgo/v2"
13 | . "github.com/onsi/gomega"
14 |
15 | "github.com/hyperledger-labs/fabric-token-sdk/integration"
16 | )
17 |
18 | func TestEndToEnd(t *testing.T) {
19 | if testing.Short() {
20 | t.Skip("skipping test in short mode.")
21 | }
22 |
23 | RegisterFailHandler(Fail)
24 | RunSpecs(t, "EndToEnd DVP (FabToken) Suite")
25 | }
26 |
27 | func StartPort() int {
28 | return integration.FabTokenDVP.StartPortForNode()
29 | }
30 |
--------------------------------------------------------------------------------
/integration/token/dvp/views/auditor.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package views
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/assert"
11 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
12 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/ttx"
13 | )
14 |
15 | type AuditView struct{}
16 |
17 | func (a *AuditView) Call(context view.Context) (interface{}, error) {
18 | tx, err := ttx.ReceiveTransaction(context)
19 | assert.NoError(err, "failed receiving transaction")
20 |
21 | w := ttx.MyAuditorWallet(context)
22 | assert.NotNil(w, "failed getting default auditor wallet")
23 |
24 | // Validate
25 | auditor, err := ttx.NewAuditor(context, w)
26 | assert.NoError(err, "failed to get auditor instance")
27 | assert.NoError(auditor.Validate(tx), "failed auditing verification")
28 |
29 | return context.RunView(ttx.NewAuditApproveView(w, tx))
30 | }
31 |
32 | type RegisterAuditorView struct{}
33 |
34 | func (r *RegisterAuditorView) Call(context view.Context) (interface{}, error) {
35 | return context.RunView(ttx.NewRegisterAuditorView(
36 | &AuditView{},
37 | ))
38 | }
39 |
40 | type RegisterAuditorViewFactory struct{}
41 |
42 | func (p *RegisterAuditorViewFactory) NewView(in []byte) (view.View, error) {
43 | f := &RegisterAuditorView{}
44 | return f, nil
45 | }
46 |
--------------------------------------------------------------------------------
/integration/token/dvp/views/house/house.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package house
8 |
9 | // House is a struct that contains a house
10 | type House struct {
11 | LinearID string
12 | Address string
13 | Valuation uint64
14 | }
15 |
16 | // SetLinearID sets the linear id of the house
17 | func (h *House) SetLinearID(id string) string {
18 | if len(h.LinearID) == 0 {
19 | h.LinearID = id
20 | }
21 | return h.LinearID
22 | }
23 |
--------------------------------------------------------------------------------
/integration/token/dvp/views/house/list.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package house
8 |
9 | import (
10 | "encoding/json"
11 |
12 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/assert"
13 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
14 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/nfttx"
15 | )
16 |
17 | // GetHouse contains the input to query a house by id
18 | type GetHouse struct {
19 | HouseID string
20 | }
21 |
22 | type GetHouseView struct {
23 | *GetHouse
24 | }
25 |
26 | func (p *GetHouseView) Call(context view.Context) (interface{}, error) {
27 | wallet := nfttx.MyWallet(context)
28 | assert.NotNil(wallet, "wallet is nil")
29 |
30 | house := &House{}
31 | assert.NoError(wallet.QueryByKey(context.Context(), house, "LinearID", p.HouseID), "failed loading house with id %s", p.HouseID)
32 |
33 | return house, nil
34 | }
35 |
36 | type GetHouseViewFactory struct{}
37 |
38 | func (i *GetHouseViewFactory) NewView(in []byte) (view.View, error) {
39 | f := &GetHouseView{GetHouse: &GetHouse{}}
40 | err := json.Unmarshal(in, f.GetHouse)
41 | assert.NoError(err, "failed unmarshalling input")
42 | return f, nil
43 | }
44 |
--------------------------------------------------------------------------------
/integration/token/fungible/dlog/dlog_suite_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package dlog
8 |
9 | import (
10 | "testing"
11 |
12 | "github.com/hyperledger-labs/fabric-token-sdk/integration"
13 | . "github.com/onsi/ginkgo/v2"
14 | . "github.com/onsi/gomega"
15 | )
16 |
17 | func TestEndToEnd(t *testing.T) {
18 | if testing.Short() {
19 | t.Skip("skipping test in short mode.")
20 | }
21 |
22 | RegisterFailHandler(Fail)
23 | RunSpecs(t, "EndToEnd Fungible (DLOG) Suite")
24 | }
25 |
26 | func StartPortDlog() int {
27 | return integration.ZKATDLogFungible.StartPortForNode()
28 | }
29 |
--------------------------------------------------------------------------------
/integration/token/fungible/dloghsm/dlog_suite_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package dloghsm
8 |
9 | import (
10 | "testing"
11 |
12 | . "github.com/onsi/ginkgo/v2"
13 | . "github.com/onsi/gomega"
14 |
15 | "github.com/hyperledger-labs/fabric-token-sdk/integration"
16 | )
17 |
18 | func TestEndToEnd(t *testing.T) {
19 | if testing.Short() {
20 | t.Skip("skipping test in short mode.")
21 | }
22 |
23 | RegisterFailHandler(Fail)
24 | RunSpecs(t, "EndToEnd Fungible (DLOG-HSM) Suite")
25 | }
26 |
27 | func StartPortDlog() int {
28 | return integration.ZKATDLogFungibleHSM.StartPortForNode()
29 | }
30 |
--------------------------------------------------------------------------------
/integration/token/fungible/dlogstress/dlog_suite_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package dlog
8 |
9 | import (
10 | "testing"
11 |
12 | "github.com/hyperledger-labs/fabric-token-sdk/integration"
13 | . "github.com/onsi/ginkgo/v2"
14 | . "github.com/onsi/gomega"
15 | )
16 |
17 | func TestEndToEnd(t *testing.T) {
18 | if testing.Short() {
19 | t.Skip("skipping test in short mode.")
20 | }
21 |
22 | RegisterFailHandler(Fail)
23 | RunSpecs(t, "EndToEnd Fungible (DLOG) Stress Suite")
24 | }
25 |
26 | func StartPortDlog() int {
27 | return integration.ZKATDLogFungibleStress.StartPortForNode()
28 | }
29 |
--------------------------------------------------------------------------------
/integration/token/fungible/fabtoken/fabtoken_suite_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package fabtoken
8 |
9 | import (
10 | "testing"
11 |
12 | . "github.com/onsi/ginkgo/v2"
13 | . "github.com/onsi/gomega"
14 |
15 | "github.com/hyperledger-labs/fabric-token-sdk/integration"
16 | )
17 |
18 | func TestEndToEnd(t *testing.T) {
19 | if testing.Short() {
20 | t.Skip("skipping test in short mode.")
21 | }
22 |
23 | RegisterFailHandler(Fail)
24 | RunSpecs(t, "EndToEnd Fungible (FabToken) Suite")
25 | }
26 |
27 | func StartPortDlog() int {
28 | return integration.FabTokenFungible.StartPortForNode()
29 | }
30 |
--------------------------------------------------------------------------------
/integration/token/fungible/mixed/mixed_suite_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package mixed
8 |
9 | import (
10 | "testing"
11 |
12 | . "github.com/onsi/ginkgo/v2"
13 | . "github.com/onsi/gomega"
14 |
15 | "github.com/hyperledger-labs/fabric-token-sdk/integration"
16 | )
17 |
18 | func TestEndToEnd(t *testing.T) {
19 | if testing.Short() {
20 | t.Skip("skipping test in short mode.")
21 | }
22 |
23 | RegisterFailHandler(Fail)
24 | RunSpecs(t, "EndToEnd Fungible (DLOG) Suite")
25 | }
26 |
27 | func StartPortDlog() int {
28 | return integration.Mixed.StartPortForNode()
29 | }
30 |
--------------------------------------------------------------------------------
/integration/token/fungible/odlog/dlog_suite_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package dlog
8 |
9 | import (
10 | "testing"
11 |
12 | "github.com/hyperledger-labs/fabric-token-sdk/integration"
13 | . "github.com/onsi/ginkgo/v2"
14 | . "github.com/onsi/gomega"
15 | )
16 |
17 | func TestEndToEnd(t *testing.T) {
18 | if testing.Short() {
19 | t.Skip("skipping test in short mode.")
20 | }
21 |
22 | RegisterFailHandler(Fail)
23 | RunSpecs(t, "Orion EndToEnd ZKAT CC (DLOG) Suite")
24 | }
25 |
26 | func StartPortDlog() int {
27 | return integration.OrionZKATDLogBasics.StartPortForNode()
28 | }
29 |
--------------------------------------------------------------------------------
/integration/token/fungible/ofabtoken/fabtoken_suite_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package fabtoken
8 |
9 | import (
10 | "testing"
11 |
12 | . "github.com/onsi/ginkgo/v2"
13 | . "github.com/onsi/gomega"
14 |
15 | "github.com/hyperledger-labs/fabric-token-sdk/integration"
16 | )
17 |
18 | func TestEndToEnd(t *testing.T) {
19 | if testing.Short() {
20 | t.Skip("skipping test in short mode.")
21 | }
22 |
23 | RegisterFailHandler(Fail)
24 | RunSpecs(t, "Orion EndToEnd ZKAT CC (FabToken) Suite")
25 | }
26 |
27 | func StartPortDlog() int {
28 | return integration.OrionFabTokenBasics.StartPortForNode()
29 | }
30 |
--------------------------------------------------------------------------------
/integration/token/fungible/sdk/auditor/sdk_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package auditor
8 |
9 | import (
10 | "testing"
11 |
12 | dig2 "github.com/hyperledger-labs/fabric-smart-client/platform/common/sdk/dig"
13 | fabricsdk "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/sdk/dig"
14 | orionsdk "github.com/hyperledger-labs/fabric-smart-client/platform/orion/sdk/dig"
15 | sdk "github.com/hyperledger-labs/fabric-smart-client/platform/view/sdk/dig"
16 | tokensdk "github.com/hyperledger-labs/fabric-token-sdk/token/sdk/dig"
17 | "github.com/stretchr/testify/assert"
18 | )
19 |
20 | func TestAllWiring(t *testing.T) {
21 | assert.NoError(t, sdk.DryRunWiring(
22 | func(sdk dig2.SDK) *SDK { return NewFrom(tokensdk.NewFrom(orionsdk.NewFrom(fabricsdk.NewFrom(sdk)))) },
23 | sdk.WithBool("token.enabled", true),
24 | ))
25 | }
26 |
--------------------------------------------------------------------------------
/integration/token/fungible/sdk/custodian/sdk.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package custodian
8 |
9 | import (
10 | errors2 "errors"
11 |
12 | dig2 "github.com/hyperledger-labs/fabric-smart-client/platform/common/sdk/dig"
13 | "github.com/hyperledger-labs/fabric-smart-client/platform/view"
14 | "github.com/hyperledger-labs/fabric-token-sdk/integration/token/fungible/views"
15 | "github.com/pkg/errors"
16 | )
17 |
18 | type SDK struct {
19 | dig2.SDK
20 | }
21 |
22 | func NewFrom(sdk dig2.SDK) *SDK {
23 | return &SDK{SDK: sdk}
24 | }
25 |
26 | func (p *SDK) Install() error {
27 | // get dig from registry, this was installed by the FTS's sdk
28 | if err := p.SDK.Install(); err != nil {
29 | return err
30 | }
31 |
32 | if err := p.SDK.Container().Invoke(func(
33 | registry *view.Registry,
34 | ) error {
35 | return errors2.Join(
36 | registry.RegisterFactory("GetPublicParams", &views.GetPublicParamsViewFactory{}),
37 | registry.RegisterFactory("FetchAndUpdatePublicParams", &views.UpdatePublicParamsViewFactory{}),
38 | )
39 | }); err != nil {
40 | return errors.WithMessage(err, "failed to install endorser's views")
41 | }
42 | return nil
43 | }
44 |
--------------------------------------------------------------------------------
/integration/token/fungible/sdk/custodian/sdk_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package custodian
8 |
9 | import (
10 | "testing"
11 |
12 | dig2 "github.com/hyperledger-labs/fabric-smart-client/platform/common/sdk/dig"
13 | fabricsdk "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/sdk/dig"
14 | orionsdk "github.com/hyperledger-labs/fabric-smart-client/platform/orion/sdk/dig"
15 | sdk "github.com/hyperledger-labs/fabric-smart-client/platform/view/sdk/dig"
16 | tokensdk "github.com/hyperledger-labs/fabric-token-sdk/token/sdk/dig"
17 | "github.com/stretchr/testify/assert"
18 | )
19 |
20 | func TestAllWiring(t *testing.T) {
21 | assert.NoError(t, sdk.DryRunWiring(
22 | func(sdk dig2.SDK) *SDK { return NewFrom(tokensdk.NewFrom(orionsdk.NewFrom(fabricsdk.NewFrom(sdk)))) },
23 | sdk.WithBool("token.enabled", true),
24 | ))
25 | }
26 |
--------------------------------------------------------------------------------
/integration/token/fungible/sdk/endorser/sdk.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package endorser
8 |
9 | import (
10 | errors2 "errors"
11 |
12 | dig2 "github.com/hyperledger-labs/fabric-smart-client/platform/common/sdk/dig"
13 | "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/services/endorser"
14 | "github.com/hyperledger-labs/fabric-smart-client/platform/view"
15 | "github.com/hyperledger-labs/fabric-token-sdk/integration/token/fungible/views"
16 | "github.com/pkg/errors"
17 | )
18 |
19 | type SDK struct {
20 | dig2.SDK
21 | }
22 |
23 | func NewFrom(sdk dig2.SDK) *SDK {
24 | return &SDK{SDK: sdk}
25 | }
26 |
27 | func (p *SDK) Install() error {
28 | // get dig from registry, this was installed by the FTS's sdk
29 | if err := p.SDK.Install(); err != nil {
30 | return err
31 | }
32 |
33 | if err := p.SDK.Container().Invoke(func(
34 | registry *view.Registry,
35 | ) error {
36 | return errors2.Join(
37 | registry.RegisterFactory("GetPublicParams", &views.GetPublicParamsViewFactory{}),
38 | registry.RegisterFactory("EndorserFinality", &endorser.FinalityViewFactory{}),
39 | registry.RegisterFactory("FetchAndUpdatePublicParams", &views.UpdatePublicParamsViewFactory{}),
40 | )
41 | }); err != nil {
42 | return errors.WithMessage(err, "failed to install endorser's views")
43 | }
44 | return nil
45 | }
46 |
--------------------------------------------------------------------------------
/integration/token/fungible/sdk/endorser/sdk_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package endorser
8 |
9 | import (
10 | "testing"
11 |
12 | dig2 "github.com/hyperledger-labs/fabric-smart-client/platform/common/sdk/dig"
13 | fabricsdk "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/sdk/dig"
14 | orionsdk "github.com/hyperledger-labs/fabric-smart-client/platform/orion/sdk/dig"
15 | sdk "github.com/hyperledger-labs/fabric-smart-client/platform/view/sdk/dig"
16 | tokensdk "github.com/hyperledger-labs/fabric-token-sdk/token/sdk/dig"
17 | "github.com/stretchr/testify/assert"
18 | )
19 |
20 | func TestAllWiring(t *testing.T) {
21 | assert.NoError(t, sdk.DryRunWiring(
22 | func(sdk dig2.SDK) *SDK { return NewFrom(tokensdk.NewFrom(orionsdk.NewFrom(fabricsdk.NewFrom(sdk)))) },
23 | sdk.WithBool("token.enabled", true),
24 | ))
25 | }
26 |
--------------------------------------------------------------------------------
/integration/token/fungible/sdk/issuer/sdk_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package issuer
8 |
9 | import (
10 | "testing"
11 |
12 | dig2 "github.com/hyperledger-labs/fabric-smart-client/platform/common/sdk/dig"
13 | fabricsdk "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/sdk/dig"
14 | orionsdk "github.com/hyperledger-labs/fabric-smart-client/platform/orion/sdk/dig"
15 | sdk "github.com/hyperledger-labs/fabric-smart-client/platform/view/sdk/dig"
16 | tokensdk "github.com/hyperledger-labs/fabric-token-sdk/token/sdk/dig"
17 | "github.com/stretchr/testify/assert"
18 | )
19 |
20 | func TestAllWiring(t *testing.T) {
21 | assert.NoError(t, sdk.DryRunWiring(
22 | func(sdk dig2.SDK) *SDK { return NewFrom(tokensdk.NewFrom(orionsdk.NewFrom(fabricsdk.NewFrom(sdk)))) },
23 | sdk.WithBool("token.enabled", true),
24 | ))
25 | }
26 |
--------------------------------------------------------------------------------
/integration/token/fungible/sdk/party/sdk_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package party
8 |
9 | import (
10 | "testing"
11 |
12 | dig2 "github.com/hyperledger-labs/fabric-smart-client/platform/common/sdk/dig"
13 | fabricsdk "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/sdk/dig"
14 | orionsdk "github.com/hyperledger-labs/fabric-smart-client/platform/orion/sdk/dig"
15 | sdk "github.com/hyperledger-labs/fabric-smart-client/platform/view/sdk/dig"
16 | tokensdk "github.com/hyperledger-labs/fabric-token-sdk/token/sdk/dig"
17 | "github.com/stretchr/testify/assert"
18 | )
19 |
20 | func TestAllWiring(t *testing.T) {
21 | assert.NoError(t, sdk.DryRunWiring(
22 | func(sdk dig2.SDK) *SDK { return NewFrom(tokensdk.NewFrom(orionsdk.NewFrom(fabricsdk.NewFrom(sdk)))) },
23 | sdk.WithBool("token.enabled", true),
24 | ))
25 | }
26 |
--------------------------------------------------------------------------------
/integration/token/fungible/update/update_suite_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package update
8 |
9 | import (
10 | "testing"
11 |
12 | . "github.com/onsi/ginkgo/v2"
13 | . "github.com/onsi/gomega"
14 |
15 | "github.com/hyperledger-labs/fabric-token-sdk/integration"
16 | )
17 |
18 | func TestEndToEnd(t *testing.T) {
19 | if testing.Short() {
20 | t.Skip("skipping test in short mode.")
21 | }
22 |
23 | RegisterFailHandler(Fail)
24 | RunSpecs(t, "EndToEnd Fungible (DLOG) Suite")
25 | }
26 |
27 | func StartPortDlog() int {
28 | return integration.Updatability.StartPortForNode()
29 | }
30 |
--------------------------------------------------------------------------------
/integration/token/fungible/views/binding.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 | SPDX-License-Identifier: Apache-2.0
4 | */
5 |
6 | package views
7 |
8 | import (
9 | "encoding/json"
10 |
11 | view2 "github.com/hyperledger-labs/fabric-smart-client/platform/view"
12 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/assert"
13 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
14 | "github.com/pkg/errors"
15 | )
16 |
17 | type Binding struct {
18 | FSCNodeIdentity view.Identity
19 | Alias view.Identity
20 | }
21 |
22 | type SetBindingView struct {
23 | *Binding
24 | }
25 |
26 | func (s *SetBindingView) Call(context view.Context) (interface{}, error) {
27 | es := view2.GetEndpointService(context)
28 | if err := es.Bind(context.Context(), s.FSCNodeIdentity, s.Alias); err != nil {
29 | return nil, errors.Wrap(err, `failed to bind fsc node identity`)
30 | }
31 | return nil, nil
32 | }
33 |
34 | type SetBindingViewFactory struct{}
35 |
36 | func (p *SetBindingViewFactory) NewView(in []byte) (view.View, error) {
37 | f := &SetBindingView{Binding: &Binding{}}
38 | err := json.Unmarshal(in, f.Binding)
39 | assert.NoError(err, "failed unmarshalling input")
40 |
41 | return f, nil
42 | }
43 |
--------------------------------------------------------------------------------
/integration/token/fungible/views/certifier.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | package views
7 |
8 | import (
9 | "encoding/json"
10 |
11 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/assert"
12 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
13 |
14 | certifier "github.com/hyperledger-labs/fabric-token-sdk/token/services/certifier/views"
15 | )
16 |
17 | type RegisterCertifier struct {
18 | Network string
19 | Channel string
20 | Namespace string
21 | Wallet string
22 | }
23 |
24 | type RegisterCertifierView struct {
25 | *RegisterCertifier
26 | }
27 |
28 | func (r *RegisterCertifierView) Call(context view.Context) (interface{}, error) {
29 | return context.RunView(certifier.NewRegisterView(r.Network, r.Channel, r.Namespace, r.Wallet))
30 | }
31 |
32 | type RegisterCertifierViewFactory struct{}
33 |
34 | func (p *RegisterCertifierViewFactory) NewView(in []byte) (view.View, error) {
35 | f := &RegisterCertifierView{RegisterCertifier: &RegisterCertifier{}}
36 | if len(in) != 0 {
37 | err := json.Unmarshal(in, f.RegisterCertifier)
38 | assert.NoError(err, "failed unmarshalling input")
39 | }
40 | return f, nil
41 | }
42 |
--------------------------------------------------------------------------------
/integration/token/fungible/views/logger.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package views
8 |
9 | import "github.com/hyperledger-labs/fabric-token-sdk/token/services/logging"
10 |
11 | var logger = logging.MustGetLogger()
12 |
--------------------------------------------------------------------------------
/integration/token/interop/dlog/dlog_suite_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package dlog_test
8 |
9 | import (
10 | "testing"
11 |
12 | . "github.com/onsi/ginkgo/v2"
13 | . "github.com/onsi/gomega"
14 | )
15 |
16 | func TestEndToEnd(t *testing.T) {
17 | if testing.Short() {
18 | t.Skip("skipping test in short mode.")
19 | }
20 |
21 | RegisterFailHandler(Fail)
22 | RunSpecs(t, "EndToEnd Interop (DLOG) Suite")
23 | }
24 |
--------------------------------------------------------------------------------
/integration/token/interop/fabtoken/fabtoken_suite_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package fabtoken_test
8 |
9 | import (
10 | "testing"
11 |
12 | . "github.com/onsi/ginkgo/v2"
13 | . "github.com/onsi/gomega"
14 | )
15 |
16 | func TestEndToEnd(t *testing.T) {
17 | if testing.Short() {
18 | t.Skip("skipping test in short mode.")
19 | }
20 |
21 | RegisterFailHandler(Fail)
22 | RunSpecs(t, "EndToEnd Interop (FabToken) Suite")
23 | }
24 |
--------------------------------------------------------------------------------
/integration/token/interop/views/logger.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package views
8 |
9 | import "github.com/hyperledger-labs/fabric-token-sdk/token/services/logging"
10 |
11 | var logger = logging.MustGetLogger()
12 |
--------------------------------------------------------------------------------
/integration/token/nft/dlog/dlog_suite_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package dlog
8 |
9 | import (
10 | "testing"
11 |
12 | . "github.com/onsi/ginkgo/v2"
13 | . "github.com/onsi/gomega"
14 |
15 | "github.com/hyperledger-labs/fabric-token-sdk/integration"
16 | )
17 |
18 | func TestEndToEnd(t *testing.T) {
19 | if testing.Short() {
20 | t.Skip("skipping test in short mode.")
21 | }
22 |
23 | RegisterFailHandler(Fail)
24 | RunSpecs(t, "EndToEnd NFT (DLOG) Suite")
25 | }
26 |
27 | func StartPortDlog() int {
28 | return integration.ZKATDLogNFT.StartPortForNode()
29 | }
30 |
--------------------------------------------------------------------------------
/integration/token/nft/fabtoken/fabtoken_suite_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package fabtoken
8 |
9 | import (
10 | "testing"
11 |
12 | . "github.com/onsi/ginkgo/v2"
13 | . "github.com/onsi/gomega"
14 |
15 | "github.com/hyperledger-labs/fabric-token-sdk/integration"
16 | )
17 |
18 | func TestEndToEnd(t *testing.T) {
19 | if testing.Short() {
20 | t.Skip("skipping test in short mode.")
21 | }
22 |
23 | RegisterFailHandler(Fail)
24 | RunSpecs(t, "EndToEnd NFT (FabToken) Suite")
25 | }
26 |
27 | func StartPortDlog() int {
28 | return integration.FabTokenNFT.StartPortForNode()
29 | }
30 |
--------------------------------------------------------------------------------
/integration/token/nft/odlog/dlog_suite_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package dlog
8 |
9 | import (
10 | "testing"
11 |
12 | . "github.com/onsi/ginkgo/v2"
13 | . "github.com/onsi/gomega"
14 |
15 | "github.com/hyperledger-labs/fabric-token-sdk/integration"
16 | )
17 |
18 | func TestEndToEnd(t *testing.T) {
19 | if testing.Short() {
20 | t.Skip("skipping test in short mode.")
21 | }
22 |
23 | RegisterFailHandler(Fail)
24 | RunSpecs(t, "EndToEnd NFT (DLOG) Suite Orion")
25 | }
26 |
27 | func StartPortDlog() int {
28 | return integration.OrionZKATDLogNFT.StartPortForNode()
29 | }
30 |
--------------------------------------------------------------------------------
/integration/token/nft/ofabtoken/fabtoken_suite_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package fabtoken
8 |
9 | import (
10 | "testing"
11 |
12 | . "github.com/onsi/ginkgo/v2"
13 | . "github.com/onsi/gomega"
14 |
15 | "github.com/hyperledger-labs/fabric-token-sdk/integration"
16 | )
17 |
18 | func TestEndToEnd(t *testing.T) {
19 | if testing.Short() {
20 | t.Skip("skipping test in short mode.")
21 | }
22 |
23 | RegisterFailHandler(Fail)
24 | RunSpecs(t, "EndToEnd NFT (FabToken) Suite Orion")
25 | }
26 |
27 | func StartPortDlog() int {
28 | return integration.OrionFabTokenNFT.StartPortForNode()
29 | }
30 |
--------------------------------------------------------------------------------
/integration/token/nft/views/house.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package views
8 |
9 | // House is a struct that contains a house
10 | type House struct {
11 | LinearID string
12 | Address string
13 | Valuation uint64
14 | }
15 |
16 | // SetLinearID sets the linear id of the house
17 | func (h *House) SetLinearID(id string) string {
18 | if len(h.LinearID) == 0 {
19 | h.LinearID = id
20 | }
21 | return h.LinearID
22 | }
23 |
--------------------------------------------------------------------------------
/integration/token/nft/views/list.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package views
8 |
9 | import (
10 | "encoding/json"
11 |
12 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/assert"
13 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
14 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/nfttx"
15 | )
16 |
17 | // GetHouse contains the input to query a house by id
18 | type GetHouse struct {
19 | HouseID string
20 | }
21 |
22 | type GetHouseView struct {
23 | *GetHouse
24 | }
25 |
26 | func (p *GetHouseView) Call(context view.Context) (interface{}, error) {
27 | house := &House{}
28 | wallet := nfttx.MyWallet(context)
29 | assert.NoError(wallet.QueryByKey(context.Context(), house, "LinearID", p.HouseID), "failed loading house with id %s", p.HouseID)
30 |
31 | return house, nil
32 | }
33 |
34 | type GetHouseViewFactory struct{}
35 |
36 | func (i *GetHouseViewFactory) NewView(in []byte) (view.View, error) {
37 | f := &GetHouseView{GetHouse: &GetHouse{}}
38 | err := json.Unmarshal(in, f.GetHouse)
39 | assert.NoError(err, "failed unmarshalling input")
40 | return f, nil
41 | }
42 |
--------------------------------------------------------------------------------
/staticcheck.conf:
--------------------------------------------------------------------------------
1 | # SPDX-License-Identifier: Apache-2.0
2 |
3 | # onsi/gomega is used only for testing purposes (in test files and in the integration-test logic)
4 | dot_import_whitelist=["github.com/onsi/gomega"]
5 |
--------------------------------------------------------------------------------
/token/authorization.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package token
8 |
9 | import "github.com/hyperledger-labs/fabric-token-sdk/token/driver"
10 |
11 | // Authorization defines method to check the relation between a token
12 | // and wallets (owner, auditor, etc.)
13 | type Authorization struct {
14 | driver.Authorization
15 | }
16 |
--------------------------------------------------------------------------------
/token/config.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package token
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-token-sdk/token/driver"
11 | )
12 |
13 | // Configuration manages the configuration of the token-sdk
14 | type Configuration struct {
15 | cm driver.Configuration
16 | }
17 |
18 | // IsSet checks to see if the key has been set in any of the data locations
19 | func (m *Configuration) IsSet(key string) bool {
20 | return m.cm.IsSet(key)
21 | }
22 |
23 | // UnmarshalKey takes a single key and unmarshals it into a Struct
24 | func (m *Configuration) UnmarshalKey(key string, rawVal interface{}) error {
25 | return m.cm.UnmarshalKey(key, rawVal)
26 | }
27 |
--------------------------------------------------------------------------------
/token/core/common/encoding/json/json.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package json
8 |
9 | import (
10 | "bytes"
11 | "encoding/json"
12 | )
13 |
14 | // Unmarshal is json.Unmarshal with unknown fields disallowed.
15 | func Unmarshal(data []byte, v interface{}) error {
16 | decoder := json.NewDecoder(bytes.NewReader(data))
17 | decoder.DisallowUnknownFields()
18 | return decoder.Decode(v)
19 | }
20 |
21 | var (
22 | Marshal = json.Marshal
23 | MarshalIndent = json.MarshalIndent
24 | )
25 |
--------------------------------------------------------------------------------
/token/core/common/encoding/pp/pp.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package pp
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
11 | "github.com/hyperledger-labs/fabric-token-sdk/token/core/common/encoding/json"
12 | "github.com/hyperledger-labs/fabric-token-sdk/token/driver/protos-go/pp"
13 | )
14 |
15 | // Marshal marshals the passed public parameters
16 | func Marshal(pp *pp.PublicParameters) ([]byte, error) {
17 | if pp == nil {
18 | return nil, errors.New("nil public parameters")
19 | }
20 | return json.Marshal(pp)
21 | }
22 |
23 | // Unmarshal unmarshals the passed slice into an instance of pp.PublicParameters
24 | func Unmarshal(raw []byte) (*pp.PublicParameters, error) {
25 | pp := &pp.PublicParameters{}
26 | if err := json.Unmarshal(raw, pp); err != nil {
27 | return nil, err
28 | }
29 | return pp, nil
30 | }
31 |
--------------------------------------------------------------------------------
/token/core/common/encoding/pp/pp_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package pp
8 |
9 | import (
10 | "testing"
11 |
12 | "github.com/hyperledger-labs/fabric-token-sdk/token/driver/protos-go/pp"
13 | "github.com/stretchr/testify/assert"
14 | )
15 |
16 | func TestSerialization(t *testing.T) {
17 | // Marshal
18 |
19 | // check failures
20 | _, err := Marshal(nil)
21 | assert.Error(t, err)
22 | assert.EqualError(t, err, "nil public parameters")
23 |
24 | // success
25 | pp := &pp.PublicParameters{
26 | Identifier: "pineapple",
27 | Raw: []byte{1, 2, 3},
28 | }
29 | res, err := Marshal(pp)
30 | assert.NoError(t, err)
31 |
32 | // Unmarshall
33 |
34 | // success
35 | pp2, err := Unmarshal(res)
36 | assert.NoError(t, err)
37 | assert.Equal(t, pp, pp2)
38 |
39 | // failure
40 | _, err = Unmarshal([]byte{})
41 | assert.Error(t, err)
42 |
43 | _, err = Unmarshal(nil)
44 | assert.Error(t, err)
45 |
46 | _, err = Unmarshal([]byte{1, 2, 3})
47 | assert.Error(t, err)
48 | }
49 |
--------------------------------------------------------------------------------
/token/core/common/meta/metadata.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package meta
8 |
9 | import (
10 | "strings"
11 | )
12 |
13 | const (
14 | TransferMetadataPrefix = "TransferMetadataPrefix"
15 | )
16 |
17 | // TransferActionMetadata extracts the transfer metadata from the passed attributes and
18 | // sets them to the passed metadata
19 | func TransferActionMetadata(attrs map[interface{}]interface{}) map[string][]byte {
20 | metadata := map[string][]byte{}
21 | for key, value := range attrs {
22 | k, ok1 := key.(string)
23 | v, ok2 := value.([]byte)
24 | if ok1 && ok2 {
25 | if strings.HasPrefix(k, TransferMetadataPrefix) {
26 | mKey := strings.TrimPrefix(k, TransferMetadataPrefix)
27 | metadata[mKey] = v
28 | }
29 | }
30 | }
31 | return metadata
32 | }
33 |
--------------------------------------------------------------------------------
/token/core/common/metrics/metrics.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package metrics
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/metrics"
11 | )
12 |
13 | type (
14 | CounterOpts = metrics.CounterOpts
15 | Counter = metrics.Counter
16 | GaugeOpts = metrics.GaugeOpts
17 | Gauge = metrics.Gauge
18 | HistogramOpts = metrics.HistogramOpts
19 | Histogram = metrics.Histogram
20 | Provider = metrics.Provider
21 | MetricLabel = string
22 | )
23 |
24 | var GetProvider = metrics.GetProvider
25 |
--------------------------------------------------------------------------------
/token/core/common/tracing/tracing.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package tracing
8 |
9 | import (
10 | "reflect"
11 |
12 | "github.com/hyperledger-labs/fabric-smart-client/platform/view"
13 | "go.opentelemetry.io/otel/trace"
14 | )
15 |
16 | var providerType = reflect.TypeOf((*TracerProvider)(nil))
17 |
18 | type TracerProvider struct {
19 | trace.TracerProvider
20 | }
21 |
22 | func NewTracerProvider(tp trace.TracerProvider) *TracerProvider {
23 | return &TracerProvider{TracerProvider: tp}
24 | }
25 |
26 | func GetProvider(sp view.ServiceProvider) *TracerProvider {
27 | s, err := sp.GetService(providerType)
28 | if err != nil {
29 | panic(err)
30 | }
31 | return s.(*TracerProvider)
32 | }
33 |
--------------------------------------------------------------------------------
/token/core/fabtoken/protos/ftpp.proto:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | syntax = "proto3";
8 |
9 | package fabtoken;
10 |
11 | option go_package = "github.com/hyperledger-labs/fabric-token-sdk/token/core/fabtoken/protos-go/pp";
12 |
13 | message Identity {
14 | bytes raw = 1;
15 | }
16 |
17 | // PublicParameters describes typed public parameters
18 | message PublicParameters {
19 | string identifier = 1; // the identifier of the public parameters
20 | uint64 version = 2; // the version of these public params
21 | Identity auditor = 7; // is the public key of the auditor.
22 | repeated Identity issuers = 8; // is a list of public keys of the entities that can issue tokens.
23 | uint64 max_token = 9; // is the maximum quantity a token can hold
24 | uint64 quantity_precision = 10; // is the precision used to represent quantities
25 | }
--------------------------------------------------------------------------------
/token/core/fabtoken/protos/generate.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package protos
8 |
9 | //go:generate protoc ftactions.proto --go_out=../protos-go/actions --go_opt=paths=source_relative
10 | //go:generate protoc ftpp.proto --go_out=../protos-go/pp --go_opt=paths=source_relative
11 |
--------------------------------------------------------------------------------
/token/core/fabtoken/v1/auditor.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package v1
8 |
9 | import (
10 | "context"
11 |
12 | "github.com/hyperledger-labs/fabric-token-sdk/token/driver"
13 | )
14 |
15 | type AuditorService struct{}
16 |
17 | func NewAuditorService() *AuditorService {
18 | return &AuditorService{}
19 | }
20 |
21 | // AuditorCheck verifies if the passed tokenRequest matches the tokenRequestMetadata
22 | // fabtoken does not make use of AuditorCheck as the token request contains token
23 | // information in the clear
24 | func (s *AuditorService) AuditorCheck(ctx context.Context, request *driver.TokenRequest, metadata *driver.TokenRequestMetadata, anchor string) error {
25 | return nil
26 | }
27 |
--------------------------------------------------------------------------------
/token/core/fabtoken/v1/driver/ppm_factory.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package driver
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-token-sdk/token/core"
11 | "github.com/hyperledger-labs/fabric-token-sdk/token/core/common"
12 | v1 "github.com/hyperledger-labs/fabric-token-sdk/token/core/fabtoken/v1/setup"
13 | "github.com/hyperledger-labs/fabric-token-sdk/token/driver"
14 | "github.com/pkg/errors"
15 | )
16 |
17 | // PPMFactory contains the static logic of the driver
18 | type PPMFactory struct{ *base }
19 |
20 | func NewPPMFactory() core.NamedFactory[driver.PPMFactory] {
21 | return core.NamedFactory[driver.PPMFactory]{
22 | Name: v1.PublicParameters,
23 | Driver: &PPMFactory{},
24 | }
25 | }
26 |
27 | func (d *PPMFactory) NewPublicParametersManager(params driver.PublicParameters) (driver.PublicParamsManager, error) {
28 | pp, ok := params.(*v1.PublicParams)
29 | if !ok {
30 | return nil, errors.Errorf("invalid public parameters type [%T]", params)
31 | }
32 | return common.NewPublicParamsManagerFromParams[*v1.PublicParams](pp)
33 | }
34 |
--------------------------------------------------------------------------------
/token/core/zkatdlog/nogh/protos/generate.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package protos
8 |
9 | //go:generate protoc noghmath.proto --go_out=../protos-go/math --go_opt=paths=source_relative
10 | //go:generate protoc -I=. -I=../../../fabtoken/protos noghactions.proto --go_out=../protos-go/actions --go_opt=paths=source_relative
11 | //go:generate protoc noghpp.proto --go_out=../protos-go/pp --go_opt=paths=source_relative
12 |
--------------------------------------------------------------------------------
/token/core/zkatdlog/nogh/protos/noghmath.proto:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | syntax = "proto3";
8 |
9 | package nogh;
10 |
11 | option go_package = "github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/protos-go/math";
12 |
13 | message G1 {
14 | bytes raw = 1;
15 | }
16 |
17 | message Zr {
18 | bytes raw = 1;
19 | }
20 |
21 | message CurveID {
22 | uint64 id = 1;
23 | }
--------------------------------------------------------------------------------
/token/core/zkatdlog/nogh/v1/audit/audit_suite_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | package audit_test
7 |
8 | import (
9 | "testing"
10 |
11 | . "github.com/onsi/ginkgo/v2"
12 | . "github.com/onsi/gomega"
13 | )
14 |
15 | func TestAudit(t *testing.T) {
16 | RegisterFailHandler(Fail)
17 | RunSpecs(t, "Audit Suite")
18 | }
19 |
--------------------------------------------------------------------------------
/token/core/zkatdlog/nogh/v1/audit/testdata/idemix/msp/IssuerPublicKey:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/token/core/zkatdlog/nogh/v1/audit/testdata/idemix/msp/IssuerPublicKey
--------------------------------------------------------------------------------
/token/core/zkatdlog/nogh/v1/audit/testdata/idemix/msp/RevocationPublicKey:
--------------------------------------------------------------------------------
1 | -----BEGIN PUBLIC KEY-----
2 | MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAETdaxDspGM1btPa2IKFz8dmed/xc997JN
3 | S7hhEtholpkp5mRL7FPKLC0GURgSZohw7QjoMSHa5SoMsVo/89odJMTdf+hppSAN
4 | RZouDbFPyHKa0VDF8vQmZR37tZyMRete
5 | -----END PUBLIC KEY-----
6 |
--------------------------------------------------------------------------------
/token/core/zkatdlog/nogh/v1/audit/testdata/idemix/user/SignerConfig:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/token/core/zkatdlog/nogh/v1/audit/testdata/idemix/user/SignerConfig
--------------------------------------------------------------------------------
/token/core/zkatdlog/nogh/v1/crypto/common/array.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package common
8 |
9 | import (
10 | "bytes"
11 | "encoding/hex"
12 |
13 | math "github.com/IBM/mathlib"
14 | "github.com/pkg/errors"
15 | )
16 |
17 | // Separator is used to delimit to end an array of bytes.
18 | // The bytes are the bytes of hex-encoded string.
19 | const Separator = "||"
20 |
21 | // G1Array is an array of G1 elements
22 | type G1Array []*math.G1
23 |
24 | // Bytes serialize an array of G1 elements
25 | func (a *G1Array) Bytes() ([]byte, error) {
26 | raw := make([][]byte, len([]*math.G1(*a)))
27 | for i, e := range []*math.G1(*a) {
28 | if e == nil {
29 | return nil, errors.Errorf("failed to marshal array of G1")
30 | }
31 | st := hex.EncodeToString(e.Bytes())
32 | raw[i] = []byte(st)
33 | }
34 | // join the serialization of the group elements with the predefined separator.
35 | return bytes.Join(raw, []byte(Separator)), nil
36 | }
37 |
38 | // GetG1Array takes a series of G1 elements and returns the corresponding array
39 | func GetG1Array(elements ...[]*math.G1) *G1Array {
40 | var array []*math.G1
41 | for _, e := range elements {
42 | array = append(array, e...)
43 | }
44 | a := G1Array(array)
45 | return &a
46 | }
47 |
--------------------------------------------------------------------------------
/token/core/zkatdlog/nogh/v1/crypto/common/identity.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package common
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-token-sdk/token/driver"
11 | "github.com/pkg/errors"
12 | )
13 |
14 | //go:generate counterfeiter -o ../mock/signing_identity.go -fake-name SigningIdentity . SigningIdentity
15 |
16 | type SigningIdentity interface {
17 | driver.SigningIdentity
18 | }
19 |
20 | type WrappedSigningIdentity struct {
21 | Identity driver.Identity
22 | Signer driver.Signer
23 | }
24 |
25 | func (w *WrappedSigningIdentity) Serialize() ([]byte, error) {
26 | return w.Identity, nil
27 | }
28 |
29 | func (w *WrappedSigningIdentity) Sign(raw []byte) ([]byte, error) {
30 | if w.Signer == nil {
31 | return nil, errors.New("please initialize signing identity in WrappedSigningIdentity")
32 | }
33 | return w.Signer.Sign(raw)
34 | }
35 |
--------------------------------------------------------------------------------
/token/core/zkatdlog/nogh/v1/crypto/math/math_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package math
8 |
9 | import (
10 | "testing"
11 |
12 | math "github.com/IBM/mathlib"
13 | "github.com/stretchr/testify/assert"
14 | )
15 |
16 | func TestCheckElement(t *testing.T) {
17 | var g1 *math.G1
18 | assert.Error(t, CheckElement(g1, 0))
19 |
20 | g1 = &math.G1{}
21 | assert.Error(t, CheckElement(g1, 0))
22 | }
23 |
--------------------------------------------------------------------------------
/token/core/zkatdlog/nogh/v1/crypto/rp/rp_suite_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | package rp_test
7 |
8 | import (
9 | "testing"
10 |
11 | . "github.com/onsi/ginkgo/v2"
12 | . "github.com/onsi/gomega"
13 | )
14 |
15 | func TestEnc(t *testing.T) {
16 | RegisterFailHandler(Fail)
17 | RunSpecs(t, "Bullet Proof Suite")
18 | }
19 |
--------------------------------------------------------------------------------
/token/core/zkatdlog/nogh/v1/driver/ppm_factory.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package driver
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-token-sdk/token/core"
11 | "github.com/hyperledger-labs/fabric-token-sdk/token/core/common"
12 | v1 "github.com/hyperledger-labs/fabric-token-sdk/token/core/zkatdlog/nogh/v1/setup"
13 | "github.com/hyperledger-labs/fabric-token-sdk/token/driver"
14 | "github.com/pkg/errors"
15 | )
16 |
17 | type PPMFactory struct{ *base }
18 |
19 | func NewPPMFactory() core.NamedFactory[driver.PPMFactory] {
20 | return core.NamedFactory[driver.PPMFactory]{
21 | Name: v1.DLogPublicParameters,
22 | Driver: &PPMFactory{},
23 | }
24 | }
25 |
26 | func (d *PPMFactory) NewPublicParametersManager(params driver.PublicParameters) (driver.PublicParamsManager, error) {
27 | pp, ok := params.(*v1.PublicParams)
28 | if !ok {
29 | return nil, errors.Errorf("invalid public parameters type [%T]", params)
30 | }
31 | return common.NewPublicParamsManagerFromParams[*v1.PublicParams](pp)
32 | }
33 |
--------------------------------------------------------------------------------
/token/core/zkatdlog/nogh/v1/metrics.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package v1
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-token-sdk/token/core/common/metrics"
11 | )
12 |
13 | var (
14 | zkIssueDurationOpts = metrics.HistogramOpts{
15 | Namespace: "token_sdk_zkatdlog_nogh",
16 | Name: "issue_duration",
17 | Help: "Duration of zk issue token",
18 | LabelNames: []string{"network", "channel", "namespace"},
19 | StatsdFormat: "%{#fqname}.%{network}.%{channel}.%{namespace}",
20 | }
21 | zkTransferDurationOpts = metrics.HistogramOpts{
22 | Namespace: "token_sdk_zkatdlog_nogh",
23 | Name: "transfer_duration",
24 | Help: "Duration of zk transfer token",
25 | LabelNames: []string{"network", "channel", "namespace"},
26 | StatsdFormat: "%{#fqname}.%{network}.%{channel}.%{namespace}",
27 | }
28 | )
29 |
30 | type Metrics struct {
31 | zkIssueDuration metrics.Histogram
32 | zkTransferDuration metrics.Histogram
33 | }
34 |
35 | func NewMetrics(p metrics.Provider) *Metrics {
36 | return &Metrics{
37 | zkIssueDuration: p.NewHistogram(zkIssueDurationOpts),
38 | zkTransferDuration: p.NewHistogram(zkTransferDurationOpts),
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/token/core/zkatdlog/nogh/v1/setup/testdata/idemix/msp/IssuerPublicKey:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/token/core/zkatdlog/nogh/v1/setup/testdata/idemix/msp/IssuerPublicKey
--------------------------------------------------------------------------------
/token/core/zkatdlog/nogh/v1/setup/testdata/idemix/msp/RevocationPublicKey:
--------------------------------------------------------------------------------
1 | -----BEGIN PUBLIC KEY-----
2 | MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAETdaxDspGM1btPa2IKFz8dmed/xc997JN
3 | S7hhEtholpkp5mRL7FPKLC0GURgSZohw7QjoMSHa5SoMsVo/89odJMTdf+hppSAN
4 | RZouDbFPyHKa0VDF8vQmZR37tZyMRete
5 | -----END PUBLIC KEY-----
6 |
--------------------------------------------------------------------------------
/token/core/zkatdlog/nogh/v1/token/fabtoken.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package token
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
11 | "github.com/hyperledger-labs/fabric-token-sdk/token/core/fabtoken/v1/actions"
12 | "github.com/hyperledger-labs/fabric-token-sdk/token/token"
13 | )
14 |
15 | func ParseFabtokenToken(tok []byte, precision uint64, maxPrecision uint64) (*actions.Output, uint64, error) {
16 | if precision < maxPrecision {
17 | return nil, 0, errors.Errorf("unsupported precision [%d], max [%d]", precision, maxPrecision)
18 | }
19 |
20 | output := &actions.Output{}
21 | err := output.Deserialize(tok)
22 | if err != nil {
23 | return nil, 0, errors.Wrap(err, "failed to unmarshal fabtoken")
24 | }
25 | q, err := token.NewUBigQuantity(output.Quantity, precision)
26 | if err != nil {
27 | return nil, 0, errors.Wrap(err, "failed to create quantity")
28 | }
29 |
30 | return output, q.Uint64(), nil
31 | }
32 |
--------------------------------------------------------------------------------
/token/core/zkatdlog/nogh/v1/transfer/transfer_suite_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | package transfer_test
7 |
8 | import (
9 | "testing"
10 |
11 | . "github.com/onsi/ginkgo/v2"
12 | . "github.com/onsi/gomega"
13 | )
14 |
15 | func TestTransfer(t *testing.T) {
16 | RegisterFailHandler(Fail)
17 | RunSpecs(t, "Transfer Suite")
18 | }
19 |
--------------------------------------------------------------------------------
/token/core/zkatdlog/nogh/v1/validator/ledger.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | package validator
7 |
8 | import "github.com/hyperledger-labs/fabric-token-sdk/token/token"
9 |
10 | //go:generate counterfeiter -o mock/ledger.go -fake-name Ledger . Ledger
11 |
12 | type Ledger interface {
13 | GetState(id token.ID) ([]byte, error)
14 | }
15 |
--------------------------------------------------------------------------------
/token/core/zkatdlog/nogh/v1/validator/testdata/idemix/msp/IssuerPublicKey:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/token/core/zkatdlog/nogh/v1/validator/testdata/idemix/msp/IssuerPublicKey
--------------------------------------------------------------------------------
/token/core/zkatdlog/nogh/v1/validator/testdata/idemix/msp/RevocationPublicKey:
--------------------------------------------------------------------------------
1 | -----BEGIN PUBLIC KEY-----
2 | MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAETdaxDspGM1btPa2IKFz8dmed/xc997JN
3 | S7hhEtholpkp5mRL7FPKLC0GURgSZohw7QjoMSHa5SoMsVo/89odJMTdf+hppSAN
4 | RZouDbFPyHKa0VDF8vQmZR37tZyMRete
5 | -----END PUBLIC KEY-----
6 |
--------------------------------------------------------------------------------
/token/core/zkatdlog/nogh/v1/validator/testdata/idemix/user/SignerConfig:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/token/core/zkatdlog/nogh/v1/validator/testdata/idemix/user/SignerConfig
--------------------------------------------------------------------------------
/token/core/zkatdlog/nogh/v1/validator/validator_suite_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | package validator_test
7 |
8 | import (
9 | "testing"
10 |
11 | . "github.com/onsi/ginkgo/v2"
12 | . "github.com/onsi/gomega"
13 | )
14 |
15 | func TestEngine(t *testing.T) {
16 | RegisterFailHandler(Fail)
17 | RunSpecs(t, "Validator Suite")
18 | }
19 |
--------------------------------------------------------------------------------
/token/driver/auditor.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package driver
8 |
9 | import "context"
10 |
11 | // AuditorService models the auditor service
12 | type AuditorService interface {
13 | // AuditorCheck verifies the well-formedness of the passed request with the respect to the passed metadata and anchor
14 | AuditorCheck(ctx context.Context, request *TokenRequest, metadata *TokenRequestMetadata, anchor string) error
15 | }
16 |
--------------------------------------------------------------------------------
/token/driver/config.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package driver
8 |
9 | // Configuration provides functions to access the configuration of a given TMS
10 | type Configuration interface {
11 | // ID identities the TMS this configuration refers to.
12 | ID() TMSID
13 | // IsSet checks to see if the key has been set in any of the data locations
14 | IsSet(key string) bool
15 | // UnmarshalKey takes a single key and unmarshals it into a struct.
16 | // The key must be relative to the TMS this configuration refers to.
17 | UnmarshalKey(key string, rawVal interface{}) error
18 | // GetString returns the value associated with the key as a string
19 | GetString(key string) string
20 | // GetBool returns the value associated with the key as a bool
21 | GetBool(key string) bool
22 | // TranslatePath translates the passed path relative to the config path
23 | TranslatePath(path string) string
24 | }
25 |
--------------------------------------------------------------------------------
/token/driver/driver.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package driver
8 |
9 | // ServiceProvider is used to return instances of a given type
10 | type ServiceProvider interface {
11 | // GetService returns an instance of the given type
12 | GetService(v interface{}) (interface{}, error)
13 | }
14 |
15 | // Driver is the interface that must be implemented by a token driver.
16 | type Driver interface {
17 | PPReader
18 | // NewTokenService returns a new TokenManagerService instance.
19 | NewTokenService(tmsID TMSID, publicParams []byte) (TokenManagerService, error)
20 | // NewDefaultValidator returns a new Validator instance from the passed public parameters
21 | NewDefaultValidator(pp PublicParameters) (Validator, error)
22 | }
23 |
--------------------------------------------------------------------------------
/token/driver/marshaller.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package driver
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-token-sdk/token/driver/protos-go/request"
11 | "github.com/hyperledger-labs/fabric-token-sdk/token/token"
12 | )
13 |
14 | // ToTokenID converts *request.TokenID to *token.ID
15 | func ToTokenID(id *request.TokenID) *token.ID {
16 | if id == nil {
17 | return nil
18 | }
19 | return &token.ID{
20 | TxId: id.TxId,
21 | Index: id.Index,
22 | }
23 | }
24 |
25 | // ToProtoIdentitySlice converts []Identity to []*request.Identity
26 | func ToProtoIdentitySlice(identities []Identity) []*request.Identity {
27 | res := make([]*request.Identity, len(identities))
28 | for i, id := range identities {
29 | res[i] = &request.Identity{
30 | Raw: id,
31 | }
32 | }
33 | return res
34 | }
35 |
36 | // FromProtoIdentitySlice converts []*request.Identity to []Identity
37 | func FromProtoIdentitySlice(identities []*request.Identity) []Identity {
38 | res := make([]Identity, len(identities))
39 | for i, id := range identities {
40 | if id != nil {
41 | res[i] = id.Raw
42 | }
43 | }
44 | return res
45 | }
46 |
47 | // ToIdentity converts *request.Identity to Identity
48 | func ToIdentity(id *request.Identity) Identity {
49 | if id == nil {
50 | return nil
51 | }
52 | return id.Raw
53 | }
54 |
--------------------------------------------------------------------------------
/token/driver/protos-go/utils/proto.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package utils
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-token-sdk/token/driver/protos-go/request"
11 | "github.com/hyperledger-labs/fabric-token-sdk/token/token"
12 | )
13 |
14 | func ToActionSlice(actionType request.ActionType, actions [][]byte) []*request.Action {
15 | res := make([]*request.Action, len(actions))
16 | for i, action := range actions {
17 | res[i] = &request.Action{
18 | Type: actionType,
19 | Raw: action,
20 | }
21 | }
22 | return res
23 | }
24 |
25 | func ToSignatureSlice(signatures [][]byte) []*request.Signature {
26 | res := make([]*request.Signature, len(signatures))
27 | for i, signature := range signatures {
28 | res[i] = &request.Signature{
29 | Raw: signature,
30 | }
31 | }
32 | return res
33 | }
34 |
35 | func ToTokenID(id *token.ID) (*request.TokenID, error) {
36 | if id == nil {
37 | return nil, nil
38 | }
39 | return &request.TokenID{
40 | TxId: id.TxId,
41 | Index: id.Index,
42 | }, nil
43 | }
44 |
--------------------------------------------------------------------------------
/token/driver/protos/generate.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package protos
8 |
9 | //go:generate protoc request.proto pp.proto --go_out=.
10 |
--------------------------------------------------------------------------------
/token/driver/protos/pp.proto:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | syntax = "proto3";
8 |
9 | package protos;
10 |
11 | option go_package = "../protos-go/pp";
12 |
13 | // PublicParameters describes typed public parameters
14 | message PublicParameters {
15 | string identifier = 1; // the identifier of the public parameters
16 | bytes raw = 2; // the actual public parameters to be interpreted depending on the identifier
17 | }
18 |
--------------------------------------------------------------------------------
/token/driver/sig.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package driver
8 |
9 | type FullIdentity interface {
10 | SigningIdentity
11 | Verifier
12 | }
13 |
14 | // SigningIdentity models a signing identity
15 | type SigningIdentity interface {
16 | // Sign signs message bytes and returns the signature or an error on failure.
17 | Sign(raw []byte) ([]byte, error)
18 |
19 | // Serialize serializes the signing identity
20 | Serialize() ([]byte, error)
21 | }
22 |
23 | //go:generate counterfeiter -o mock/verifier.go -fake-name Verifier . Verifier
24 |
25 | // Verifier is an interface which wraps the Verify method.
26 | type Verifier interface {
27 | // Verify verifies the signature over the message bytes and returns nil if the signature is valid and an error otherwise.
28 | Verify(message, sigma []byte) error
29 | }
30 |
31 | //go:generate counterfeiter -o mock/signer.go -fake-name Signer . Signer
32 |
33 | // Signer is an interface which wraps the Sign method.
34 | type Signer interface {
35 | // Sign signs message bytes and returns the signature or an error on failure.
36 | Sign(message []byte) ([]byte, error)
37 | }
38 |
--------------------------------------------------------------------------------
/token/hashable.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package token
8 |
9 | import (
10 | "crypto/sha256"
11 | "encoding/base64"
12 | )
13 |
14 | type Hashable []byte
15 |
16 | func (id Hashable) Raw() []byte {
17 | if len(id) == 0 {
18 | return nil
19 | }
20 | hash := sha256.New()
21 | n, err := hash.Write(id)
22 | if n != len(id) {
23 | panic("hash failure")
24 | }
25 | if err != nil {
26 | panic(err)
27 | }
28 | return hash.Sum(nil)
29 | }
30 |
31 | func (id Hashable) String() string { return base64.StdEncoding.EncodeToString(id.Raw()) }
32 |
33 | func (id Hashable) RawString() string { return string(id.Raw()) }
34 |
--------------------------------------------------------------------------------
/token/sdk/db/config.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package db
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-token-sdk/token"
11 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/config"
12 | "github.com/pkg/errors"
13 | )
14 |
15 | type ConfigProvider interface {
16 | ConfigurationFor(network, channel, namespace string) (config.Configuration, error)
17 | }
18 |
19 | type Config struct {
20 | configProvider ConfigProvider
21 | configurationKeys []string
22 | }
23 |
24 | func NewConfig(configProvider ConfigProvider, configurationKeys ...string) *Config {
25 | return &Config{configProvider: configProvider, configurationKeys: configurationKeys}
26 | }
27 |
28 | func (c *Config) DriverFor(tmsID token.TMSID) (string, error) {
29 | tmsConfig, err := c.configProvider.ConfigurationFor(tmsID.Network, tmsID.Channel, tmsID.Namespace)
30 | if err != nil {
31 | return "", errors.WithMessagef(err, "failed to load configuration for tms [%s]", tmsID)
32 | }
33 | for _, key := range c.configurationKeys {
34 | if tmsConfig.IsSet(key) {
35 | return tmsConfig.GetString(key), nil
36 | }
37 | }
38 | return "", errors.Errorf("configuration not found")
39 | }
40 |
--------------------------------------------------------------------------------
/token/sdk/dig/checks.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package sdk
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-token-sdk/token/sdk/db"
11 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/db/common"
12 | "go.uber.org/dig"
13 | )
14 |
15 | func NewAuditorCheckServiceProvider(in struct {
16 | dig.In
17 | TMSProvider common.TokenManagementServiceProvider
18 | NetworkProvider common.NetworkProvider
19 | Checkers []common.NamedChecker `group:"auditdb-checkers"`
20 | }) *db.AuditorCheckServiceProvider {
21 | return db.NewAuditorCheckServiceProvider(in.TMSProvider, in.NetworkProvider, in.Checkers)
22 | }
23 |
24 | func NewOwnerCheckServiceProvider(in struct {
25 | dig.In
26 | TMSProvider common.TokenManagementServiceProvider
27 | NetworkProvider common.NetworkProvider
28 | Checkers []common.NamedChecker `group:"ttxdb-checkers"`
29 | }) *db.OwnerCheckServiceProvider {
30 | return db.NewOwnerCheckServiceProvider(in.TMSProvider, in.NetworkProvider, in.Checkers)
31 | }
32 |
--------------------------------------------------------------------------------
/token/sdk/dig/providers.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package sdk
8 |
9 | import (
10 | driver2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/driver"
11 | "github.com/hyperledger-labs/fabric-token-sdk/token/core"
12 | "github.com/hyperledger-labs/fabric-token-sdk/token/driver"
13 | dbdriver "github.com/hyperledger-labs/fabric-token-sdk/token/services/db/driver"
14 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/db/sql/multiplexed"
15 | "go.uber.org/dig"
16 | )
17 |
18 | func newMultiplexedDriver(in struct {
19 | dig.In
20 | Drivers []dbdriver.NamedDriver `group:"token-db-drivers"`
21 | ConfigProvider driver2.ConfigService
22 | }) multiplexed.Driver {
23 | return multiplexed.NewDriver(in.ConfigProvider, in.Drivers...)
24 | }
25 |
26 | func newTokenDriverService(in struct {
27 | dig.In
28 | Drivers []core.NamedFactory[driver.Driver] `group:"token-drivers"`
29 | }) *core.TokenDriverService {
30 | return core.NewTokenDriverService(in.Drivers)
31 | }
32 |
--------------------------------------------------------------------------------
/token/sdk/network/certifier.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package network
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-token-sdk/token"
11 | "github.com/hyperledger-labs/fabric-token-sdk/token/driver"
12 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/certifier"
13 | )
14 |
15 | type CertificationClientProvider struct {
16 | }
17 |
18 | func NewCertificationClientProvider() *CertificationClientProvider {
19 | return &CertificationClientProvider{}
20 | }
21 |
22 | func (c *CertificationClientProvider) New(tms *token.ManagementService) (driver.CertificationClient, error) {
23 | return certifier.NewCertificationClient(tms)
24 | }
25 |
--------------------------------------------------------------------------------
/token/sdk/vault/pps.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package vault
8 |
9 | import (
10 | "context"
11 |
12 | "github.com/pkg/errors"
13 | )
14 |
15 | type PublicParamsStorage struct {
16 | Provider *Provider
17 | }
18 |
19 | func (p *PublicParamsStorage) PublicParams(ctx context.Context, networkID string, channel string, namespace string) ([]byte, error) {
20 | vault, err := p.Provider.Vault(networkID, channel, namespace)
21 | if err != nil {
22 | return nil, errors.WithMessagef(err, "failed to get network for [%s:%s:%s]", networkID, channel, namespace)
23 | }
24 | return vault.QueryEngine().PublicParams(ctx)
25 | }
26 |
--------------------------------------------------------------------------------
/token/services/certifier/client.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package certifier
8 |
9 | import (
10 | "context"
11 |
12 | "github.com/hyperledger-labs/fabric-token-sdk/token"
13 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/certifier/driver"
14 | token2 "github.com/hyperledger-labs/fabric-token-sdk/token/token"
15 | "github.com/pkg/errors"
16 | )
17 |
18 | type CertificationClient struct {
19 | c driver.CertificationClient
20 | }
21 |
22 | func NewCertificationClient(tms *token.ManagementService) (*CertificationClient, error) {
23 | driver := tms.PublicParametersManager().PublicParameters().CertificationDriver()
24 | d, ok := holder.Drivers[driver]
25 | if !ok {
26 | return nil, errors.Errorf("certifier driver [%s] not found", driver)
27 | }
28 | c, err := d.NewCertificationClient(tms)
29 | if err != nil {
30 | return nil, errors.Wrapf(err, "failed instantiating certification manager with driver [%s]", driver)
31 | }
32 | return &CertificationClient{c: c}, nil
33 | }
34 |
35 | func (c *CertificationClient) IsCertified(ctx context.Context, id *token2.ID) bool {
36 | return c.c.IsCertified(ctx, id)
37 | }
38 |
39 | func (c *CertificationClient) RequestCertification(ctx context.Context, ids ...*token2.ID) error {
40 | return c.c.RequestCertification(ctx, ids...)
41 | }
42 |
--------------------------------------------------------------------------------
/token/services/certifier/driver.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | package certifier
7 |
8 | import (
9 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/certifier/driver"
10 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/utils/drivers"
11 | )
12 |
13 | var holder = drivers.NewHolder[string, driver.Driver]()
14 |
--------------------------------------------------------------------------------
/token/services/certifier/driver/driver.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | package driver
7 |
8 | import (
9 | "context"
10 |
11 | "github.com/hyperledger-labs/fabric-token-sdk/token"
12 | token2 "github.com/hyperledger-labs/fabric-token-sdk/token/token"
13 | )
14 |
15 | type CertificationClient interface {
16 | IsCertified(ctx context.Context, id *token2.ID) bool
17 | RequestCertification(ctx context.Context, ids ...*token2.ID) error
18 | }
19 |
20 | type CertificationService interface {
21 | Start() error
22 | }
23 |
24 | type Driver interface {
25 | NewCertificationClient(tms *token.ManagementService) (CertificationClient, error)
26 | NewCertificationService(tms *token.ManagementService, wallet string) (CertificationService, error)
27 | }
28 |
--------------------------------------------------------------------------------
/token/services/certifier/dummy/driver.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package dummy
8 |
9 | import (
10 | "context"
11 |
12 | "github.com/hyperledger-labs/fabric-token-sdk/token"
13 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/certifier/driver"
14 | token2 "github.com/hyperledger-labs/fabric-token-sdk/token/token"
15 | )
16 |
17 | type CertificationClient struct{}
18 |
19 | func (c *CertificationClient) IsCertified(ctx context.Context, id *token2.ID) bool {
20 | return true
21 | }
22 |
23 | func (c *CertificationClient) RequestCertification(ctx context.Context, ids ...*token2.ID) error {
24 | return nil
25 | }
26 |
27 | func (c *CertificationClient) Start() error {
28 | return nil
29 | }
30 |
31 | type CertificationService struct{}
32 |
33 | func (c *CertificationService) Start() error {
34 | return nil
35 | }
36 |
37 | type Driver struct{}
38 |
39 | func NewDriver() *Driver {
40 | return &Driver{}
41 | }
42 |
43 | func (d *Driver) NewCertificationClient(tms *token.ManagementService) (driver.CertificationClient, error) {
44 | return &CertificationClient{}, nil
45 | }
46 |
47 | func (d *Driver) NewCertificationService(tms *token.ManagementService, wallet string) (driver.CertificationService, error) {
48 | return &CertificationService{}, nil
49 | }
50 |
--------------------------------------------------------------------------------
/token/services/certifier/interactive/metrics.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package interactive
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/metrics"
11 | )
12 |
13 | var (
14 | certifiedTokens = metrics.CounterOpts{
15 | Namespace: "certification_interactive",
16 | Name: "certified_tokens",
17 | Help: "The number of tokens certified.",
18 | LabelNames: []string{"network", "channel", "namespace"},
19 | StatsdFormat: "%{#fqname}.%{network}.%{channel}.%{namespace}",
20 | }
21 | )
22 |
23 | type Metrics struct {
24 | CertifiedTokens metrics.Counter
25 | }
26 |
27 | func NewMetrics(p metrics.Provider) *Metrics {
28 | return &Metrics{
29 | CertifiedTokens: p.NewCounter(certifiedTokens),
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/token/services/certifier/service.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package certifier
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-token-sdk/token"
11 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/certifier/driver"
12 | "github.com/pkg/errors"
13 | )
14 |
15 | type CertificationService struct {
16 | c driver.CertificationService
17 | }
18 |
19 | func NewCertificationService(tms *token.ManagementService, wallet string) (*CertificationService, error) {
20 | driver := tms.PublicParametersManager().PublicParameters().CertificationDriver()
21 | d, ok := holder.Drivers[driver]
22 | if !ok {
23 | return nil, errors.Errorf("certifier driver [%s] not found", driver)
24 | }
25 |
26 | c, err := d.NewCertificationService(tms, wallet)
27 | if err != nil {
28 | return nil, errors.Wrapf(err, "failed instantiating certifier with driver [%s]", driver)
29 | }
30 | return &CertificationService{c: c}, nil
31 | }
32 |
33 | func (c *CertificationService) Start() error {
34 | return c.c.Start()
35 | }
36 |
--------------------------------------------------------------------------------
/token/services/config/config_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package config
8 |
9 | import (
10 | "testing"
11 |
12 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/core/config"
13 | "github.com/stretchr/testify/assert"
14 | )
15 |
16 | // TestGetTMSs tests the Configurations function
17 | func TestGetTMSs(t *testing.T) {
18 | // create a new config service by loading the config file
19 | cp, err := config.NewProvider("./testdata/token0")
20 | assert.NoError(t, err)
21 |
22 | // instantiate the token sdk config
23 | tokenSDKConfig := NewService(cp)
24 |
25 | // compare the TMSs obtained from Configurations with the corresponding TMSs obtained from ConfigurationFor
26 | tmss, err := tokenSDKConfig.Configurations()
27 | assert.NoError(t, err)
28 | assert.Equal(t, 2, len(tmss))
29 | for _, tms := range tmss {
30 | tms2, err := tokenSDKConfig.ConfigurationFor(tms.ID().Network, tms.ID().Channel, tms.ID().Namespace)
31 | assert.NoError(t, err)
32 | assert.Equal(t, tms, tms2)
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/token/services/db/driver/config.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package driver
8 |
9 | type ConfigProvider interface {
10 | UnmarshalKey(key string, rawVal interface{}) error
11 | GetString(key string) string
12 | GetBool(key string) bool
13 | IsSet(key string) bool
14 | TranslatePath(path string) string
15 | }
16 |
--------------------------------------------------------------------------------
/token/services/db/driver/driver.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package driver
8 |
9 | import (
10 | driver2 "github.com/hyperledger-labs/fabric-smart-client/platform/common/driver"
11 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver"
12 | )
13 |
14 | type NamedDriver = driver2.NamedDriver[Driver]
15 |
16 | type Config = driver.Config
17 |
18 | type Driver interface {
19 | NewTokenLock(driver.PersistenceName, ...string) (TokenLockStore, error)
20 |
21 | NewWallet(driver.PersistenceName, ...string) (WalletStore, error)
22 |
23 | NewIdentity(driver.PersistenceName, ...string) (IdentityStore, error)
24 |
25 | NewToken(driver.PersistenceName, ...string) (TokenStore, error)
26 |
27 | NewTokenNotifier(driver.PersistenceName, ...string) (TokenNotifier, error)
28 |
29 | NewAuditTransaction(driver.PersistenceName, ...string) (AuditTransactionStore, error)
30 |
31 | NewOwnerTransaction(driver.PersistenceName, ...string) (TokenTransactionStore, error)
32 | }
33 |
--------------------------------------------------------------------------------
/token/services/db/driver/identity.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package driver
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-token-sdk/token/driver"
11 | driver2 "github.com/hyperledger-labs/fabric-token-sdk/token/services/identity/driver"
12 | )
13 |
14 | type (
15 | WalletID = driver2.WalletID
16 | IdentityConfiguration = driver.IdentityConfiguration
17 | WalletStore = driver2.WalletStoreService
18 | IdentityStore = driver2.IdentityStoreService
19 | )
20 |
--------------------------------------------------------------------------------
/token/services/db/sql/common/common.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package common
8 |
9 | type Closer interface {
10 | Close() error
11 | }
12 |
13 | func Close(closer Closer) {
14 | if closer == nil {
15 | return
16 | }
17 | if err := closer.Close(); err != nil {
18 | logger.Errorf("failed closing connection: %s", err)
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/token/services/db/sql/memory/memory_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package memory
8 |
9 | import (
10 | "testing"
11 |
12 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/db/dbtest"
13 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/db/driver"
14 | )
15 |
16 | func TestTokens(t *testing.T) {
17 | dbtest.TokensTest(t, func(string) driver.Driver { return NewDriver() })
18 | }
19 |
20 | func TestTransactions(t *testing.T) {
21 | dbtest.TransactionsTest(t, func(string) driver.Driver { return NewDriver() })
22 | }
23 |
24 | func TestTokenLocks(t *testing.T) {
25 | dbtest.TokenLocksTest(t, func(string) driver.Driver { return NewDriver() })
26 | }
27 |
28 | func TestIdentity(t *testing.T) {
29 | dbtest.IdentityTest(t, func(string) driver.Driver { return NewDriver() })
30 | }
31 |
32 | func TestWallet(t *testing.T) {
33 | dbtest.WalletTest(t, func(string) driver.Driver { return NewDriver() })
34 | }
35 |
--------------------------------------------------------------------------------
/token/services/db/sql/postgres/identity.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package postgres
8 |
9 | import (
10 | common2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/common"
11 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/sql/postgres"
12 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/db/sql/common"
13 | )
14 |
15 | type IdentityStore = common.IdentityStore
16 |
17 | func NewIdentityStore(dbs *common2.RWDB, tableNames common.TableNames) (*IdentityStore, error) {
18 | return common.NewCachedIdentityStore(dbs.ReadDB, dbs.WriteDB, tableNames, postgres.NewConditionInterpreter())
19 | }
20 |
--------------------------------------------------------------------------------
/token/services/db/sql/postgres/tokens.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package postgres
8 |
9 | import (
10 | common2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/common"
11 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/sql/postgres"
12 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/db/sql/common"
13 | )
14 |
15 | type (
16 | TokenStore = common.TokenStore
17 | TokenNotifier = postgres.Notifier
18 | )
19 |
20 | func NewTokenStore(dbs *common2.RWDB, tableNames common.TableNames) (*TokenStore, error) {
21 | return common.NewTokenStore(dbs.ReadDB, dbs.WriteDB, tableNames, postgres.NewConditionInterpreter())
22 | }
23 |
24 | func NewTokenNotifier(dbs *common2.RWDB, tableNames common.TableNames, dataSource string) (*TokenNotifier, error) {
25 | return postgres.NewNotifier(dbs.WriteDB, tableNames.Tokens, dataSource, postgres.AllOperations, *postgres.NewSimplePrimaryKey("tx_id"), *postgres.NewSimplePrimaryKey("idx")), nil
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/token/services/db/sql/postgres/transactions.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package postgres
8 |
9 | import (
10 | common2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/common"
11 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/sql/postgres"
12 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/sql/query/pagination"
13 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/db/sql/common"
14 | )
15 |
16 | type (
17 | AuditTransactionStore = common.TransactionStore
18 | TransactionStore = common.TransactionStore
19 | )
20 |
21 | func NewAuditTransactionStore(dbs *common2.RWDB, tableNames common.TableNames) (*AuditTransactionStore, error) {
22 | return common.NewAuditTransactionStore(dbs.ReadDB, dbs.WriteDB, tableNames, postgres.NewConditionInterpreter(), pagination.NewDefaultInterpreter())
23 | }
24 |
25 | func NewTransactionStore(dbs *common2.RWDB, tableNames common.TableNames) (*TransactionStore, error) {
26 | return common.NewOwnerTransactionStore(dbs.ReadDB, dbs.WriteDB, tableNames, postgres.NewConditionInterpreter(), pagination.NewDefaultInterpreter())
27 | }
28 |
--------------------------------------------------------------------------------
/token/services/db/sql/postgres/wallet.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package postgres
8 |
9 | import (
10 | common2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/common"
11 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/sql/postgres"
12 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/db/sql/common"
13 | )
14 |
15 | type WalletStore = common.WalletStore
16 |
17 | func NewWalletStore(dbs *common2.RWDB, tableNames common.TableNames) (*WalletStore, error) {
18 | return common.NewWalletStore(dbs.ReadDB, dbs.WriteDB, tableNames, postgres.NewConditionInterpreter())
19 | }
20 |
--------------------------------------------------------------------------------
/token/services/db/sql/sqlite/identity.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package sqlite
8 |
9 | import (
10 | common2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/common"
11 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/sql/sqlite"
12 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/db/sql/common"
13 | )
14 |
15 | type IdentityStore = common.IdentityStore
16 |
17 | func NewIdentityStore(dbs *common2.RWDB, tableNames common.TableNames) (*IdentityStore, error) {
18 | return common.NewCachedIdentityStore(dbs.ReadDB, dbs.WriteDB, tableNames, sqlite.NewConditionInterpreter())
19 | }
20 |
--------------------------------------------------------------------------------
/token/services/db/sql/sqlite/tokenlock_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package sqlite
8 |
9 | import (
10 | "testing"
11 | "time"
12 |
13 | q "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/sql/query"
14 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/sql/sqlite"
15 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/db/driver"
16 | . "github.com/onsi/gomega"
17 | )
18 |
19 | func TestIsStale(t *testing.T) {
20 | RegisterTestingT(t)
21 |
22 | query, args := q.DeleteFrom("TokenLocks").
23 | Where(IsStale("TokenLocks", "Requests", 5*time.Second)).
24 | Format(sqlite.NewConditionInterpreter())
25 |
26 | Expect(query).To(Equal("DELETE FROM TokenLocks WHERE tx_id IN (" +
27 | "SELECT tl.tx_id " +
28 | "FROM TokenLocks AS tl " +
29 | "LEFT JOIN Requests AS tr " +
30 | "ON tl.tx_id = tr.tx_id " +
31 | "WHERE (tr.status = $1) OR (tl.created_at < datetime('now', '-5 seconds'))" +
32 | ")"))
33 | Expect(args).To(ConsistOf(driver.Deleted))
34 | }
35 |
--------------------------------------------------------------------------------
/token/services/db/sql/sqlite/tokens.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package sqlite
8 |
9 | import (
10 | common2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/common"
11 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/notifier"
12 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/sql/sqlite"
13 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/db/sql/common"
14 | )
15 |
16 | type TokenStore = common.TokenStore
17 |
18 | func NewTokenStore(dbs *common2.RWDB, tableNames common.TableNames) (*TokenStore, error) {
19 | return common.NewTokenStore(dbs.ReadDB, dbs.WriteDB, tableNames, sqlite.NewConditionInterpreter())
20 | }
21 |
22 | type TokenNotifier struct {
23 | *notifier.Notifier
24 | }
25 |
26 | func NewTokenNotifier(*common2.RWDB, common.TableNames) (*TokenNotifier, error) {
27 | return &TokenNotifier{Notifier: notifier.NewNotifier()}, nil
28 | }
29 |
30 | func (db *TokenNotifier) CreateSchema() error { return nil }
31 |
--------------------------------------------------------------------------------
/token/services/db/sql/sqlite/transactions.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package sqlite
8 |
9 | import (
10 | common2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/common"
11 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/sql/query/pagination"
12 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/sql/sqlite"
13 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/db/sql/common"
14 | )
15 |
16 | type (
17 | AuditTransactionStore = common.TransactionStore
18 | OwnerTransactionStore = common.TransactionStore
19 | )
20 |
21 | func NewAuditTransactionStore(dbs *common2.RWDB, tableNames common.TableNames) (*AuditTransactionStore, error) {
22 | return common.NewAuditTransactionStore(dbs.ReadDB, dbs.WriteDB, tableNames, sqlite.NewConditionInterpreter(), pagination.NewDefaultInterpreter())
23 | }
24 |
25 | func NewTransactionStore(dbs *common2.RWDB, tableNames common.TableNames) (*OwnerTransactionStore, error) {
26 | return common.NewOwnerTransactionStore(dbs.ReadDB, dbs.WriteDB, tableNames, sqlite.NewConditionInterpreter(), pagination.NewDefaultInterpreter())
27 | }
28 |
--------------------------------------------------------------------------------
/token/services/db/sql/sqlite/wallet.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package sqlite
8 |
9 | import (
10 | common2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/common"
11 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/sql/sqlite"
12 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/db/sql/common"
13 | )
14 |
15 | type WalletStore = common.WalletStore
16 |
17 | func NewWalletStore(dbs *common2.RWDB, tableNames common.TableNames) (*WalletStore, error) {
18 | return common.NewWalletStore(dbs.ReadDB, dbs.WriteDB, tableNames, sqlite.NewConditionInterpreter())
19 | }
20 |
--------------------------------------------------------------------------------
/token/services/identity/config/testdata/invalid/core.yaml:
--------------------------------------------------------------------------------
1 | token:
2 | enabled: true
3 | tms:
4 | n1c1ns1:
5 | certification: null
6 | network: n1
7 | channel: c1
8 | namespace: ns1
9 | wallets:
10 | # Default cache size reference that can be used by any wallet that support caching
11 | defaultCacheSize: 3
12 | owners:
13 | - default: false
14 | id: owner1
15 | path: /path/to/crypto/owner1
16 | cacheSize: rehuifuerh
--------------------------------------------------------------------------------
/token/services/identity/driver/common.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package driver
8 |
9 | import (
10 | "context"
11 |
12 | "github.com/hyperledger-labs/fabric-token-sdk/token/driver"
13 | )
14 |
15 | type SigService interface {
16 | IsMe(context.Context, driver.Identity) bool
17 | RegisterSigner(identity driver.Identity, signer driver.Signer, verifier driver.Verifier, signerInfo []byte) error
18 | RegisterVerifier(identity driver.Identity, v driver.Verifier) error
19 | }
20 |
21 | type NetworkBinderService interface {
22 | Bind(ctx context.Context, longTerm driver.Identity, ephemeral driver.Identity) error
23 | }
24 |
25 | type BinderService interface {
26 | Bind(ctx context.Context, longTerm driver.Identity, ephemeral driver.Identity, copyAll bool) error
27 | }
28 |
29 | type IdentityProvider interface {
30 | // RegisterAuditInfo binds the passed audit info to the passed identity
31 | RegisterAuditInfo(identity driver.Identity, info []byte) error
32 |
33 | // GetAuditInfo returns the audit info associated to the passed identity, nil if not found
34 | GetAuditInfo(ctx context.Context, identity driver.Identity) ([]byte, error)
35 | }
36 |
--------------------------------------------------------------------------------
/token/services/identity/driver/config.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package driver
8 |
9 | type ConfiguredIdentity struct {
10 | ID string `yaml:"id"`
11 | Default bool `yaml:"default,omitempty"`
12 | Path string `yaml:"path"`
13 | CacheSize int `yaml:"cacheSize"`
14 | Type string `yaml:"type,omitempty"`
15 | Opts interface{} `yaml:"opts,omitempty"`
16 | }
17 |
18 | func (i *ConfiguredIdentity) String() string {
19 | return i.ID
20 | }
21 |
22 | type Config interface {
23 | // CacheSizeForOwnerID returns the cache size to be used for the given owner wallet.
24 | // If not defined, the function returns -1
25 | CacheSizeForOwnerID(id string) int
26 | TranslatePath(path string) string
27 | IdentitiesForRole(role IdentityRoleType) ([]*ConfiguredIdentity, error)
28 | }
29 |
--------------------------------------------------------------------------------
/token/services/identity/driver/driver.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package driver
8 |
9 | import tdriver "github.com/hyperledger-labs/fabric-token-sdk/token/driver"
10 |
11 | type Deserializer interface {
12 | DeserializeVerifier(raw []byte) (tdriver.Verifier, error)
13 | DeserializeSigner(raw []byte) (tdriver.Signer, error)
14 | Info(raw []byte, auditInfo []byte) (string, error)
15 | }
16 |
17 | type DeserializerManager interface {
18 | AddDeserializer(deserializer Deserializer)
19 | DeserializeSigner(raw []byte) (tdriver.Signer, error)
20 | }
21 |
22 | type AuditInfo interface {
23 | EnrollmentID() string
24 | RevocationHandle() string
25 | }
26 |
27 | type AuditInfoDeserializer interface {
28 | DeserializeAuditInfo([]byte) (AuditInfo, error)
29 | }
30 |
--------------------------------------------------------------------------------
/token/services/identity/driver/storage.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package driver
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-token-sdk/token"
11 | )
12 |
13 | type Keystore interface {
14 | Put(id string, state interface{}) error
15 | Get(id string, state interface{}) error
16 | }
17 |
18 | type StorageProvider interface {
19 | WalletStore(tmsID token.TMSID) (WalletStoreService, error)
20 | IdentityStore(tmsID token.TMSID) (IdentityStoreService, error)
21 | Keystore() (Keystore, error)
22 | }
23 |
--------------------------------------------------------------------------------
/token/services/identity/idemix/cache/cache_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package cache
8 |
9 | import (
10 | "testing"
11 |
12 | "github.com/hyperledger-labs/fabric-token-sdk/token/driver"
13 | "github.com/stretchr/testify/assert"
14 | )
15 |
16 | func TestIdentityCache(t *testing.T) {
17 | c := NewIdentityCache(func([]byte) (driver.Identity, []byte, error) {
18 | return []byte("hello world"), []byte("audit"), nil
19 | }, 100, nil)
20 | id, audit, err := c.Identity(nil)
21 | assert.NoError(t, err)
22 | assert.Equal(t, driver.Identity([]byte("hello world")), id)
23 | assert.Equal(t, []byte("audit"), audit)
24 |
25 | id, audit, err = c.Identity(nil)
26 | assert.NoError(t, err)
27 | assert.Equal(t, driver.Identity([]byte("hello world")), id)
28 | assert.Equal(t, []byte("audit"), audit)
29 | }
30 |
--------------------------------------------------------------------------------
/token/services/identity/idemix/crypto/protos/generate.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package protos
8 |
9 | //go:generate protoc idemix_config.proto --go_out=../protos-go/config --go_opt=paths=source_relative
10 |
--------------------------------------------------------------------------------
/token/services/identity/idemix/testdata/bls12_381_bbs/idemix/msp/IssuerPublicKey:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/token/services/identity/idemix/testdata/bls12_381_bbs/idemix/msp/IssuerPublicKey
--------------------------------------------------------------------------------
/token/services/identity/idemix/testdata/bls12_381_bbs/idemix/msp/RevocationPublicKey:
--------------------------------------------------------------------------------
1 | -----BEGIN PUBLIC KEY-----
2 | MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEE8emFexTWUYy5Ege3Yph8uFv8TqMAkIi
3 | xM47SYzFBy5ggQ/lNTknaJAXyzxT06WUXg4mvQ1OsX8GLA96ytqYHYP0PRTCt6MC
4 | 3Vx1lXkbfSFw0Q+J7l6Lst52DXHnVoI1
5 | -----END PUBLIC KEY-----
6 |
--------------------------------------------------------------------------------
/token/services/identity/idemix/testdata/bls12_381_bbs/idemix/user/SignerConfig:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/token/services/identity/idemix/testdata/bls12_381_bbs/idemix/user/SignerConfig
--------------------------------------------------------------------------------
/token/services/identity/idemix/testdata/bls12_381_bbs/idemix2/msp/IssuerPublicKey:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/token/services/identity/idemix/testdata/bls12_381_bbs/idemix2/msp/IssuerPublicKey
--------------------------------------------------------------------------------
/token/services/identity/idemix/testdata/bls12_381_bbs/idemix2/msp/RevocationPublicKey:
--------------------------------------------------------------------------------
1 | -----BEGIN PUBLIC KEY-----
2 | MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEE8emFexTWUYy5Ege3Yph8uFv8TqMAkIi
3 | xM47SYzFBy5ggQ/lNTknaJAXyzxT06WUXg4mvQ1OsX8GLA96ytqYHYP0PRTCt6MC
4 | 3Vx1lXkbfSFw0Q+J7l6Lst52DXHnVoI1
5 | -----END PUBLIC KEY-----
6 |
--------------------------------------------------------------------------------
/token/services/identity/idemix/testdata/bls12_381_bbs/idemix2/user/SignerConfig:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/token/services/identity/idemix/testdata/bls12_381_bbs/idemix2/user/SignerConfig
--------------------------------------------------------------------------------
/token/services/identity/idemix/testdata/fp256bn_amcl/charlie.ExtraId2/IssuerPublicKey:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/token/services/identity/idemix/testdata/fp256bn_amcl/charlie.ExtraId2/IssuerPublicKey
--------------------------------------------------------------------------------
/token/services/identity/idemix/testdata/fp256bn_amcl/charlie.ExtraId2/IssuerRevocationPublicKey:
--------------------------------------------------------------------------------
1 | -----BEGIN PUBLIC KEY-----
2 | MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEC8Li6cAeTbbm4EDn7WW6jadtm1SxyuZN
3 | VxO4b+lWIj1fM5q2ZQOfGhvX6tamjjqAsWcPlB9pExtqwNZYkmy/p08vEDjdcJdw
4 | /Zm+DxBgy/V0RqnOQoikUEY2HW1CiyOt
5 | -----END PUBLIC KEY-----
6 |
--------------------------------------------------------------------------------
/token/services/identity/idemix/testdata/fp256bn_amcl/charlie.ExtraId2/cacerts/localhost-7054-default-testchannel-token-chaincode-example-com.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIICFzCCAb2gAwIBAgIUG8VbHeXmzg6NP1p2keeEKLktU7swCgYIKoZIzj0EAwIw
3 | aDELMAkGA1UEBhMCVVMxFzAVBgNVBAgTDk5vcnRoIENhcm9saW5hMRQwEgYDVQQK
4 | EwtIeXBlcmxlZGdlcjEPMA0GA1UECxMGRmFicmljMRkwFwYDVQQDExBmYWJyaWMt
5 | Y2Etc2VydmVyMB4XDTIzMDYyOTE0MDUwMFoXDTM4MDYyNTE0MDUwMFowaDELMAkG
6 | A1UEBhMCVVMxFzAVBgNVBAgTDk5vcnRoIENhcm9saW5hMRQwEgYDVQQKEwtIeXBl
7 | cmxlZGdlcjEPMA0GA1UECxMGRmFicmljMRkwFwYDVQQDExBmYWJyaWMtY2Etc2Vy
8 | dmVyMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEzaCNErKmgyfKOI6+ZpySBWeR
9 | Ar/lC6xz3qMJfng43bwP8lh/itvs30bykj5rXV72SgKonzxpBg6Jmo33WRoMAaNF
10 | MEMwDgYDVR0PAQH/BAQDAgEGMBIGA1UdEwEB/wQIMAYBAf8CAQEwHQYDVR0OBBYE
11 | FHOGW/tJ64Z6Ey5YpPa2TKBbgad/MAoGCCqGSM49BAMCA0gAMEUCIQDrrplKe4+E
12 | kBWINrIeunCsfmLdRElCK32i0vhJKwoK8AIgWbqPYqahMWBFw0kjzcVhEo2nnluN
13 | /E50lRakHY0g7GY=
14 | -----END CERTIFICATE-----
15 |
--------------------------------------------------------------------------------
/token/services/identity/idemix/testdata/fp256bn_amcl/charlie.ExtraId2/user/SignerConfig:
--------------------------------------------------------------------------------
1 | {"Cred":"CkQKIBgoychRH352qH5kn2PgsDqYy7YV4fIIpNTPy3jKaqs0EiAUTfWTT3HERcQOH6SqiMsNvEOJZG67WgVZvZD38sy6jhJECiAZkx52wMXtHpAIyi2QVgQEtBvRADhuVSsbbnIezqqfehIgAWgT5QS+dXuI/roShhYnn8bHLHngTvTaAc3CjM4b7yYaIAjk8NdMhGHOnuQfg8Xt+r2E9F9bldx+CdWwK37KCePjIiAv/sSDk+3fTv2KP2cg7APGE3KGV7hggmNFZ8+Nw88SmyogIh+KdxQ1m225ut3uk2pXr4beoMJ9tdEHlQ3Cy7hSuFEqIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABKiAZf1sC4JEoVA9LcdmW7C/6O3/EluHH9kXv4h9IzY95zyogCr4VjjzRvI4syvTh/FeOnPdF1FmuvDwnOFpntdeHW0k=","Sk":"DpK+mjLmMq56x6HQFtksSyyaqhlVONwC2KcdWbK1hso=","enrollment_id":"charlie.ExtraId2","credential_revocation_information":"CAESiAEKIBmOk5OSDUg6cmC/tzH7XSXxqkkzNannEpfkhbeu8xLCEiAYAN7vEh8edkJqAGZeXER5Z0Mi1Pde2t1G3r1c2ZL27RogCQaJ0Fhf8HXsnpmtaQwzlbxLMTNws47zVaza3NEil1siIBLIXqXbjG3rSqtxgI3LQI/j0edpDEPTe0zmzAFm+n2qGmcwZQIwLNKDW/OpTOeREehIcKTqQZy55wHAmUwsBdOnGyAotrgRhBy5WV+QcbOnEH5QCXycAjEA23xRDoXD22WjgubK22tvf1uh6JZ+O5vGSD91TZq5OOKRTSIopomictjB+pLOk5Z7","revocation_handle":"1","curveID":"gurvy.Bn254"}
--------------------------------------------------------------------------------
/token/services/identity/idemix/testdata/fp256bn_amcl/idemix/msp/IssuerPublicKey:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/token/services/identity/idemix/testdata/fp256bn_amcl/idemix/msp/IssuerPublicKey
--------------------------------------------------------------------------------
/token/services/identity/idemix/testdata/fp256bn_amcl/idemix/msp/RevocationPublicKey:
--------------------------------------------------------------------------------
1 | -----BEGIN PUBLIC KEY-----
2 | MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAETdaxDspGM1btPa2IKFz8dmed/xc997JN
3 | S7hhEtholpkp5mRL7FPKLC0GURgSZohw7QjoMSHa5SoMsVo/89odJMTdf+hppSAN
4 | RZouDbFPyHKa0VDF8vQmZR37tZyMRete
5 | -----END PUBLIC KEY-----
6 |
--------------------------------------------------------------------------------
/token/services/identity/idemix/testdata/fp256bn_amcl/idemix/user/SignerConfig:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/token/services/identity/idemix/testdata/fp256bn_amcl/idemix/user/SignerConfig
--------------------------------------------------------------------------------
/token/services/identity/idemix/testdata/fp256bn_amcl/idemix2/msp/IssuerPublicKey:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/token/services/identity/idemix/testdata/fp256bn_amcl/idemix2/msp/IssuerPublicKey
--------------------------------------------------------------------------------
/token/services/identity/idemix/testdata/fp256bn_amcl/idemix2/msp/RevocationPublicKey:
--------------------------------------------------------------------------------
1 | -----BEGIN PUBLIC KEY-----
2 | MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAETdaxDspGM1btPa2IKFz8dmed/xc997JN
3 | S7hhEtholpkp5mRL7FPKLC0GURgSZohw7QjoMSHa5SoMsVo/89odJMTdf+hppSAN
4 | RZouDbFPyHKa0VDF8vQmZR37tZyMRete
5 | -----END PUBLIC KEY-----
6 |
--------------------------------------------------------------------------------
/token/services/identity/idemix/testdata/fp256bn_amcl/idemix2/user/SignerConfig:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/token/services/identity/idemix/testdata/fp256bn_amcl/idemix2/user/SignerConfig
--------------------------------------------------------------------------------
/token/services/identity/idemix/testdata/fp256bn_amcl/sameissuer/idemix/msp/IssuerPublicKey:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/token/services/identity/idemix/testdata/fp256bn_amcl/sameissuer/idemix/msp/IssuerPublicKey
--------------------------------------------------------------------------------
/token/services/identity/idemix/testdata/fp256bn_amcl/sameissuer/idemix/msp/RevocationPublicKey:
--------------------------------------------------------------------------------
1 | -----BEGIN PUBLIC KEY-----
2 | MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEUvyZcTtq+2+UzsKTElqAW/fugMoZwtfY
3 | kPpIwrjJbIHfOEvuyeGKNkvQbW8tCwFIQyDSLOKffaimGUDaftqdRPbzvpLXe28d
4 | jEBxo6tQa9BNzqnybKqJJtg7ceNMVD30
5 | -----END PUBLIC KEY-----
6 |
--------------------------------------------------------------------------------
/token/services/identity/idemix/testdata/fp256bn_amcl/sameissuer/idemix/user/SignerConfig:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/token/services/identity/idemix/testdata/fp256bn_amcl/sameissuer/idemix/user/SignerConfig
--------------------------------------------------------------------------------
/token/services/identity/idemix/testdata/fp256bn_amcl/sameissuer/idemix2/msp/IssuerPublicKey:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/token/services/identity/idemix/testdata/fp256bn_amcl/sameissuer/idemix2/msp/IssuerPublicKey
--------------------------------------------------------------------------------
/token/services/identity/idemix/testdata/fp256bn_amcl/sameissuer/idemix2/msp/RevocationPublicKey:
--------------------------------------------------------------------------------
1 | -----BEGIN PUBLIC KEY-----
2 | MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEUvyZcTtq+2+UzsKTElqAW/fugMoZwtfY
3 | kPpIwrjJbIHfOEvuyeGKNkvQbW8tCwFIQyDSLOKffaimGUDaftqdRPbzvpLXe28d
4 | jEBxo6tQa9BNzqnybKqJJtg7ceNMVD30
5 | -----END PUBLIC KEY-----
6 |
--------------------------------------------------------------------------------
/token/services/identity/idemix/testdata/fp256bn_amcl/sameissuer/idemix2/user/SignerConfig:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hyperledger-labs/fabric-token-sdk/6451c4d1bd0e9795d57fb4988be7ba54ffb9a692/token/services/identity/idemix/testdata/fp256bn_amcl/sameissuer/idemix2/user/SignerConfig
--------------------------------------------------------------------------------
/token/services/identity/idemix/testdata/generate.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package testdata
8 |
9 | //go:generate idemixgen ca-keygen --output ./bls12_381_bbs/ca --curve BLS12_381_BBS --aries
10 | //go:generate idemixgen signerconfig --ca-input ./bls12_381_bbs/ca --output ./bls12_381_bbs/idemix --admin -u example.com -e alice -r 150 --curve BLS12_381_BBS --aries
11 | //go:generate idemixgen signerconfig --ca-input ./bls12_381_bbs/ca --output ./bls12_381_bbs/idemix2 --admin -u example.com -e bob -r 200 --curve BLS12_381_BBS --aries
12 |
--------------------------------------------------------------------------------
/token/services/identity/interop/htlc/info.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package htlc
8 |
9 | import (
10 | "context"
11 | "encoding/json"
12 |
13 | "github.com/hyperledger-labs/fabric-token-sdk/token/driver"
14 | )
15 |
16 | type AuditInfoProvider interface {
17 | GetAuditInfo(ctx context.Context, identity driver.Identity) ([]byte, error)
18 | }
19 |
20 | // ScriptInfo includes info about the sender and the recipient
21 | type ScriptInfo struct {
22 | Sender []byte
23 | Recipient []byte
24 | }
25 |
26 | func (si *ScriptInfo) Marshal() ([]byte, error) {
27 | return json.Marshal(si)
28 | }
29 |
30 | func (si *ScriptInfo) Unmarshal(raw []byte) error {
31 | return json.Unmarshal(raw, si)
32 | }
33 |
--------------------------------------------------------------------------------
/token/services/identity/roles.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package identity
8 |
9 | import (
10 | "fmt"
11 |
12 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/identity/driver"
13 | )
14 |
15 | // RoleType is the role of an identity
16 | type RoleType = driver.IdentityRoleType
17 |
18 | const (
19 | // IssuerRole is the role of an issuer
20 | IssuerRole = driver.IssuerRole
21 | // AuditorRole is the role of an auditor
22 | AuditorRole = driver.AuditorRole
23 | // OwnerRole is the role of an owner
24 | OwnerRole = driver.OwnerRole
25 | // CertifierRole is the role of a certifier
26 | CertifierRole = driver.CertifierRole
27 | )
28 |
29 | var (
30 | RoleTypeStrings = driver.IdentityRoleStrings
31 | )
32 |
33 | func RoleToString(r RoleType) string {
34 | s, ok := RoleTypeStrings[r]
35 | if ok {
36 | return s
37 | }
38 | return fmt.Sprintf("role%d", r)
39 | }
40 |
41 | // Info models a long-term identity inside the Identity Provider.
42 | // An identity has an identifier (ID) and an Enrollment ID, unique identifier.
43 | // An identity can be remote, meaning that the corresponding secret key is remotely available.
44 | type Info = driver.IdentityInfo
45 |
46 | // Role is a container of long-term identities.
47 | // A long-term identity is then used to construct a wallet.
48 | type Role = driver.Role
49 |
--------------------------------------------------------------------------------
/token/services/identity/storage/kvs/hashicorp/identitydb_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package hashicorp_test
8 |
9 | import (
10 | "fmt"
11 | "testing"
12 |
13 | token2 "github.com/hyperledger-labs/fabric-token-sdk/token"
14 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/db/dbtest"
15 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/identity/storage/kvs"
16 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/identity/storage/kvs/hashicorp"
17 | "github.com/stretchr/testify/assert"
18 | )
19 |
20 | func TestIdentityDBWithHashicorpVault(t *testing.T) {
21 | terminate, vaultURL, token := hashicorp.StartHashicorpVaultContainer(t, 11200)
22 | defer terminate()
23 | client, err := hashicorp.NewVaultClient(vaultURL, token)
24 | assert.NoError(t, err)
25 |
26 | for i, c := range dbtest.IdentityCases {
27 | backend, err := hashicorp.NewWithClient(client, fmt.Sprintf("kv1/data/token-sdk/%d/", i))
28 | assert.NoError(t, err)
29 | db := kvs.NewIdentityStore(backend, token2.TMSID{
30 | Network: "apple",
31 | Channel: "pears",
32 | Namespace: "strawberries",
33 | })
34 | t.Run(c.Name, func(xt *testing.T) {
35 | c.Fn(xt, db)
36 | })
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/token/services/identity/storage/kvs/kvs.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package kvs
8 |
9 | import (
10 | "context"
11 |
12 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/kvs"
13 | )
14 |
15 | type KVS interface {
16 | Exists(ctx context.Context, id string) bool
17 | GetExisting(ctx context.Context, ids ...string) []string
18 | Put(ctx context.Context, id string, state interface{}) error
19 | Get(ctx context.Context, id string, state interface{}) error
20 | GetByPartialCompositeID(ctx context.Context, prefix string, attrs []string) (kvs.Iterator, error)
21 | }
22 |
--------------------------------------------------------------------------------
/token/services/identity/storage/kvs/memory.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package kvs
8 |
9 | import (
10 | "context"
11 |
12 | "github.com/IBM/idemix/bccsp/keystore"
13 | "github.com/hyperledger-labs/fabric-smart-client/platform/common/utils"
14 | memory "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/memory"
15 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/kvs"
16 | )
17 |
18 | func NewInMemory() (KVS, error) {
19 | return kvs.New(utils.MustGet(memory.NewDriver().NewKVS("")), "", kvs.DefaultCacheSize)
20 | }
21 |
22 | func Keystore(kvs KVS) keystore.KVS {
23 | return &kvsAdapter{kvs: kvs}
24 | }
25 |
26 | type kvsAdapter struct {
27 | kvs KVS
28 | }
29 |
30 | func (k *kvsAdapter) Put(id string, state interface{}) error {
31 | return k.kvs.Put(context.Background(), id, state)
32 | }
33 |
34 | func (k *kvsAdapter) Get(id string, state interface{}) error {
35 | return k.kvs.Get(context.Background(), id, state)
36 | }
37 |
--------------------------------------------------------------------------------
/token/services/identity/typed.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package identity
8 |
9 | import (
10 | "encoding/asn1"
11 |
12 | "github.com/hyperledger-labs/fabric-token-sdk/token/driver"
13 | "github.com/pkg/errors"
14 | )
15 |
16 | type (
17 | Type = string
18 | Identity = driver.Identity
19 | )
20 |
21 | // TypedIdentity encodes an identity with a type.
22 | type TypedIdentity struct {
23 | // Type encodes the type of the identity
24 | Type Type `protobuf:"bytes,1,opt,name=type,json=type,proto3" json:"type,omitempty"`
25 | // Identity encodes the identity itself
26 | Identity Identity `protobuf:"bytes,2,opt,name=identity,proto3" json:"identity,omitempty"`
27 | }
28 |
29 | func (i TypedIdentity) Bytes() ([]byte, error) {
30 | return asn1.Marshal(i)
31 | }
32 |
33 | func UnmarshalTypedIdentity(id driver.Identity) (*TypedIdentity, error) {
34 | si := &TypedIdentity{}
35 | _, err := asn1.Unmarshal(id, si)
36 | if err != nil {
37 | return nil, errors.Wrap(err, "failed to unmarshal to TypedIdentity")
38 | }
39 | return si, nil
40 | }
41 |
42 | func WrapWithType(idType Type, id driver.Identity) (driver.Identity, error) {
43 | raw, err := (&TypedIdentity{Type: idType, Identity: id}).Bytes()
44 | if err != nil {
45 | return nil, err
46 | }
47 | return raw, nil
48 | }
49 |
--------------------------------------------------------------------------------
/token/services/identity/x509/audit.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package x509
8 |
9 | import "encoding/json"
10 |
11 | type AuditInfo struct {
12 | EID string
13 | RH []byte
14 | }
15 |
16 | func (a *AuditInfo) Bytes() ([]byte, error) {
17 | return json.Marshal(a)
18 | }
19 |
20 | func (a *AuditInfo) FromBytes(raw []byte) error {
21 | return json.Unmarshal(raw, a)
22 | }
23 |
24 | func (a *AuditInfo) EnrollmentID() string {
25 | return a.EID
26 | }
27 |
28 | func (a *AuditInfo) RevocationHandle() string {
29 | return string(a.RH)
30 | }
31 |
--------------------------------------------------------------------------------
/token/services/identity/x509/crypto/csp/hash.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package csp
8 |
9 | import (
10 | "hash"
11 |
12 | "github.com/hyperledger/fabric/bccsp"
13 | )
14 |
15 | type hasher struct {
16 | hash func() hash.Hash
17 | }
18 |
19 | func (c *hasher) Hash(msg []byte, opts bccsp.HashOpts) ([]byte, error) {
20 | h := c.hash()
21 | h.Write(msg)
22 | return h.Sum(nil), nil
23 | }
24 |
25 | func (c *hasher) GetHash(opts bccsp.HashOpts) (hash.Hash, error) {
26 | return c.hash(), nil
27 | }
28 |
--------------------------------------------------------------------------------
/token/services/identity/x509/crypto/csp/keygen.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package csp
8 |
9 | import (
10 | "crypto/ecdsa"
11 | "crypto/elliptic"
12 | "crypto/rand"
13 |
14 | "github.com/hyperledger/fabric/bccsp"
15 | "github.com/pkg/errors"
16 | )
17 |
18 | type ecdsaKeyGenerator struct {
19 | curve elliptic.Curve
20 | }
21 |
22 | func (kg *ecdsaKeyGenerator) KeyGen(opts bccsp.KeyGenOpts) (bccsp.Key, error) {
23 | privKey, err := ecdsa.GenerateKey(kg.curve, rand.Reader)
24 | if err != nil {
25 | return nil, errors.Wrapf(err, "failed generating ECDSA key for [%v]", kg.curve)
26 | }
27 |
28 | return &ecdsaPrivateKey{privKey}, nil
29 | }
30 |
--------------------------------------------------------------------------------
/token/services/identity/x509/crypto/csp/keys.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package csp
8 |
9 | import (
10 | "crypto/ecdsa"
11 | "crypto/x509"
12 | "errors"
13 | )
14 |
15 | func derToPrivateKey(der []byte) (key interface{}, err error) {
16 | if key, err = x509.ParsePKCS1PrivateKey(der); err == nil {
17 | return key, nil
18 | }
19 |
20 | if key, err = x509.ParsePKCS8PrivateKey(der); err == nil {
21 | switch key.(type) {
22 | case *ecdsa.PrivateKey:
23 | return
24 | default:
25 | return nil, errors.New("found unknown private key type in PKCS#8 wrapping")
26 | }
27 | }
28 |
29 | if key, err = x509.ParseECPrivateKey(der); err == nil {
30 | return
31 | }
32 |
33 | return nil, errors.New("invalid key type. The DER must contain an ecdsa.PrivateKey")
34 | }
35 |
36 | func derToPublicKey(raw []byte) (pub interface{}, err error) {
37 | if len(raw) == 0 {
38 | return nil, errors.New("invalid DER. It must be different from nil")
39 | }
40 |
41 | key, err := x509.ParsePKIXPublicKey(raw)
42 |
43 | return key, err
44 | }
45 |
--------------------------------------------------------------------------------
/token/services/identity/x509/crypto/deserializer.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package crypto
8 |
9 | import (
10 | "crypto/ecdsa"
11 | "fmt"
12 |
13 | "github.com/hyperledger-labs/fabric-smart-client/pkg/utils/errors"
14 | "github.com/hyperledger-labs/fabric-token-sdk/token/driver"
15 | )
16 |
17 | func DeserializeVerifier(id driver.Identity) (driver.Verifier, error) {
18 | genericPublicKey, err := PemDecodeKey(id)
19 | if err != nil {
20 | return nil, errors.Wrap(err, "failed parsing received public key")
21 | }
22 | publicKey, ok := genericPublicKey.(*ecdsa.PublicKey)
23 | if !ok {
24 | return nil, errors.New("expected *ecdsa.PublicKey")
25 | }
26 | return NewECDSAVerifier(publicKey), nil
27 | }
28 |
29 | func Info(raw []byte) (string, error) {
30 | cert, err := PemDecodeCert(raw)
31 | if err != nil {
32 | return "", err
33 | }
34 | return fmt.Sprintf("X509: [%s][%s]", driver.Identity(raw).UniqueID(), cert.Subject.CommonName), nil
35 | }
36 |
--------------------------------------------------------------------------------
/token/services/identity/x509/crypto/eidrh.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package crypto
8 |
9 | import (
10 | "crypto/x509"
11 | "strings"
12 |
13 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/hash"
14 | "github.com/pkg/errors"
15 | )
16 |
17 | func GetEnrollmentID(id []byte) (string, error) {
18 | cert, err := PemDecodeCert(id)
19 | if err != nil {
20 | return "", err
21 | }
22 | cn := cert.Subject.CommonName
23 | // if cn contains a @, then return only the left part of the string
24 | index := strings.Index(cn, "@")
25 | if index != -1 {
26 | cn = cn[:index]
27 | }
28 | return cn, nil
29 | }
30 |
31 | func GetRevocationHandle(id []byte) ([]byte, error) {
32 | cert, err := PemDecodeCert(id)
33 | if err != nil {
34 | return nil, err
35 | }
36 | encoded, err := x509.MarshalPKIXPublicKey(cert.PublicKey)
37 | if err != nil {
38 | return nil, errors.WithMessage(err, "Failed to marshal PKI public key")
39 | }
40 | return []byte(hash.Hashable(encoded).String()), nil
41 | }
42 |
--------------------------------------------------------------------------------
/token/services/identity/x509/crypto/mocks/key.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package mocks
8 |
9 | import "github.com/hyperledger/fabric/bccsp"
10 |
11 | type Key struct{}
12 |
13 | func (t *Key) Bytes() ([]byte, error) {
14 | // TODO implement me
15 | panic("implement me")
16 | }
17 |
18 | func (t *Key) SKI() []byte {
19 | // TODO implement me
20 | panic("implement me")
21 | }
22 |
23 | func (t *Key) Symmetric() bool {
24 | // TODO implement me
25 | panic("implement me")
26 | }
27 |
28 | func (t *Key) Private() bool {
29 | // TODO implement me
30 | panic("implement me")
31 | }
32 |
33 | func (t *Key) PublicKey() (bccsp.Key, error) {
34 | // TODO implement me
35 | panic("implement me")
36 | }
37 |
--------------------------------------------------------------------------------
/token/services/identity/x509/crypto/protos/generate.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package protos
8 |
9 | //go:generate protoc x509_config.proto --go_out=../protos-go/config --go_opt=paths=source_relative
10 |
--------------------------------------------------------------------------------
/token/services/identity/x509/testdata/msp/keystore/priv_sk:
--------------------------------------------------------------------------------
1 | -----BEGIN PRIVATE KEY-----
2 | MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgnua+u09X+gqgMIoa
3 | LB+Wx1ubmzyws2zV2wgrOLMudH+hRANCAAQfoflioOL9uq1twxj7x4ucuMdDep7u
4 | 6yqJMG2AivhfLNpXQIItnilWC8SnRCrKklJNRouiDAGAnAQBxDPiEcDl
5 | -----END PRIVATE KEY-----
6 |
--------------------------------------------------------------------------------
/token/services/identity/x509/testdata/msp/signcerts/auditor.org1.example.com-cert.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIICGzCCAcGgAwIBAgIQStFHgcrqyWKnhU6IaiIy4DAKBggqhkjOPQQDAjBzMQsw
3 | CQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy
4 | YW5jaXNjbzEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEcMBoGA1UEAxMTY2Eu
5 | b3JnMS5leGFtcGxlLmNvbTAeFw0yMTAyMDMwOTEzMDBaFw0zMTAyMDEwOTEzMDBa
6 | MF0xCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1T
7 | YW4gRnJhbmNpc2NvMSEwHwYDVQQDExhhdWRpdG9yLm9yZzEuZXhhbXBsZS5jb20w
8 | WTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAQfoflioOL9uq1twxj7x4ucuMdDep7u
9 | 6yqJMG2AivhfLNpXQIItnilWC8SnRCrKklJNRouiDAGAnAQBxDPiEcDlo00wSzAO
10 | BgNVHQ8BAf8EBAMCB4AwDAYDVR0TAQH/BAIwADArBgNVHSMEJDAigCB1RzfqXXdy
11 | 4Ox5KCv1YawRo//gn64GWnWX6NOgjWYveDAKBggqhkjOPQQDAgNIADBFAiEAwUxj
12 | Jvg9GplXsDaFmLLxa6IPZqxTpouthPjwsQXzHSUCIH/lnC+XFxN2643iEKO+m7Cr
13 | qjQWln/aJUEy7o/cX+Tg
14 | -----END CERTIFICATE-----
15 |
--------------------------------------------------------------------------------
/token/services/identity/x509/testdata/msp1/signcerts/auditor.org1.example.com-cert.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIICGzCCAcGgAwIBAgIQStFHgcrqyWKnhU6IaiIy4DAKBggqhkjOPQQDAjBzMQsw
3 | CQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy
4 | YW5jaXNjbzEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEcMBoGA1UEAxMTY2Eu
5 | b3JnMS5leGFtcGxlLmNvbTAeFw0yMTAyMDMwOTEzMDBaFw0zMTAyMDEwOTEzMDBa
6 | MF0xCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1T
7 | YW4gRnJhbmNpc2NvMSEwHwYDVQQDExhhdWRpdG9yLm9yZzEuZXhhbXBsZS5jb20w
8 | WTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAQfoflioOL9uq1twxj7x4ucuMdDep7u
9 | 6yqJMG2AivhfLNpXQIItnilWC8SnRCrKklJNRouiDAGAnAQBxDPiEcDlo00wSzAO
10 | BgNVHQ8BAf8EBAMCB4AwDAYDVR0TAQH/BAIwADArBgNVHSMEJDAigCB1RzfqXXdy
11 | 4Ox5KCv1YawRo//gn64GWnWX6NOgjWYveDAKBggqhkjOPQQDAgNIADBFAiEAwUxj
12 | Jvg9GplXsDaFmLLxa6IPZqxTpouthPjwsQXzHSUCIH/lnC+XFxN2643iEKO+m7Cr
13 | qjQWln/aJUEy7o/cX+Tg
14 | -----END CERTIFICATE-----
15 |
--------------------------------------------------------------------------------
/token/services/identity/x509/testdata/msp2/keystoreFull/priv_sk:
--------------------------------------------------------------------------------
1 | -----BEGIN PRIVATE KEY-----
2 | MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgnua+u09X+gqgMIoa
3 | LB+Wx1ubmzyws2zV2wgrOLMudH+hRANCAAQfoflioOL9uq1twxj7x4ucuMdDep7u
4 | 6yqJMG2AivhfLNpXQIItnilWC8SnRCrKklJNRouiDAGAnAQBxDPiEcDl
5 | -----END PRIVATE KEY-----
6 |
--------------------------------------------------------------------------------
/token/services/identity/x509/testdata/msp2/signcerts/auditor.org1.example.com-cert.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIICGzCCAcGgAwIBAgIQStFHgcrqyWKnhU6IaiIy4DAKBggqhkjOPQQDAjBzMQsw
3 | CQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNU2FuIEZy
4 | YW5jaXNjbzEZMBcGA1UEChMQb3JnMS5leGFtcGxlLmNvbTEcMBoGA1UEAxMTY2Eu
5 | b3JnMS5leGFtcGxlLmNvbTAeFw0yMTAyMDMwOTEzMDBaFw0zMTAyMDEwOTEzMDBa
6 | MF0xCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1T
7 | YW4gRnJhbmNpc2NvMSEwHwYDVQQDExhhdWRpdG9yLm9yZzEuZXhhbXBsZS5jb20w
8 | WTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAQfoflioOL9uq1twxj7x4ucuMdDep7u
9 | 6yqJMG2AivhfLNpXQIItnilWC8SnRCrKklJNRouiDAGAnAQBxDPiEcDlo00wSzAO
10 | BgNVHQ8BAf8EBAMCB4AwDAYDVR0TAQH/BAIwADArBgNVHSMEJDAigCB1RzfqXXdy
11 | 4Ox5KCv1YawRo//gn64GWnWX6NOgjWYveDAKBggqhkjOPQQDAgNIADBFAiEAwUxj
12 | Jvg9GplXsDaFmLLxa6IPZqxTpouthPjwsQXzHSUCIH/lnC+XFxN2643iEKO+m7Cr
13 | qjQWln/aJUEy7o/cX+Tg
14 | -----END CERTIFICATE-----
15 |
--------------------------------------------------------------------------------
/token/services/identitydb/store.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package identitydb
8 |
9 | import (
10 | driver2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/driver"
11 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/config"
12 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/db"
13 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/db/driver"
14 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/db/sql/multiplexed"
15 | )
16 |
17 | type StoreServiceManager db.StoreServiceManager[*StoreService]
18 |
19 | func NewStoreServiceManager(cp driver2.ConfigService, drivers multiplexed.Driver) StoreServiceManager {
20 | return db.NewStoreServiceManager(config.NewService(cp), "identitydb.persistence", drivers.NewIdentity, newStoreService)
21 | }
22 |
23 | // StoreService is a database that stores identity related information
24 | type StoreService struct {
25 | driver.IdentityStore
26 | }
27 |
28 | func newStoreService(p driver.IdentityStore) (*StoreService, error) {
29 | return &StoreService{IdentityStore: p}, nil
30 | }
31 |
--------------------------------------------------------------------------------
/token/services/identitydb/store_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package identitydb_test
8 |
9 | import (
10 | "testing"
11 |
12 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/core/config"
13 | sqlite2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/sql/sqlite"
14 | token2 "github.com/hyperledger-labs/fabric-token-sdk/token"
15 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/db/sql/multiplexed"
16 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/db/sql/sqlite"
17 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/identitydb"
18 | "github.com/stretchr/testify/assert"
19 | )
20 |
21 | func TestDB(t *testing.T) {
22 | // create a new config service by loading the config file
23 | cp, err := config.NewProvider("./testdata/sqlite")
24 | assert.NoError(t, err)
25 |
26 | manager := identitydb.NewStoreServiceManager(cp, multiplexed.NewDriver(cp, sqlite.NewNamedDriver(cp, sqlite2.NewDbProvider())))
27 | _, err = manager.StoreServiceByTMSId(token2.TMSID{Network: "pineapple"})
28 | assert.NoError(t, err)
29 | }
30 |
--------------------------------------------------------------------------------
/token/services/identitydb/testdata/sqlite/core.yaml:
--------------------------------------------------------------------------------
1 | fsc:
2 | persistences:
3 | token_persistence:
4 | type: sqlite
5 | opts:
6 | dataSource: file:tmp?_pragma=journal_mode(WAL)&_pragma=busy_timeout(20000)&mode=memory&cache=shared
7 | skipCreateSchema: false
8 | tablePrefix: tsdk
9 | maxOpenConns: 10
10 |
11 | token:
12 | enabled: true
13 | tms:
14 | pineapple:
15 | network: pineapple
16 | channel:
17 | namespace:
18 | identitydb:
19 | persistence: token_persistence
20 | grapes:
21 | network: grapes
22 | channel:
23 | namespace:
24 | identitydb:
25 | persistence: token_persistence
--------------------------------------------------------------------------------
/token/services/interop/encoding/encoding_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package encoding_test
8 |
9 | import (
10 | "encoding/base64"
11 | "encoding/hex"
12 | "testing"
13 |
14 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/interop/encoding"
15 | "github.com/stretchr/testify/assert"
16 | )
17 |
18 | func TestEncodingNone(t *testing.T) {
19 | msg := []byte("hello world")
20 | e := encoding.None.New()
21 | o1 := e.EncodeToString(msg)
22 | assert.Equal(t, o1, string(msg))
23 | }
24 |
25 | func TestEncodingBase64(t *testing.T) {
26 | msg := []byte("hello world")
27 | e := encoding.Base64.New()
28 | o1 := e.EncodeToString(msg)
29 | o2 := base64.StdEncoding.EncodeToString(msg)
30 | assert.Equal(t, o1, o2)
31 | }
32 |
33 | func TestEncodingHex(t *testing.T) {
34 | msg := []byte("hello world")
35 | e := encoding.Hex.New()
36 | o1 := e.EncodeToString(msg)
37 | o2 := hex.EncodeToString(msg)
38 | assert.Equal(t, o1, o2)
39 | }
40 |
--------------------------------------------------------------------------------
/token/services/interop/encoding/logger.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package encoding
8 |
9 | import "github.com/hyperledger-labs/fabric-token-sdk/token/services/logging"
10 |
11 | var logger = logging.MustGetLogger()
12 |
--------------------------------------------------------------------------------
/token/services/interop/htlc/accept.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package htlc
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
11 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/ttx"
12 | )
13 |
14 | // NewAcceptView returns an instance of the ttx acceptView struct
15 | func NewAcceptView(tx *Transaction) view.View {
16 | return ttx.NewAcceptView(tx.Transaction)
17 | }
18 |
--------------------------------------------------------------------------------
/token/services/interop/htlc/finality.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package htlc
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
11 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/ttx"
12 | )
13 |
14 | // NewFinalityView returns an instance of the ttx FinalityView
15 | func NewFinalityView(tx *Transaction, opts ...ttx.TxOption) view.View {
16 | return ttx.NewFinalityView(tx.Transaction, opts...)
17 | }
18 |
--------------------------------------------------------------------------------
/token/services/interop/htlc/keys.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package htlc
8 |
9 | import (
10 | "encoding/hex"
11 | )
12 |
13 | const (
14 | ClaimPreImage = "htlc.cpi"
15 | LockHash = "htlc.lh"
16 | )
17 |
18 | // ClaimKey returns the claim key for the passed byte array
19 | func ClaimKey(v []byte) string {
20 | return ClaimPreImage + hex.EncodeToString(v)
21 | }
22 |
23 | // LockKey returns the lock key for the passed byte array
24 | func LockKey(v []byte) string {
25 | return LockHash + hex.EncodeToString(v)
26 | }
27 |
28 | // LockValue returns the encoding of the value for a lock key
29 | func LockValue(v []byte) []byte {
30 | return []byte(hex.EncodeToString(v))
31 | }
32 |
--------------------------------------------------------------------------------
/token/services/interop/htlc/logger.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package htlc
8 |
9 | import "github.com/hyperledger-labs/fabric-token-sdk/token/services/logging"
10 |
11 | var logger = logging.MustGetLogger()
12 |
--------------------------------------------------------------------------------
/token/services/interop/htlc/ordering.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package htlc
8 |
9 | import (
10 | "time"
11 |
12 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
13 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/ttx"
14 | )
15 |
16 | // NewOrderingAndFinalityView returns a new instance of the ttx orderingAndFinalityView struct
17 | func NewOrderingAndFinalityView(tx *Transaction) view.View {
18 | return ttx.NewOrderingAndFinalityView(tx.Transaction)
19 | }
20 |
21 | // NewOrderingAndFinalityWithTimeoutView returns a new instance of the ttx orderingAndFinalityWithTimeoutView struct
22 | func NewOrderingAndFinalityWithTimeoutView(tx *Transaction, timeout time.Duration) view.View {
23 | return ttx.NewOrderingAndFinalityWithTimeoutView(tx.Transaction, timeout)
24 | }
25 |
--------------------------------------------------------------------------------
/token/services/interop/htlc/recipients.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package htlc
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
11 | "github.com/hyperledger-labs/fabric-token-sdk/token"
12 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/ttx"
13 | )
14 |
15 | // ExchangeRecipientIdentities executes the ttx ExchangeRecipientIdentitiesView
16 | func ExchangeRecipientIdentities(context view.Context, walletID string, recipient view.Identity, opts ...token.ServiceOption) (view.Identity, view.Identity, error) {
17 | return ttx.ExchangeRecipientIdentities(context, walletID, recipient, opts...)
18 | }
19 |
20 | // RespondExchangeRecipientIdentities executes the ttx RespondExchangeRecipientIdentitiesView
21 | func RespondExchangeRecipientIdentities(context view.Context) (view.Identity, view.Identity, error) {
22 | return ttx.RespondExchangeRecipientIdentities(context)
23 | }
24 |
--------------------------------------------------------------------------------
/token/services/logging/mock.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package logging
8 |
9 | import "github.com/hyperledger-labs/fabric-smart-client/platform/common/services/logging"
10 |
11 | type MockLogger = logging.MockLogger
12 |
--------------------------------------------------------------------------------
/token/services/logging/types.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | package logging
7 |
8 | import (
9 | "fmt"
10 | "strings"
11 |
12 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/hash"
13 | )
14 |
15 | func WalletID(id string) fmt.Stringer {
16 | return walletID(id)
17 | }
18 |
19 | type walletID string
20 |
21 | func (w walletID) String() string {
22 | s := string(w)
23 | if len(s) <= 20 {
24 | return strings.ToValidUTF8(s, "X")
25 | }
26 | return fmt.Sprintf("%s~%s", strings.ToValidUTF8(s[:20], "X"), hash.Hashable(s).String())
27 | }
28 |
--------------------------------------------------------------------------------
/token/services/network/common/fetcher.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package common
8 |
9 | type Fetcher interface {
10 | FetchPublicParameters(namespace string) ([]byte, error)
11 | }
12 |
13 | type publicParamsFetcher struct {
14 | fetcher Fetcher
15 | namespace string
16 | }
17 |
18 | func NewPublicParamsFetcher(fetcher Fetcher, namespace string) *publicParamsFetcher {
19 | return &publicParamsFetcher{
20 | fetcher: fetcher,
21 | namespace: namespace,
22 | }
23 | }
24 |
25 | func (c *publicParamsFetcher) Fetch() ([]byte, error) {
26 | return c.fetcher.FetchPublicParameters(c.namespace)
27 | }
28 |
--------------------------------------------------------------------------------
/token/services/network/common/finalitymanager.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package common
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-smart-client/platform/common/driver"
11 | )
12 |
13 | type parallelListenerManagerProvider[V comparable] struct {
14 | provider driver.ListenerManagerProvider[V]
15 | }
16 |
17 | func NewParallelListenerManagerProvider[V comparable](provider driver.ListenerManagerProvider[V]) *parallelListenerManagerProvider[V] {
18 | return ¶llelListenerManagerProvider[V]{provider: provider}
19 | }
20 |
21 | func (p *parallelListenerManagerProvider[V]) NewManager() driver.ListenerManager[V] {
22 | return ¶llelListenerManager[V]{ListenerManager: p.provider.NewManager()}
23 | }
24 |
25 | type parallelListenerManager[V comparable] struct {
26 | driver.ListenerManager[V]
27 | }
28 |
29 | func (m *parallelListenerManager[V]) InvokeListeners(event driver.FinalityEvent[V]) {
30 | m.ListenerManager.InvokeListeners(event)
31 | }
32 |
--------------------------------------------------------------------------------
/token/services/network/common/normalizer.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package common
8 |
9 | import "github.com/hyperledger-labs/fabric-token-sdk/token/services/config"
10 |
11 | // Configuration models the configuration provider
12 | type Configuration interface {
13 | // LookupNamespace searches for a TMS configuration that matches the given network and channel, and
14 | // return its namespace.
15 | // If no matching configuration is found, an error is returned.
16 | // If multiple matching configurations are found, an error is returned.
17 | LookupNamespace(network, channel string) (string, error)
18 |
19 | ConfigurationFor(network, channel, namespace string) (config.Configuration, error)
20 | }
21 |
--------------------------------------------------------------------------------
/token/services/network/common/rws/translator/issuer.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | package translator
7 |
8 | import "github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
9 |
10 | //go:generate counterfeiter -o mock/issuing_validator.go -fake-name IssuingValidator . IssuingValidator
11 |
12 | // IssuingValidator is used to establish if the creator can issue tokens of the passed type.
13 | type IssuingValidator interface {
14 | // Validate returns no error if the passed creator can issue tokens of the passed type,, an error otherwise.
15 | Validate(creator view.Identity, tokenType string) error
16 | }
17 |
--------------------------------------------------------------------------------
/token/services/network/common/rws/translator/translator_suite_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | package translator_test
7 |
8 | import (
9 | "testing"
10 |
11 | . "github.com/onsi/ginkgo/v2"
12 | . "github.com/onsi/gomega"
13 | )
14 |
15 | func TestTranslator(t *testing.T) {
16 | RegisterFailHandler(Fail)
17 | RunSpecs(t, "Translator and Approver Suite")
18 | }
19 |
--------------------------------------------------------------------------------
/token/services/network/driver/driver.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package driver
8 |
9 | // Driver models the network driver factory
10 | type Driver interface {
11 | // New returns a new network instance for the passed network and channel (if applicable)
12 | New(network, channel string) (Network, error)
13 | }
14 |
--------------------------------------------------------------------------------
/token/services/network/driver/envelope.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package driver
8 |
9 | // Envelope models a network envelope
10 | type Envelope interface {
11 | // Bytes marshals the envelope to bytes
12 | Bytes() ([]byte, error)
13 |
14 | // FromBytes unmarshals the envelope from bytes
15 | FromBytes([]byte) error
16 |
17 | // TxID returns the ID of this envelope
18 | TxID() string
19 |
20 | // String returns the string representation of this envelope
21 | String() string
22 | }
23 |
--------------------------------------------------------------------------------
/token/services/network/driver/ledger.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package driver
8 |
9 | // Ledger models the ledger service
10 | type Ledger interface {
11 | // Status returns the status of the transaction
12 | Status(id string) (ValidationCode, error)
13 | }
14 |
--------------------------------------------------------------------------------
/token/services/network/driver/lm.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package driver
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
11 | )
12 |
13 | // LocalMembership models the local membership service
14 | type LocalMembership interface {
15 | // DefaultIdentity returns the default FSC node identity
16 | DefaultIdentity() view.Identity
17 |
18 | // AnonymousIdentity returns a fresh anonymous identity
19 | AnonymousIdentity() (view.Identity, error)
20 | }
21 |
--------------------------------------------------------------------------------
/token/services/network/driver/tokens.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package driver
8 |
9 | import (
10 | "context"
11 |
12 | token2 "github.com/hyperledger-labs/fabric-token-sdk/token/token"
13 | )
14 |
15 | type TokenQueryExecutorProvider interface {
16 | GetExecutor(network, channel string) (TokenQueryExecutor, error)
17 | }
18 |
19 | // TokenQueryExecutor queries the global state/ledger for tokens
20 | type TokenQueryExecutor interface {
21 | QueryTokens(ctx context.Context, namespace string, IDs []*token2.ID) ([][]byte, error)
22 | }
23 |
24 | type SpentTokenQueryExecutorProvider interface {
25 | GetSpentExecutor(network, channel string) (SpentTokenQueryExecutor, error)
26 | }
27 |
28 | // SpentTokenQueryExecutor queries the global state/ledger for tokens
29 | type SpentTokenQueryExecutor interface {
30 | QuerySpentTokens(ctx context.Context, namespace string, IDs []*token2.ID, meta []string) ([]bool, error)
31 | }
32 |
--------------------------------------------------------------------------------
/token/services/network/driver/vault.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package driver
8 |
9 | type ValidationCode = int
10 |
11 | const (
12 | _ ValidationCode = iota
13 | Valid // Transaction is valid and committed
14 | Invalid // Transaction is invalid and has been discarded
15 | Busy // Transaction does not yet have a validity state
16 | Unknown // Transaction is unknown
17 | )
18 |
19 | type TxStatus = int
20 |
--------------------------------------------------------------------------------
/token/services/network/fabric/finality/delivery.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package finality
8 |
9 | import (
10 | "context"
11 |
12 | "github.com/hyperledger-labs/fabric-smart-client/platform/fabric"
13 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/logging"
14 | )
15 |
16 | type Delivery struct {
17 | *fabric.Delivery
18 | *fabric.Ledger
19 | Logger logging.Logger
20 | }
21 |
22 | func (d *Delivery) ScanBlock(background context.Context, callback fabric.BlockCallback) error {
23 | startingBlock := uint64(0)
24 | if d.Ledger != nil {
25 | info, err := d.GetLedgerInfo()
26 | if err == nil {
27 | startingBlock = info.Height
28 | } else {
29 | d.Logger.Errorf("failed to get ledger info: %s", err)
30 | }
31 | }
32 | return d.ScanBlockFrom(background, startingBlock, callback)
33 | }
34 |
--------------------------------------------------------------------------------
/token/services/network/fabric/ppfetcher.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package fabric
8 |
9 | import (
10 | "context"
11 |
12 | driver2 "github.com/hyperledger-labs/fabric-smart-client/platform/common/driver"
13 | "github.com/hyperledger-labs/fabric-smart-client/platform/fabric/services/chaincode"
14 | "github.com/hyperledger-labs/fabric-smart-client/platform/view"
15 | )
16 |
17 | func NewChaincodePublicParamsFetcher(viewManager *view.Manager) *chaincodePublicParamsFetcher {
18 | return &chaincodePublicParamsFetcher{viewManager: viewManager}
19 | }
20 |
21 | type chaincodePublicParamsFetcher struct {
22 | viewManager ViewManager
23 | }
24 |
25 | func (f *chaincodePublicParamsFetcher) Fetch(network driver2.Network, channel driver2.Channel, namespace driver2.Namespace) ([]byte, error) {
26 | ppBoxed, err := f.viewManager.InitiateView(
27 | chaincode.NewQueryView(
28 | namespace,
29 | QueryPublicParamsFunction,
30 | ).WithNetwork(network).WithChannel(channel),
31 | context.TODO(),
32 | )
33 | if err != nil {
34 | return nil, err
35 | }
36 | return ppBoxed.([]byte), nil
37 | }
38 |
--------------------------------------------------------------------------------
/token/services/network/fabric/rws.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package fabric
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-smart-client/platform/fabric"
11 | "github.com/pkg/errors"
12 | )
13 |
14 | type RWSWrapper struct {
15 | r *fabric.RWSet
16 | }
17 |
18 | func NewRWSWrapper(r *fabric.RWSet) *RWSWrapper {
19 | return &RWSWrapper{r: r}
20 | }
21 |
22 | func (rwset *RWSWrapper) SetState(namespace string, key string, value []byte) error {
23 | return rwset.r.SetState(namespace, key, value)
24 | }
25 |
26 | func (rwset *RWSWrapper) GetState(namespace string, key string) ([]byte, error) {
27 | return rwset.r.GetState(namespace, key)
28 | }
29 |
30 | func (rwset *RWSWrapper) DeleteState(namespace string, key string) error {
31 | return rwset.r.DeleteState(namespace, key)
32 | }
33 |
34 | func (rwset *RWSWrapper) Bytes() ([]byte, error) {
35 | return rwset.r.Bytes()
36 | }
37 |
38 | func (rwset *RWSWrapper) Done() {
39 | rwset.r.Done()
40 | }
41 |
42 | func (rwset *RWSWrapper) Equals(r interface{}, namespace string) error {
43 | switch t := r.(type) {
44 | case *RWSWrapper:
45 | return rwset.r.Equals(t.r, namespace)
46 | case *fabric.RWSet:
47 | return rwset.r.Equals(t, namespace)
48 | default:
49 | return errors.Errorf("invalid type, got [%T]", t)
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/token/services/network/fabric/tcc/certifier.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package tcc
8 |
9 | import (
10 | "github.com/pkg/errors"
11 |
12 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
13 |
14 | "github.com/hyperledger-labs/fabric-token-sdk/token"
15 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/network"
16 | token2 "github.com/hyperledger-labs/fabric-token-sdk/token/token"
17 | )
18 |
19 | type GetTokenView struct {
20 | Network string
21 | Channel string
22 | Namespace string
23 | IDs []*token2.ID
24 | }
25 |
26 | func NewGetTokensView(channel string, namespace string, ids ...*token2.ID) *GetTokenView {
27 | return &GetTokenView{Channel: channel, Namespace: namespace, IDs: ids}
28 | }
29 |
30 | func (r *GetTokenView) Call(context view.Context) (interface{}, error) {
31 | if len(r.IDs) == 0 {
32 | return nil, errors.Errorf("no token ids provided")
33 | }
34 | tms := token.GetManagementService(
35 | context,
36 | token.WithNetwork(r.Network),
37 | token.WithChannel(r.Channel),
38 | token.WithNamespace(r.Namespace),
39 | )
40 | tokens, err := network.GetInstance(context, tms.Network(), tms.Channel()).QueryTokens(context.Context(), tms.Namespace(), r.IDs)
41 | if err != nil {
42 | return nil, errors.Wrapf(err, "failed querying tokens")
43 | }
44 | return tokens, nil
45 | }
46 |
--------------------------------------------------------------------------------
/token/services/network/fabric/tcc/chaincode_suite_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | package tcc_test
7 |
8 | import (
9 | "testing"
10 |
11 | . "github.com/onsi/ginkgo/v2"
12 | . "github.com/onsi/gomega"
13 | )
14 |
15 | func TestZKToken(t *testing.T) {
16 | RegisterFailHandler(Fail)
17 | RunSpecs(t, "Token Chaincode Suite")
18 | }
19 |
--------------------------------------------------------------------------------
/token/services/network/fabric/tcc/params.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 | package tcc
7 |
8 | const Params = ``
9 |
--------------------------------------------------------------------------------
/token/services/network/fabric/tcc/rwset.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package tcc
8 |
9 | import (
10 | "github.com/hyperledger/fabric-chaincode-go/shim"
11 | )
12 |
13 | type rwsWrapper struct {
14 | stub shim.ChaincodeStubInterface
15 | }
16 |
17 | func (rwset *rwsWrapper) SetState(namespace string, key string, value []byte) error {
18 | return rwset.stub.PutState(key, value)
19 | }
20 |
21 | func (rwset *rwsWrapper) GetState(namespace string, key string) ([]byte, error) {
22 | return rwset.stub.GetState(key)
23 | }
24 |
25 | func (rwset *rwsWrapper) DeleteState(namespace string, key string) error {
26 | return rwset.stub.DelState(key)
27 | }
28 |
--------------------------------------------------------------------------------
/token/services/network/fabric/tcc/shim.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package tcc
8 |
9 | import (
10 | "github.com/hyperledger/fabric-chaincode-go/shim"
11 | )
12 |
13 | //go:generate counterfeiter -o mock/chaincode_stub_interface.go -fake-name ChaincodeStubInterface . ChaincodeStubInterface
14 |
15 | // ChaincodeStubInterface is used by deployable chaincode apps to access and
16 | // modify their ledgers
17 | type ChaincodeStubInterface interface {
18 | shim.ChaincodeStubInterface
19 | }
20 |
--------------------------------------------------------------------------------
/token/services/network/orion/lm.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package orion
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-smart-client/platform/orion"
11 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
12 | )
13 |
14 | type lm struct {
15 | lm *orion.IdentityManager
16 | ip IdentityProvider
17 | }
18 |
19 | func (n *lm) DefaultIdentity() view.Identity {
20 | return n.ip.DefaultIdentity()
21 | }
22 |
23 | func (n *lm) AnonymousIdentity() (view.Identity, error) {
24 | return view.Identity(n.lm.Me()), nil
25 | }
26 |
--------------------------------------------------------------------------------
/token/services/nfttx/marshaller/marshaller.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package marshaller
8 |
9 | import "encoding/json"
10 |
11 | // Marshal marshals the given object
12 | func Marshal(v interface{}) ([]byte, error) {
13 | return json.Marshal(v)
14 | }
15 |
16 | // Unmarshal unmarshalls the given bytes into the given object
17 | func Unmarshal(data []byte, v interface{}) error {
18 | return json.Unmarshal(data, v)
19 | }
20 |
--------------------------------------------------------------------------------
/token/services/nfttx/options.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package nfttx
8 |
9 | import "github.com/hyperledger-labs/fabric-token-sdk/token"
10 |
11 | // WithUniqueID sets the unique ID of the NFT
12 | func WithUniqueID(uniqueID string) token.IssueOption {
13 | return token.WithIssueAttribute("github.com/hyperledger-labs/fabric-token-sdk/token/services/nfttx/UniqueID", uniqueID)
14 | }
15 |
--------------------------------------------------------------------------------
/token/services/nfttx/qe_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package nfttx
8 |
9 | import (
10 | "encoding/base64"
11 | "encoding/json"
12 | "testing"
13 |
14 | token2 "github.com/hyperledger-labs/fabric-token-sdk/token/token"
15 | "github.com/stretchr/testify/assert"
16 | "github.com/thedevsaddam/gojsonq"
17 | )
18 |
19 | type House struct {
20 | LinearID string
21 | Address string
22 | Valuation uint64
23 | }
24 |
25 | func TestJsonFilter(t *testing.T) {
26 | h := &House{
27 | LinearID: "hello world",
28 | Address: "5th Avenue",
29 | Valuation: 100,
30 | }
31 | raw, err := json.Marshal(h)
32 | assert.NoError(t, err, "json marshal failed")
33 | tok := &token2.UnspentToken{
34 | Type: token2.Type(base64.StdEncoding.EncodeToString(raw)),
35 | }
36 |
37 | // hit
38 | f := &jsonFilter{
39 | q: gojsonq.New(),
40 | key: "LinearID",
41 | value: "hello world",
42 | }
43 | assert.True(t, f.ContainsToken(tok))
44 |
45 | // no hit
46 | f = &jsonFilter{
47 | q: gojsonq.New(),
48 | key: "LinearID",
49 | value: "pineapple",
50 | }
51 | assert.False(t, f.ContainsToken(tok))
52 | }
53 |
--------------------------------------------------------------------------------
/token/services/nfttx/recipient.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package nfttx
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
11 | "github.com/hyperledger-labs/fabric-token-sdk/token"
12 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/ttx"
13 | )
14 |
15 | func RequestRecipientIdentity(context view.Context, recipient view.Identity, opts ...token.ServiceOption) (view.Identity, error) {
16 | return ttx.RequestRecipientIdentity(context, recipient, opts...)
17 | }
18 |
19 | func RespondRequestRecipientIdentity(context view.Context) (view.Identity, error) {
20 | return ttx.RespondRequestRecipientIdentity(context)
21 | }
22 |
--------------------------------------------------------------------------------
/token/services/nfttx/state.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package nfttx
8 |
9 | // LinearState models a state with a unique identifier that does not change through the evolution
10 | // of the state.
11 | type LinearState interface {
12 | // SetLinearID assigns the passed id to the state
13 | SetLinearID(id string) string
14 | }
15 |
16 | type AutoLinearState interface {
17 | GetLinearID() (string, error)
18 | }
19 |
--------------------------------------------------------------------------------
/token/services/nfttx/uuid.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package nfttx
8 |
9 | import (
10 | "crypto/rand"
11 | "fmt"
12 | "io"
13 | )
14 |
15 | // GenerateBytesUUID returns a UUID based on RFC 4122 returning the generated bytes
16 | // The function panics in case of an error
17 | func GenerateBytesUUID() []byte {
18 | uuid := make([]byte, 16)
19 | _, err := io.ReadFull(rand.Reader, uuid)
20 | if err != nil {
21 | panic(fmt.Sprintf("Error generating UUID: %s", err))
22 | }
23 |
24 | // variant bits; see section 4.1.1
25 | uuid[8] = uuid[8]&^0xc0 | 0x80
26 |
27 | // version 4 (pseudo-random); see section 4.1.3
28 | uuid[6] = uuid[6]&^0xf0 | 0x40
29 |
30 | return uuid
31 | }
32 |
33 | // GenerateUUID returns a UUID based on RFC 4122
34 | func GenerateUUID() string {
35 | uuid := GenerateBytesUUID()
36 | return idBytesToStr(uuid)
37 | }
38 |
39 | func idBytesToStr(id []byte) string {
40 | return fmt.Sprintf("%x-%x-%x-%x-%x", id[0:4], id[4:6], id[6:8], id[8:10], id[10:])
41 | }
42 |
--------------------------------------------------------------------------------
/token/services/nfttx/views.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package nfttx
8 |
9 | import (
10 | "time"
11 |
12 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
13 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/ttx"
14 | )
15 |
16 | func NewCollectEndorsementsView(tx *Transaction) view.View {
17 | return ttx.NewCollectEndorsementsView(tx.Transaction)
18 | }
19 |
20 | func NewOrderingAndFinalityView(tx *Transaction) view.View {
21 | return ttx.NewOrderingAndFinalityView(tx.Transaction)
22 | }
23 |
24 | func NewOrderingAndFinalityWithTimeoutView(tx *Transaction, timeout time.Duration) view.View {
25 | return ttx.NewOrderingAndFinalityWithTimeoutView(tx.Transaction, timeout)
26 | }
27 |
28 | func NewFinalityView(tx *Transaction, opts ...ttx.TxOption) view.View {
29 | return ttx.NewFinalityView(tx.Transaction, opts...)
30 | }
31 |
32 | func NewAcceptView(tx *Transaction) view.View {
33 | return ttx.NewAcceptView(tx.Transaction)
34 | }
35 |
--------------------------------------------------------------------------------
/token/services/selector/README.md:
--------------------------------------------------------------------------------
1 | # Token Selector
2 |
3 | This package contains the token selector implementations.
4 | The token selector is responsible to select tokens of a given type and for a given amount from a wallet.
5 | See more details in the [Token API documentation](../../../docs/apis/token-api.md#token-selector-manager).
6 |
7 | ## Available Implementations
8 |
9 | - Simple
10 | - Sherdlock (Default)
11 |
12 | ## Benchmarking
13 | ```go
14 | go test -v -run=XXX -bench=BenchmarkSelectorSingle . -benchmem
15 | go test -v -run=XXX -bench=BenchmarkSelectorParallel . -cpu=4,8,16,32,64,128,256,512 -benchmem
16 |
17 | go test -ginkgo.v -ginkgo.trace .
18 | ```
19 |
--------------------------------------------------------------------------------
/token/services/selector/driver/driver.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package driver
8 |
9 | import (
10 | "time"
11 | )
12 |
13 | const (
14 | Sherdlock Driver = "sherdlock"
15 | Simple Driver = "simple"
16 | )
17 |
18 | type SelectorConfig interface {
19 | GetDriver() Driver
20 | GetNumRetries() int
21 | GetRetryInterval() time.Duration
22 | GetLeaseExpiry() time.Duration
23 | GetLeaseCleanupTickPeriod() time.Duration
24 | }
25 |
26 | type Driver string
27 |
--------------------------------------------------------------------------------
/token/services/selector/sherdlock/inmemory/locker.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package inmemory
8 |
9 | import (
10 | "context"
11 | "time"
12 |
13 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/utils/types/transaction"
14 | "github.com/hyperledger-labs/fabric-token-sdk/token/token"
15 | )
16 |
17 | type Locker interface {
18 | Lock(ctx context.Context, id *token.ID, txID string, reclaim bool) (string, error)
19 | UnlockByTxID(ctx context.Context, txID string)
20 | }
21 |
22 | type Vault interface {
23 | Status(id string) (int, error)
24 | }
25 |
26 | type locker struct {
27 | Locker
28 | }
29 |
30 | func NewLocker(l Locker) *locker {
31 | return &locker{Locker: l}
32 | }
33 |
34 | func (l *locker) Lock(ctx context.Context, tokenID *token.ID, consumerTxID transaction.ID) error {
35 | _, err := l.Locker.Lock(ctx, tokenID, consumerTxID, false)
36 | return err
37 | }
38 |
39 | func (l *locker) UnlockByTxID(ctx context.Context, txID transaction.ID) error {
40 | l.Locker.UnlockByTxID(ctx, txID)
41 | return nil
42 | }
43 |
44 | func (l *locker) Cleanup(ctx context.Context, leaseExpiry time.Duration) error {
45 | return nil
46 | }
47 |
--------------------------------------------------------------------------------
/token/services/selector/sherdlock/metrics.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package sherdlock
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/tracing"
11 | "github.com/hyperledger-labs/fabric-token-sdk/token/core/common/metrics"
12 | )
13 |
14 | const (
15 | fetcherTypeLabel tracing.LabelName = "fetcher_type"
16 | lazy string = "lazy"
17 | eager string = "eager"
18 | )
19 |
20 | type Metrics struct {
21 | UnspentTokensInvocations metrics.Counter
22 | }
23 |
24 | func newMetrics(p metrics.Provider) *Metrics {
25 | return &Metrics{
26 | UnspentTokensInvocations: p.NewCounter(metrics.CounterOpts{
27 | Namespace: "sherdlock",
28 | Name: "unspent_tokens_invocations",
29 | Help: "The number of invocations",
30 | LabelNames: []string{fetcherTypeLabel},
31 | }),
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/token/services/selector/simple/inmemory/locker_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package inmemory
8 |
9 | import (
10 | "testing"
11 |
12 | "github.com/hyperledger-labs/fabric-token-sdk/token/token"
13 | "github.com/stretchr/testify/assert"
14 | )
15 |
16 | func TestLockEntry(t *testing.T) {
17 | m := map[token.ID]string{}
18 |
19 | id1 := token.ID{
20 | TxId: "a",
21 | Index: 0,
22 | }
23 | id2 := token.ID{
24 | TxId: "a",
25 | Index: 0,
26 | }
27 |
28 | m[id1] = "a"
29 | m[id2] = "b"
30 | assert.Equal(t, 1, len(m))
31 | assert.Equal(t, "b", m[id1])
32 | assert.Equal(t, "b", m[id2])
33 | }
34 |
--------------------------------------------------------------------------------
/token/services/tokendb/store_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package tokendb_test
8 |
9 | import (
10 | "testing"
11 |
12 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/core/config"
13 | sqlite2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/sql/sqlite"
14 | "github.com/hyperledger-labs/fabric-token-sdk/token"
15 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/db/sql/multiplexed"
16 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/db/sql/sqlite"
17 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/tokendb"
18 | "github.com/stretchr/testify/assert"
19 | _ "modernc.org/sqlite"
20 | )
21 |
22 | func TestDB(t *testing.T) {
23 | // create a new config service by loading the config file
24 | cp, err := config.NewProvider("./testdata/sqlite")
25 | assert.NoError(t, err)
26 | manager := tokendb.NewStoreServiceManager(cp, multiplexed.NewDriver(cp, sqlite.NewNamedDriver(cp, sqlite2.NewDbProvider())))
27 | _, err = manager.StoreServiceByTMSId(token.TMSID{Network: "pineapple"})
28 | assert.NoError(t, err)
29 | _, err = manager.StoreServiceByTMSId(token.TMSID{Network: "grapes"})
30 | assert.NoError(t, err)
31 | }
32 |
--------------------------------------------------------------------------------
/token/services/tokendb/testdata/sqlite/core.yaml:
--------------------------------------------------------------------------------
1 | fsc:
2 | persistences:
3 | token_persistence:
4 | type: sqlite
5 | opts:
6 | dataSource: file:tmp?_pragma=journal_mode(WAL)&_pragma=busy_timeout(20000)&mode=memory&cache=shared
7 | skipCreateSchema: false
8 | tablePrefix: tsdk
9 | maxOpenConns: 10
10 |
11 | token:
12 | enabled: true
13 | tms:
14 | pineapple:
15 | network: pineapple
16 | channel:
17 | namespace:
18 | tokendb:
19 | persistence: token_persistence
20 | identitydb:
21 | persistence: token_persistence
22 | grapes:
23 | network: grapes
24 | channel:
25 | namespace:
26 | tokendb:
27 | persistence: token_persistence
28 | identitydb:
29 | persistence: token_persistence
--------------------------------------------------------------------------------
/token/services/tokenlockdb/store.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package tokenlockdb
8 |
9 | import (
10 | driver2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/driver"
11 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/config"
12 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/db"
13 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/db/driver"
14 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/db/sql/multiplexed"
15 | )
16 |
17 | type StoreServiceManager db.StoreServiceManager[*StoreService]
18 |
19 | func NewStoreServiceManager(drivers multiplexed.Driver, cp driver2.ConfigService) StoreServiceManager {
20 | return db.NewStoreServiceManager(config.NewService(cp), "tokenlockdb.persistence", drivers.NewTokenLock, newStoreService)
21 | }
22 |
23 | type StoreService struct{ driver.TokenLockStore }
24 |
25 | func newStoreService(p driver.TokenLockStore) (*StoreService, error) {
26 | return &StoreService{TokenLockStore: p}, nil
27 | }
28 |
--------------------------------------------------------------------------------
/token/services/tokens/typed_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package tokens
8 |
9 | import (
10 | "testing"
11 |
12 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/tokens/driver"
13 | "github.com/stretchr/testify/assert"
14 | )
15 |
16 | func TestSerialization(t *testing.T) {
17 | raw := []byte("pineapple")
18 | wrappedToken, err := WrapWithType(0, raw)
19 | assert.NoError(t, err)
20 | tok, err := UnmarshalTypedToken(wrappedToken)
21 | assert.NoError(t, err)
22 | assert.Equal(t, driver.Type(0), tok.Type)
23 | assert.Equal(t, driver.Token(raw), tok.Token)
24 | }
25 |
--------------------------------------------------------------------------------
/token/services/ttx/logger.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package ttx
8 |
9 | import "github.com/hyperledger-labs/fabric-token-sdk/token/services/logging"
10 |
11 | var logger = logging.MustGetLogger()
12 |
--------------------------------------------------------------------------------
/token/services/ttx/multisig/finality.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package multisig
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
11 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/ttx"
12 | )
13 |
14 | func NewFinalityView(tx *Transaction, opts ...ttx.TxOption) view.View {
15 | return ttx.NewFinalityView(tx.Transaction, opts...)
16 | }
17 |
--------------------------------------------------------------------------------
/token/services/ttx/multisig/recipients.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package multisig
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
11 | "github.com/hyperledger-labs/fabric-token-sdk/token"
12 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/ttx"
13 | )
14 |
15 | // RequestRecipientIdentity requests the recipient identity for the given parties.
16 | // It returns a multisig identity. All the parties are notified about the participants in the multisig identity.
17 | func RequestRecipientIdentity(context view.Context, parties []token.Identity, opts ...token.ServiceOption) (token.Identity, error) {
18 | return ttx.RequestMultisigIdentity(context, parties, opts...)
19 | }
20 |
--------------------------------------------------------------------------------
/token/services/ttx/random.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. 2016 All Rights Reserved.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | package ttx
18 |
19 | import (
20 | "crypto/rand"
21 |
22 | "github.com/pkg/errors"
23 | )
24 |
25 | const (
26 | // NonceSize is the default NonceSize
27 | NonceSize = 24
28 | )
29 |
30 | // GetRandomBytes returns len random looking bytes
31 | func GetRandomBytes(len int) ([]byte, error) {
32 | key := make([]byte, len)
33 |
34 | // TODO: rand could fill less bytes then len
35 | _, err := rand.Read(key)
36 | if err != nil {
37 | return nil, errors.Wrap(err, "error getting random bytes")
38 | }
39 |
40 | return key, nil
41 | }
42 |
43 | // GetRandomNonce returns a random byte array of length NonceSize
44 | func GetRandomNonce() ([]byte, error) {
45 | return GetRandomBytes(NonceSize)
46 | }
47 |
--------------------------------------------------------------------------------
/token/services/ttx/status.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package ttx
8 |
9 | import "github.com/hyperledger-labs/fabric-token-sdk/token/services/db/driver"
10 |
11 | // TxStatus is the status of a transaction
12 | type TxStatus = driver.TxStatus
13 |
14 | const (
15 | // Unknown is the status of a transaction that is unknown
16 | Unknown TxStatus = driver.Unknown
17 | // Pending is the status of a transaction that has been submitted to the ledger
18 | Pending TxStatus = driver.Pending
19 | // Confirmed is the status of a transaction that has been confirmed by the ledger
20 | Confirmed TxStatus = driver.Confirmed
21 | // Deleted is the status of a transaction that has been deleted due to a failure to commit
22 | Deleted TxStatus = driver.Deleted
23 | )
24 |
25 | // TxStatusMessage maps TxStatus to string
26 | var TxStatusMessage = driver.TxStatusMessage
27 |
--------------------------------------------------------------------------------
/token/services/ttx/support.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package ttx
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/view"
11 | )
12 |
13 | // StoreTransactionRecords stores the transaction records extracted from the passed transaction to the
14 | // token transaction db
15 | func StoreTransactionRecords(context view.Context, tx *Transaction) error {
16 | return NewOwner(context, tx.TokenRequest.TokenService).Append(context.Context(), tx)
17 | }
18 |
--------------------------------------------------------------------------------
/token/services/ttxdb/testdata/sqlite/core.yaml:
--------------------------------------------------------------------------------
1 | fsc:
2 | persistences:
3 | token_persistence:
4 | type: sqlite
5 | opts:
6 | dataSource: file:tmp?_pragma=journal_mode(WAL)&_pragma=busy_timeout(20000)&mode=memory&cache=shared
7 | skipCreateSchema: false
8 | tablePrefix: tsdk
9 | maxOpenConns: 10
10 |
11 | token:
12 | enabled: true
13 | tms:
14 | pineapple:
15 | network: pineapple
16 | channel:
17 | namespace:
18 | ttxdb:
19 | persistence: token_persistence
20 | grapes:
21 | network: grapes
22 | channel:
23 | namespace:
24 | ttxdb:
25 | persistence: token_persistence
--------------------------------------------------------------------------------
/token/services/utils/closer.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package utils
8 |
9 | // IgnoreError runs a function that returns an error and silently ignores the error.
10 | // It is intended to be used when the error from a cleanup operation (e.g., Close)
11 | // is non-critical and can be safely discarded.
12 | //
13 | // Example:
14 | //
15 | // defer IgnoreError(file.Close)
16 | func IgnoreError(fn func() error) {
17 | _ = fn()
18 | }
19 |
20 | func IgnoreErrorWithOneArg[T any](fn func(t T) error, t T) {
21 | _ = fn(t)
22 | }
23 |
--------------------------------------------------------------------------------
/token/services/utils/drivers/holder.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package drivers
8 |
9 | import (
10 | "fmt"
11 | "reflect"
12 | "sync"
13 |
14 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/logging"
15 | )
16 |
17 | type Holder[K comparable, D any] struct {
18 | Logger logging.Logger
19 | driversMu sync.RWMutex
20 | Drivers map[K]D
21 | }
22 |
23 | func NewHolder[K comparable, D any]() *Holder[K, D] {
24 | return &Holder[K, D]{
25 | Logger: logging.MustGetLogger(),
26 | Drivers: make(map[K]D),
27 | }
28 | }
29 |
30 | func (h *Holder[K, D]) Get(name K) (D, bool) {
31 | d, ok := h.Drivers[name]
32 | return d, ok
33 | }
34 |
35 | // Register makes a driver available by the provided name.
36 | // If Register is called twice with the same name or if driver is nil,
37 | // it panics.
38 | func (h *Holder[K, D]) Register(name K, driver D) {
39 | h.driversMu.Lock()
40 | defer h.driversMu.Unlock()
41 | // This will fail for non nil-able inputs, but passing such services would be a programming error detected on start up
42 | if v := reflect.ValueOf(driver); v.IsNil() {
43 | panic("Register driver is nil")
44 | }
45 | if _, dup := h.Drivers[name]; dup {
46 | panic(fmt.Sprintf("Register called twice for driver %v", name))
47 | }
48 | h.Drivers[name] = driver
49 | }
50 |
--------------------------------------------------------------------------------
/token/services/utils/functions.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package utils
8 |
9 | import "reflect"
10 |
11 | func IdentityFunc[T any]() func(T) T {
12 | return func(t T) T { return t }
13 | }
14 |
15 | func IsNil[T any](value T) bool {
16 | // Use reflection to check if the value is nil
17 | v := reflect.ValueOf(value)
18 | return (v.Kind() == reflect.Ptr || v.Kind() == reflect.Slice || v.Kind() == reflect.Map || v.Kind() == reflect.Chan || v.Kind() == reflect.Func || v.Kind() == reflect.Interface) && v.IsNil()
19 | }
20 |
--------------------------------------------------------------------------------
/token/services/utils/json/decoder.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package json
8 |
9 | import (
10 | "bytes"
11 | "encoding/json"
12 | )
13 |
14 | // UnmarshalWithDisallowUnknownFields is json.Unmarshal with unknown fields disallowed.
15 | func UnmarshalWithDisallowUnknownFields(data []byte, v interface{}) error {
16 | decoder := json.NewDecoder(bytes.NewReader(data))
17 | decoder.DisallowUnknownFields()
18 | return decoder.Decode(v)
19 | }
20 |
--------------------------------------------------------------------------------
/token/services/utils/slices/slices.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package slices
8 |
9 | func GetUnique[V any](v []V) V {
10 | return v[0]
11 | }
12 |
13 | func GetAny[V any](v []V) V {
14 | return v[0]
15 | }
16 |
17 | func GetFirst[V any](v []V) V {
18 | return v[0]
19 | }
20 |
21 | func GenericSliceOfPointers[T any](size int) []*T {
22 | slice := make([]*T, size)
23 | for i := range slice {
24 | var zero T
25 | slice[i] = &zero
26 | }
27 | return slice
28 | }
29 |
--------------------------------------------------------------------------------
/token/services/utils/types/transaction/types.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package transaction
8 |
9 | type (
10 | // ID models the transaction identifier's type
11 | ID = string
12 | )
13 |
--------------------------------------------------------------------------------
/token/services/walletdb/store.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package walletdb
8 |
9 | import (
10 | driver2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/driver"
11 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/config"
12 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/db"
13 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/db/driver"
14 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/db/sql/multiplexed"
15 | )
16 |
17 | type StoreServiceManager db.StoreServiceManager[*StoreService]
18 |
19 | func NewStoreServiceManager(cp driver2.ConfigService, drivers multiplexed.Driver) StoreServiceManager {
20 | return db.NewStoreServiceManager(config.NewService(cp), "identitydb.persistence", drivers.NewWallet, newStoreService)
21 | }
22 |
23 | // StoreService is a database that stores wallet related information
24 | type StoreService struct {
25 | driver.WalletStore
26 | }
27 |
28 | func newStoreService(p driver.WalletStore) (*StoreService, error) {
29 | return &StoreService{WalletStore: p}, nil
30 | }
31 |
--------------------------------------------------------------------------------
/token/services/walletdb/store_test.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package walletdb_test
8 |
9 | import (
10 | "testing"
11 |
12 | "github.com/hyperledger-labs/fabric-smart-client/platform/view/core/config"
13 | sqlite2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/db/driver/sql/sqlite"
14 | "github.com/hyperledger-labs/fabric-token-sdk/token"
15 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/db/sql/multiplexed"
16 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/db/sql/sqlite"
17 | "github.com/hyperledger-labs/fabric-token-sdk/token/services/walletdb"
18 | "github.com/stretchr/testify/assert"
19 | _ "modernc.org/sqlite"
20 | )
21 |
22 | func TestDB(t *testing.T) {
23 | // create a new config service by loading the config file
24 | cp, err := config.NewProvider("./testdata/sqlite")
25 | assert.NoError(t, err)
26 | manager := walletdb.NewStoreServiceManager(cp, multiplexed.NewDriver(cp, sqlite.NewNamedDriver(cp, sqlite2.NewDbProvider())))
27 | _, err = manager.StoreServiceByTMSId(token.TMSID{Network: "pineapple"})
28 | assert.NoError(t, err)
29 | _, err = manager.StoreServiceByTMSId(token.TMSID{Network: "grapes"})
30 | assert.NoError(t, err)
31 | }
32 |
--------------------------------------------------------------------------------
/token/services/walletdb/testdata/sqlite/core.yaml:
--------------------------------------------------------------------------------
1 | fsc:
2 | persistences:
3 | token_persistence:
4 | type: sqlite
5 | opts:
6 | dataSource: file:tmp?_pragma=journal_mode(WAL)&_pragma=busy_timeout(20000)&mode=memory&cache=shared
7 | skipCreateSchema: false
8 | tablePrefix: tsdk
9 | maxOpenConns: 10
10 |
11 | token:
12 | enabled: true
13 | tms:
14 | pineapple:
15 | network: pineapple
16 | channel:
17 | namespace:
18 | identitydb:
19 | persistence: token_persistence
20 | grapes:
21 | network: grapes
22 | channel:
23 | namespace:
24 | identitydb:
25 | persistence: token_persistence
--------------------------------------------------------------------------------
/token/tokens.go:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright IBM Corp. All Rights Reserved.
3 |
4 | SPDX-License-Identifier: Apache-2.0
5 | */
6 |
7 | package token
8 |
9 | import (
10 | "github.com/hyperledger-labs/fabric-token-sdk/token/driver"
11 | "github.com/hyperledger-labs/fabric-token-sdk/token/token"
12 | )
13 |
14 | // TokensService models the token service
15 | type TokensService struct {
16 | ts driver.TokensService
17 | tus driver.TokensUpgradeService
18 | }
19 |
20 | // Deobfuscate processes the passed output and metadata to derive a token.Token, its issuer (if any), and its token format
21 | func (t *TokensService) Deobfuscate(output []byte, outputMetadata []byte) (*token.Token, Identity, []Identity, token.Format, error) {
22 | return t.ts.Deobfuscate(output, outputMetadata)
23 | }
24 |
25 | // NewUpgradeChallenge generates a new upgrade challenge
26 | func (t *TokensService) NewUpgradeChallenge() ([]byte, error) {
27 | return t.tus.NewUpgradeChallenge()
28 | }
29 |
30 | // GenUpgradeProof generates an upgrade proof for the given challenge and tokens
31 | func (t *TokensService) GenUpgradeProof(id []byte, tokens []token.LedgerToken) ([]byte, error) {
32 | return t.tus.GenUpgradeProof(id, tokens, nil)
33 | }
34 |
35 | // SupportedTokenFormats returns the supported token formats
36 | func (t *TokensService) SupportedTokenFormats() []token.Format {
37 | return t.ts.SupportedTokenFormats()
38 | }
39 |
--------------------------------------------------------------------------------
/tools/go.mod:
--------------------------------------------------------------------------------
1 | module tools
2 |
3 | go 1.24.1
4 |
5 | require (
6 | github.com/client9/misspell v0.3.4
7 | github.com/fzipp/gocyclo v0.6.0
8 | github.com/google/addlicense v1.1.1
9 | github.com/gordonklaus/ineffassign v0.1.0
10 | github.com/maxbrunsfeld/counterfeiter/v6 v6.11.2
11 | github.com/onsi/ginkgo/v2 v2.23.4
12 | golang.org/x/tools v0.32.0
13 | google.golang.org/protobuf v1.36.6
14 | honnef.co/go/tools v0.6.1
15 | )
16 |
17 | require (
18 | github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c // indirect
19 | github.com/bmatcuk/doublestar/v4 v4.8.1 // indirect
20 | github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
21 | github.com/google/pprof v0.0.0-20250403155104-27863c87afa6 // indirect
22 | github.com/stretchr/testify v1.9.0 // indirect
23 | go.uber.org/automaxprocs v1.6.0 // indirect
24 | golang.org/x/exp/typeparams v0.0.0-20240823005443-9b4947da3948 // indirect
25 | golang.org/x/mod v0.24.0 // indirect
26 | golang.org/x/sync v0.13.0 // indirect
27 | golang.org/x/text v0.24.0 // indirect
28 | )
29 |
--------------------------------------------------------------------------------
/tools/tools.go:
--------------------------------------------------------------------------------
1 | //go:build tools
2 |
3 | /*
4 | Copyright IBM Corp. All Rights Reserved.
5 |
6 | SPDX-License-Identifier: Apache-2.0
7 | */
8 |
9 | package tools
10 |
11 | import (
12 | _ "github.com/client9/misspell/cmd/misspell"
13 | _ "github.com/fzipp/gocyclo/cmd/gocyclo"
14 | _ "github.com/google/addlicense"
15 | _ "github.com/gordonklaus/ineffassign"
16 | _ "github.com/maxbrunsfeld/counterfeiter/v6"
17 | _ "github.com/onsi/ginkgo/v2/ginkgo"
18 | _ "golang.org/x/tools/cmd/goimports"
19 | _ "google.golang.org/protobuf/cmd/protoc-gen-go"
20 | _ "honnef.co/go/tools/cmd/staticcheck"
21 | )
22 |
--------------------------------------------------------------------------------