diff --git a/src/chia-dotnet/ChiaTypes/VCRecord.cs b/src/chia-dotnet/ChiaTypes/VCRecord.cs index e0fef31e..75867335 100644 --- a/src/chia-dotnet/ChiaTypes/VCRecord.cs +++ b/src/chia-dotnet/ChiaTypes/VCRecord.cs @@ -2,6 +2,7 @@ { public record VCRecord { + public string? CoinId { get; init; } public VerifiedCredential VC { get; init; } = new(); public uint ConfirmedAtHeight { get; init; } } diff --git a/src/chia-dotnet/VerifiedCredentialManager.cs b/src/chia-dotnet/VerifiedCredentialManager.cs new file mode 100644 index 00000000..b84d70a5 --- /dev/null +++ b/src/chia-dotnet/VerifiedCredentialManager.cs @@ -0,0 +1,140 @@ +using System; +using System.Collections.Generic; +using System.Dynamic; +using System.Threading; +using System.Threading.Tasks; + +namespace chia.dotnet +{ + /// + /// API wrapper for those wallet RPC methods dealing with verified credentials + /// + public sealed class VerifiedCredentialManager + { + public WalletProxy WalletProxy { get; init; } + + public VerifiedCredentialManager(WalletProxy walletProxy) + { + WalletProxy = walletProxy ?? throw new ArgumentNullException(nameof(walletProxy)); + } + + /// + /// Given a launcher ID get the verified credential. + /// + /// + /// A token to allow the call to be cancelled + /// + public async Task Get(string vcId, CancellationToken cancellationToken = default) + { + dynamic data = new ExpandoObject(); + data.vc_id = vcId; + return await WalletProxy.SendMessage("vc_get", data, "vc_record", cancellationToken).ConfigureAwait(false); + } + + /// + /// Get a list of verified credentials in the specified range and any 'proofs' associated with the roots contained within. + /// + /// + /// + /// A token to allow the call to be cancelled + /// + public async Task GetList(uint start = 0, uint end = 50, CancellationToken cancellationToken = default) + { + dynamic data = new ExpandoObject(); + data.start = start; + data.end = end; + return await WalletProxy.SendMessage("vc_get_list", data, "vc_records", cancellationToken).ConfigureAwait(false); + } + + /// + /// Mint a verified credential using the assigned DID. + /// + /// + /// + /// + /// A token to allow the call to be cancelled + /// + public async Task<(VCRecord VCRecord, IEnumerable Transactions)> Mint(string targetAddress, string didId, ulong fee = 0, CancellationToken cancellationToken = default) + { + dynamic data = new ExpandoObject(); + data.did_id = didId; + data.target_address = targetAddress; + data.fee = fee; + var resposne = await WalletProxy.SendMessage("vc_mint", data, cancellationToken).ConfigureAwait(false); + + return (Converters.ToObject(resposne.vc_record), Converters.ToEnumerable(resposne.transactions)); + } + + /// + /// Spend a verified credential. + /// + /// + /// + /// + /// + /// + /// + /// A token to allow the call to be cancelled + /// A list of + public async Task> Spend(string vcId, + string? newPuzhash = null, + string? providerInnerPuzhash = null, + string? newProofHash = null, + bool reusePuzhash = false, + ulong fee = 0, + CancellationToken cancellationToken = default) + { + dynamic data = new ExpandoObject(); + data.vc_id = vcId; + data.new_puzhash = newPuzhash; + data.new_proof_hash = newProofHash; + data.provider_inner_puzhash = providerInnerPuzhash; + data.fee = fee; + data.reuse_puzhash = reusePuzhash; + return await WalletProxy.SendMessage>("vc_spend", data, "transactions", cancellationToken).ConfigureAwait(false); + } + + /// + /// Add a set of proofs to the DB that can be used when spending a VC. VCs are near useless until their proofs have been added. + /// + /// + /// A token to allow the call to be cancelled + /// + public async Task AddProofs(VCProofs proofs, CancellationToken cancellationToken = default) + { + dynamic data = new ExpandoObject(); + data.proofs = proofs; + await WalletProxy.SendMessage("vc_add_proofs", data, cancellationToken).ConfigureAwait(false); + } + + /// + /// Given a specified vc root, get any proofs associated with that root. + /// + /// + /// A token to allow the call to be cancelled + /// + public async Task> GetProofsForRoot(string root, CancellationToken cancellationToken = default) + { + dynamic data = new ExpandoObject(); + data.root = root; + return await WalletProxy.SendMessage>("vc_get_proofs_for_root", data, "proofs", cancellationToken).ConfigureAwait(false); + } + + /// + /// Revoke an on chain VC provided the correct DID is available. + /// + /// + /// + /// + /// A token to allow the call to be cancelled + /// A list of + public async Task> Revoke(string vcParentId, bool reusePuzhash = false, ulong fee = 0, CancellationToken cancellationToken = default) + { + dynamic data = new ExpandoObject(); + data.vc_parent_id = vcParentId; + data.fee = fee; + data.reuse_puzhash = reusePuzhash; + return await WalletProxy.SendMessage>("vc_revoke", data, "transactions", cancellationToken).ConfigureAwait(false); + } + } +} diff --git a/src/docfx/images/uml.svg b/src/docfx/images/uml.svg index 5c7c810d..2104bfa0 100644 --- a/src/docfx/images/uml.svg +++ b/src/docfx/images/uml.svg @@ -1,2 +1,2 @@ -ExtendsExtendsExtendsExtendsExtendsExtendsExtendsExtendsExtendsExtendsExtendsExtendsServiceProxy -ServiceProxy<<Interface>>IRpcClient<<Interface>>...UseUseWebSocketRpcClientWebSocketRpcClientHttpRpcClientHttpRpcClientCrawlerProxyCrawlerProxyExtendsExtendsDaemonProxyDaemonProxyHarvesterProxyHarvesterProxyFarmerProxyFarmerProxyFullNodeProxyFullNodeProxyWalletProxyWalletProxyExtendsExtendsExtendsExtendsTradeManagerTradeManagerUseUseWalletWalletID = uint32Wallet...CATWalletCATWalletExtendsExtendsPoolWalletPoolWalletUseUseExtendsExtendsDIDWalletDIDWalletExtendsExtendsPlotterProxyPlotterProxyRateLimitedWalletRateLimitedWalletNFTWalletNFTWalletViewer does not support full SVG 1.1 \ No newline at end of file +ExtendsExtendsExtendsExtendsExtendsExtendsExtendsExtendsExtendsExtendsExtendsExtendsExtendsExtendsServiceProxy +ServiceProxy<<Interface>>IRpcClient<<Interface>>...UseUseWebSocketRpcClientWebSocketRpcClientHttpRpcClientHttpRpcClientCrawlerProxyCrawlerProxyExtendsExtendsDaemonProxyDaemonProxyHarvesterProxyHarvesterProxyFarmerProxyFarmerProxyFullNodeProxyFullNodeProxyWalletProxyWalletProxyExtendsExtendsExtendsExtendsTradeManagerTradeManagerUseUseWalletWalletID = uint32Wallet...CATWalletCATWalletExtendsExtendsPoolWalletPoolWalletUseUseExtendsExtendsDIDWalletDIDWalletExtendsExtendsPlotterProxyPlotterProxyNFTWalletNFTWalletDataLayerProxyDataLayerProxyDataLayerWalletDataLayerWalletVerifiedCredentialManagerVerifiedCredentialManagerUseUseText is not SVG - cannot display \ No newline at end of file diff --git a/uml.drawio b/uml.drawio index 6f7923c1..de4dcddc 100644 --- a/uml.drawio +++ b/uml.drawio @@ -1,10 +1,16 @@ - + - + + + + + + + @@ -12,8 +18,8 @@ - - + + @@ -44,7 +50,7 @@ - + @@ -54,33 +60,33 @@ - - + + - - + + - + - + - + - + @@ -119,7 +125,7 @@ - + @@ -128,19 +134,19 @@ - + - + - - + + - + @@ -150,28 +156,40 @@ - - + + - + - - + + - + - + + + + + + + + + + + + +
ServiceProxy
<<Interface>>IRpcClient
CrawlerProxy
DaemonProxy
HarvesterProxy
FarmerProxy
FullNodeProxy
WalletProxy
TradeManager
Wallet
WalletID = uint32
CATWallet
PoolWallet
DIDWallet
PlotterProxy
RateLimitedWallet
NFTWallet
DataLayerProxy
DataLayerWallet
VerifiedCredentialManager