private void StackPanel_Tapped(object sender, TappedRoutedEventArgs e) { if (ResultListViewControl.SelectedItem is Did did) { if (did.Quantity > did.DidSpare.Count) { Did = did; SelectedTarget.Text = $"Selected: {Did.Id}"; SelectedTarget.Visibility = Visibility.Visible; } else { Did = null; SelectedTarget.Text = $"The tapped despatch instruction detail has been assembled completely. Please choose another one."; SelectedTarget.Visibility = Visibility.Visible; } } }
public async Task TestSignAndSubmitRequestWorksForNotFoundSigner() { var signerDidJson = "{\"seed\":\"00000000000000000000UnknowSigner\"}"; var trusteeDidResult = await Did.CreateAndStoreMyDidAsync(wallet, signerDidJson); var signerDid = trusteeDidResult.Did; var myDidResult = await Did.CreateAndStoreMyDidAsync(wallet, "{}"); var myDid = myDidResult.Did; var nymRequest = await Ledger.BuildNymRequestAsync(signerDid, myDid, null, null, null); var ex = await Assert.ThrowsExceptionAsync <InvalidLedgerTransactionException>(() => Ledger.SignAndSubmitRequestAsync(pool, wallet, signerDid, nymRequest) ); }
public async Task UnpackToCustomType() { var message = new ConnectionInvitationMessage() { ConnectionKey = "123" }; var my = await Did.CreateAndStoreMyDidAsync(_wallet, "{}"); var anotherMy = await Did.CreateAndStoreMyDidAsync(_wallet, "{}"); var packed = await CryptoUtils.PackAsync(_wallet, anotherMy.VerKey, null, message); var unpack = await CryptoUtils.UnpackAsync <ConnectionInvitationMessage>(_wallet, packed); Assert.NotNull(unpack); Assert.Equal("123", unpack.ConnectionKey); }
/// <inheritdoc /> public virtual async Task <string> ProcessResponseAsync(IAgentContext agentContext, ConnectionResponseMessage response, ConnectionRecord connection) { Logger.LogInformation(LoggingEvents.AcceptConnectionResponse, "To {1}", connection.MyDid); //TODO throw exception or a problem report if the connection request features a did doc that has no indy agent did doc convention featured //i.e there is no way for this agent to respond to messages. And or no keys specified var connectionObj = await SignatureUtils.UnpackAndVerifyAsync <Connection>(response.ConnectionSig); try { await Did.StoreTheirDidAsync(agentContext.Wallet, new { did = connectionObj.Did, verkey = connectionObj.DidDoc.Keys[0].PublicKeyBase58 }.ToJson()); } catch (WalletItemAlreadyExistsException e) { Logger.LogError(e, "Unable to store their DID. Record already exists", connectionObj.Did, connectionObj.DidDoc?.Keys.FirstOrDefault()?.PublicKeyBase58 ?? "Verkey not found"); } connection.TheirDid = connectionObj.Did; connection.TheirVk = connectionObj.DidDoc.Keys[0].PublicKeyBase58; connection.SetTag(TagConstants.LastThreadId, response.GetThreadId()); if (connectionObj.DidDoc.Services[0] is IndyAgentDidDocService service) { connection.Endpoint = new AgentEndpoint(service.ServiceEndpoint, null, service.RoutingKeys != null && service.RoutingKeys.Count > 0 ? service.RoutingKeys.ToArray() : null); } await connection.TriggerAsync(ConnectionTrigger.Response); await RecordService.UpdateAsync(agentContext.Wallet, connection); EventAggregator.Publish(new ServiceMessageProcessingEvent { RecordId = connection.Id, MessageType = response.Type, ThreadId = response.GetThreadId() }); return(connection.Id); }
public async Task TestSignAndSubmitRequestWorksForNotFoundSigner() { var signerDidJson = "{\"seed\":\"00000000000000000000UnknowSigner\"}"; var trusteeDidResult = await Did.CreateAndStoreMyDidAsync(wallet, signerDidJson); var signerDid = trusteeDidResult.Did; var myDidResult = await Did.CreateAndStoreMyDidAsync(wallet, "{}"); var myDid = myDidResult.Did; var nymRequest = await Ledger.BuildNymRequestAsync(signerDid, myDid, null, null, null); var response = await Ledger.SignAndSubmitRequestAsync(pool, wallet, signerDid, nymRequest); CheckResponseType(response, "REQNACK"); }
public async Task AnonPrepareMessageNoRoutingAsync() { var message = new ConnectionInvitationMessage { RecipientKeys = new[] { "123" } }; var recipient = await Did.CreateAndStoreMyDidAsync(_wallet, "{}"); var encrypted = await _messagingService.PrepareAsync(_wallet, message, recipient.VerKey); var unpackRes = await CryptoUtils.UnpackAsync(_wallet, encrypted); var unpackMsg = JsonConvert.DeserializeObject <ConnectionInvitationMessage>(unpackRes.Message); Assert.NotNull(unpackMsg); Assert.True(string.IsNullOrEmpty(unpackRes.SenderVerkey)); Assert.True(unpackRes.RecipientVerkey == recipient.VerKey); Assert.Equal("123", unpackMsg.RecipientKeys[0]); }
public async Task PackAndUnpackAnon() { var message = new ConnectionInvitationMessage { RecipientKeys = new[] { "123" } }; var my = await Did.CreateAndStoreMyDidAsync(_wallet, "{}"); var anotherMy = await Did.CreateAndStoreMyDidAsync(_wallet, "{}"); var packed = await CryptoUtils.PackAsync(_wallet, anotherMy.VerKey, message, null); var unpack = await CryptoUtils.UnpackAsync(_wallet, packed); Assert.NotNull(unpack); Assert.Null(unpack.SenderVerkey); Assert.NotNull(unpack.RecipientVerkey); Assert.Equal(unpack.RecipientVerkey, anotherMy.VerKey); }
public async Task TestAuthDecryptWorksForInvalidMessage() { var result = await Did.CreateAndStoreMyDidAsync(wallet, "{}"); var recipientDid = result.Did; var myVk = result.VerKey; var identityJson = string.Format(IDENTITY_JSON_TEMPLATE, recipientDid, myVk); await Did.StoreTheirDidAsync(wallet, identityJson); var msgString = "[" + string.Join(",", ENCRYPTED_MESSAGE) + "]"; var msg = string.Format("{{\"auth\":true,\"nonсe\":\"Th7MpTaRZVRYnPiabds81Y12\",\"sender\":\"{0}\",\"msg\":{1}}}", VERKEY, msgString); var ex = await Assert.ThrowsExceptionAsync <InvalidStructureException>(() => Crypto.AuthDecryptAsync(wallet, myVk, Encoding.UTF8.GetBytes(msg)) ); }
/// <summary> /// Create a single wallet and enable payments /// </summary> /// <returns></returns> public async Task InitializeAsync() { Host = new HostBuilder() .ConfigureServices(services => { services.Configure <ConsoleLifetimeOptions>(options => options.SuppressStatusMessages = true); services.AddAriesFramework(builder => builder .RegisterAgent(options => { options.WalletConfiguration = new WalletConfiguration { Id = Guid.NewGuid().ToString() }; options.WalletCredentials = new WalletCredentials { Key = "test" }; options.GenesisFilename = Path.GetFullPath("pool_genesis.txn"); options.PoolName = GetPoolName(); options.EndpointUri = "http://test"; options.IssuerKeySeed = GetIssuerSeed(); }) .AddSovrinToken()); }) .Build(); await Host.StartAsync(); await Pool.SetProtocolVersionAsync(2); Context = await Host.Services.GetService <IAgentProvider>().GetContextAsync(); Trustee = await Did.CreateAndStoreMyDidAsync(Context.Wallet, new { seed = "000000000000000000000000Trustee1" }.ToJson()); Trustee2 = await PromoteTrustee("000000000000000000000000Trustee2"); Trustee3 = await PromoteTrustee("000000000000000000000000Trustee3"); provisioningService = Host.Services.GetService <IProvisioningService>(); recordService = Host.Services.GetService <IWalletRecordService>(); paymentService = Host.Services.GetService <IPaymentService>(); }
/// <inheritdoc /> public async Task <string> ProcessRequestAsync(Wallet wallet, ConnectionRequestMessage request) { Logger.LogInformation(LoggingEvents.StoreConnectionRequest, "Key {0}", request.Key); var(didOrKey, _) = MessageUtils.ParseMessageType(request.Type); var connectionSearch = await RecordService.SearchAsync <ConnectionRecord>(wallet, new SearchRecordQuery { { TagConstants.ConnectionKey, didOrKey } }, null, 1); var connection = connectionSearch.Single(); var(their, theirKey) = await MessageSerializer.UnpackSealedAsync <ConnectionDetails>(request.Content, wallet, request.Key); if (!their.Verkey.Equals(theirKey)) { throw new ArgumentException("Signed and enclosed keys don't match"); } await connection.TriggerAsync(ConnectionTrigger.InvitationAccept); var my = await Did.CreateAndStoreMyDidAsync(wallet, "{}"); await Did.StoreTheirDidAsync(wallet, new { did = their.Did, verkey = their.Verkey }.ToJson()); connection.Endpoint = their.Endpoint; connection.TheirDid = their.Did; connection.TheirVk = their.Verkey; connection.MyDid = my.Did; connection.MyVk = my.VerKey; connection.Tags[TagConstants.MyDid] = my.Did; connection.Tags[TagConstants.TheirDid] = their.Did; await RecordService.UpdateAsync(wallet, connection); if (connection.Tags.Any(_ => _.Key == TagConstants.AutoAcceptConnection && _.Value == "true")) { await AcceptRequestAsync(wallet, connection.ConnectionId); } return(connection.GetId()); }
/// <inheritdoc /> public async Task <List <long> > ListBackupsAsync(IAgentContext context) { var publicKey = await Did.KeyForLocalDidAsync(context.Wallet, InternalBackupDid); var listBackupsMessage = new ListBackupsAgentMessage() { BackupId = publicKey, }; var connection = await GetMediatorConnectionAsync(context).ConfigureAwait(false); if (connection == null) { throw new AriesFrameworkException(ErrorCode.RecordNotFound, "Couldn't locate a connection to mediator agent"); } var response = await messageService.SendReceiveAsync <ListBackupsResponseAgentMessage>(context.Wallet, listBackupsMessage, connection).ConfigureAwait(false); return(response.BackupList.ToList()); }
public async Task RestoreAgentFromBackup() { var seed = "00000000000000000000000000000000"; var path = SetupDirectoriesAndReturnPath(seed); var myDid = await Did.CreateAndStoreMyDidAsync(EdgeContext.Wallet, "{}"); await EdgeClient.CreateBackupAsync(EdgeContext, seed); // Create a DID that we will retrieve and compare from imported wallet var attachments = await EdgeClient.RetrieveBackupAsync(EdgeContext, seed); await EdgeClient.RestoreFromBackupAsync(EdgeContext, seed, attachments); var newWallet = await WalletService.GetWalletAsync(AgentOptions.WalletConfiguration, AgentOptions.WalletCredentials); var myKey = await Did.KeyForLocalDidAsync(newWallet, myDid.Did); Assert.Equal(myKey, myDid.VerKey); }
public async Task TestGetValidatorInfoRequestWorks() { var didJson = JsonConvert.SerializeObject(new { seed = TRUSTEE_SEED }); var result = await Did.CreateAndStoreMyDidAsync(wallet, didJson); var did = result.Did; var getValidatorInfoRequest = await Ledger.BuildGetValidatorInfoRequestAsync(did); var getValidatorInfoResponse = await Ledger.SignAndSubmitRequestAsync(pool, wallet, did, getValidatorInfoRequest); var getValidatorInfoObj = JObject.Parse(getValidatorInfoResponse); for (int i = 1; i <= 4; i++) { var nodeName = string.Format("Node{0}", i); var nodeObject = JObject.Parse(getValidatorInfoObj[nodeName].ToString()); Assert.IsFalse(nodeObject["result"]["data"] == null); } }
public async Task TestSendNodeRequestWorksForNewSteward() { var trusteeDidResult = await Did.CreateAndStoreMyDidAsync(wallet, TRUSTEE_IDENTITY_JSON); var trusteeDid = trusteeDidResult.Did; var myDidResult = await Did.CreateAndStoreMyDidAsync(wallet, "{}"); var myDid = myDidResult.Did; var myVerkey = myDidResult.VerKey; var nymRequest = await Ledger.BuildNymRequestAsync(trusteeDid, myDid, myVerkey, null, "STEWARD"); await Ledger.SignAndSubmitRequestAsync(pool, wallet, trusteeDid, nymRequest); var nodeRequest = await Ledger.BuildNodeRequestAsync(myDid, _dest, _data); await Ledger.SignAndSubmitRequestAsync(pool, wallet, myDid, nodeRequest); }
public async Task TestSendNodeRequestWorksForWrongRole() { var didResult = await Did.CreateAndStoreMyDidAsync(wallet, TRUSTEE_IDENTITY_JSON); var did = didResult.Did; var data = "{\"node_ip\":\"10.0.0.100\"," + "\"node_port\":910," + "\"client_ip\":\"10.0.0.100\"," + "\"client_port\":911," + "\"alias\":\"some\"," + "\"services\":[\"VALIDATOR\"]," + "\"blskey\":\"CnEDk9HrMnmiHXEV1WFgbVCRteYnPqsJwrTdcZaNhFVW\"}"; var nodeRequest = await Ledger.BuildNodeRequestAsync(did, did, data); var ex = await Assert.ThrowsExceptionAsync <InvalidLedgerTransactionException>(() => Ledger.SignAndSubmitRequestAsync(pool, wallet, did, nodeRequest) ); }
async Task <Msg> SendToCloudAgent(string type, IMessage request) { var endpoint = await Did.GetEndpointForDidAsync(wallet, pool, myPublicDid); var cloudAgentVk = await Did.KeyForDidAsync(pool, wallet, myPublicDid); var msg = new Msg { Content = request.ToByteString(), Origin = myDid, Type = type }; using (var client = new HttpClient()) { var payload = await Crypto.AuthCryptAsync(wallet, myVk, cloudAgentVk, msg.ToByteArray()); var content = new ByteArrayContent(payload); content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); var req = new HttpRequestMessage(); req.RequestUri = new Uri($"http://{endpoint.Address}/api"); req.Method = HttpMethod.Post; req.Content = content; var response = await client.SendAsync(req); var responseData = await response.Content.ReadAsByteArrayAsync(); if (responseData.Any()) { var decrypted = await Crypto.AuthDecryptAsync(wallet, myVk, responseData); var responseMsg = new Msg(); responseMsg.MergeFrom(decrypted.MessageData); return(responseMsg); } return(null); } }
public async Task SendAsync(string did, Msg message, IdentityContext context) { var endpoint = await Did.GetEndpointForDidAsync(context.Wallet, context.Pool, did); var theirKey = await Did.KeyForDidAsync(context.Pool, context.Wallet, did); var encrypted = await Crypto.AnonCryptAsync(theirKey, message.ToByteArray()); var request = new HttpRequestMessage { RequestUri = new Uri($"http://{endpoint.Address}/"), Method = HttpMethod.Post, Content = new ByteArrayContent(encrypted) }; request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); var response = await httpClient.SendAsync(request); response.EnsureSuccessStatusCode(); }
public async Task TestNymRequestsWorks() { var trusteeDidResult = await Did.CreateAndStoreMyDidAsync(wallet, TRUSTEE_IDENTITY_JSON); var trusteeDid = trusteeDidResult.Did; var myDidResult = await Did.CreateAndStoreMyDidAsync(wallet, "{}"); var myDid = myDidResult.Did; var myVerKey = myDidResult.VerKey; var nymRequest = await Ledger.BuildNymRequestAsync(trusteeDid, myDid, myVerKey, null, null); await Ledger.SignAndSubmitRequestAsync(pool, wallet, trusteeDid, nymRequest); var getNymRequest = await Ledger.BuildGetNymRequestAsync(myDid, myDid); var getNymResponse = PoolUtils.EnsurePreviousRequestAppliedAsync(pool, getNymRequest, response => { return(CompareResponseType(response, "REPLY")); }); Assert.IsNotNull(getNymResponse); }
public async Task TestBuildSchemaRequestWorksWithoutSignature() { var didResult = await Did.CreateAndStoreMyDidAsync(wallet, TRUSTEE_IDENTITY_JSON); var did = didResult.Did; var schemaRequest = await Ledger.BuildSchemaRequestAsync(did, SCHEMA_DATA); var submitRequestResponse = await Ledger.SubmitRequestAsync(pool, schemaRequest); /* SubmitRequestAsync will return error response as follows * { * "reason":"client request invalid: MissingSignature()", * "op":"REQNACK", * "reqId":1536945730478714000, * "identifier":"V4SGRU86Z58d6TV7PBUe6f" * } */ Assert.IsTrue(submitRequestResponse.Contains("\"op\":\"REQNACK\"")); Assert.IsTrue(submitRequestResponse.Contains("MissingSignature()")); }
internal static StatisticData GetStatisticSchemaData(Did DatabaseId) { if (!File.Exists(String.Format("{0}{1}.dat", _storageDirectory, DatabaseId.Duid))) { return(null); } StatisticData statisticData = null; using ( Stream stream = File.Open( String.Format("{0}{1}.dat", Settings.GetInstance().ServerStatisticDataStorageDirectory, DatabaseId.Duid), FileMode.Open)) { BinaryFormatter bFormatter = new BinaryFormatter(); statisticData = (StatisticData)bFormatter.Deserialize(stream); stream.Close(); } return(statisticData); }
public async Task SendOfferAsyncThrowsExceptionUnableToSendA2AMessage() { var(issuerConnection, _) = await Scenarios.EstablishConnectionAsync( _connectionService, _messages, _issuerWallet, _holderWallet); var issuer = await Did.CreateAndStoreMyDidAsync(_issuerWallet.Wallet, new { seed = "000000000000000000000000Steward1" }.ToJson()); (var credId, _) = await Scenarios.CreateDummySchemaAndNonRevokableCredDef(_issuerWallet, _schemaService, issuer.Did, new[] { "dummy_attr" }); _routeMessage = false; var ex = await Assert.ThrowsAsync <AgentFrameworkException>(async() => await _credentialService.SendOfferAsync(_issuerWallet, issuerConnection.Id, new OfferConfiguration { CredentialDefinitionId = credId })); _routeMessage = true; Assert.True(ex.ErrorCode == ErrorCode.A2AMessageTransmissionError); }
public async Task RejectOfferAsyncThrowsExceptionCredentialOfferInvalidState() { //Establish a connection between the two parties var(issuerConnection, holderConnection) = await Scenarios.EstablishConnectionAsync( _connectionService, _messages, _issuerWallet, _holderWallet); // Create an issuer DID/VK. Can also be created during provisioning var issuer = await Did.CreateAndStoreMyDidAsync(_issuerWallet.Wallet, new { seed = TestConstants.StewartDid }.ToJson()); // Create a schema and credential definition for this issuer var(definitionId, _) = await Scenarios.CreateDummySchemaAndNonRevokableCredDef(_issuerWallet, _schemaService, issuer.Did, new[] { "dummy_attr" }); var offerConfig = new OfferConfiguration { IssuerDid = issuer.Did, CredentialDefinitionId = definitionId }; // Send an offer to the holder using the established connection channel var(offer, _) = await _credentialService.CreateOfferAsync(_issuerWallet, offerConfig, issuerConnection.Id); _messages.Add(offer); // Holder retrieves message from their cloud agent var credentialOffer = FindContentMessage <CredentialOfferMessage>(_messages); // Holder processes the credential offer by storing it var holderCredentialId = await _credentialService.ProcessOfferAsync(_holderWallet, credentialOffer, holderConnection); //Reject the offer await _credentialService.RejectOfferAsync(_holderWallet, holderCredentialId); //Try reject the offer again var ex = await Assert.ThrowsAsync <AgentFrameworkException>(async() => await _credentialService.RejectOfferAsync(_holderWallet, holderCredentialId)); Assert.True(ex.ErrorCode == ErrorCode.RecordInInvalidState); }
public async Task TestGetTxnRequestWorksForInvalidSeqNo() { var didResult = await Did.CreateAndStoreMyDidAsync(wallet, TRUSTEE_IDENTITY_JSON); var did = didResult.Did; var schemaRequest = await Ledger.BuildSchemaRequestAsync(did, SCHEMA_DATA); var schemaResponse = await Ledger.SignAndSubmitRequestAsync(pool, wallet, did, schemaRequest); var schemaResponseObj = JObject.Parse(schemaResponse); var seqNo = (int)schemaResponseObj["result"]["seqNo"] + 1; var getTxnRequest = await Ledger.BuildGetTxnRequestAsync(did, seqNo); var getTxnResponse = await Ledger.SubmitRequestAsync(pool, getTxnRequest); var getTxnResponseObj = JObject.Parse(getTxnResponse); Assert.IsFalse(getTxnResponseObj["result"]["data"].HasValues); }
[TestMethod] //Name of this test is bad. public async Task TestSchemaRequestWorks() { var didResult = await Did.CreateAndStoreMyDidAsync(wallet, TRUSTEE_IDENTITY_JSON); var did = didResult.Did; var schemaData = "{\"name\":\"gvt2\",\"version\":\"2.0\",\"attr_names\": [\"name\", \"male\"]}"; var schemaRequest = await Ledger.BuildSchemaRequestAsync(did, schemaData); await Ledger.SignAndSubmitRequestAsync(pool, wallet, did, schemaRequest); var getSchemaData = "{\"name\":\"gvt2\",\"version\":\"2.0\"}"; var getSchemaRequest = await Ledger.BuildGetSchemaRequestAsync(did, did, getSchemaData); var getSchemaResponse = await Ledger.SubmitRequestAsync(pool, getSchemaRequest); var getSchemaResponseObject = JObject.Parse(getSchemaResponse); Assert.AreEqual("gvt2", (string)getSchemaResponseObject["result"]["data"]["name"]); Assert.AreEqual("2.0", (string)getSchemaResponseObject["result"]["data"]["version"]); }
public override int GetHashCode() { int hash = 1; if (Did.Length != 0) { hash ^= Did.GetHashCode(); } if (Verkey.Length != 0) { hash ^= Verkey.GetHashCode(); } if (RequestNonce.Length != 0) { hash ^= RequestNonce.GetHashCode(); } if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public async Task TestSignAndSubmitRequestWorksForIncompatibleWalletAndPool() { var walletName = "incompatibleWallet"; await Wallet.CreateWalletAsync("otherPoolName", walletName, "default", null, null); var wallet = await Wallet.OpenWalletAsync(walletName, null, null); var trusteeDidResult = await Did.CreateAndStoreMyDidAsync(wallet, TRUSTEE_IDENTITY_JSON); var trusteeDid = trusteeDidResult.Did; var myDidResult = await Did.CreateAndStoreMyDidAsync(wallet, "{}"); var myDid = myDidResult.Did; var nymRequest = await Ledger.BuildNymRequestAsync(trusteeDid, myDid, null, null, null); var ex = await Assert.ThrowsExceptionAsync <WrongWalletForPoolException>(() => Ledger.SignAndSubmitRequestAsync(pool, wallet, trusteeDid, nymRequest) ); }
/// <inheritdoc /> public async Task <ConnectionRecord> ProcessInvitationAsync(IAgentContext agentContext, ConnectionInvitationMessage invitation) { var my = await Did.CreateAndStoreMyDidAsync(agentContext.Wallet, "{}"); var connection = new ConnectionRecord { Endpoint = new AgentEndpoint(invitation.ServiceEndpoint, null, invitation.RoutingKeys != null && invitation.RoutingKeys.Count != 0 ? invitation.RoutingKeys.ToArray() : null), MyDid = my.Did, MyVk = my.VerKey, Role = ConnectionRole.Invitee }; connection.SetTag("InvitationKey", invitation.RecipientKeys.First()); if (!string.IsNullOrEmpty(invitation.Label) || !string.IsNullOrEmpty(invitation.ImageUrl)) { connection.Alias = new ConnectionAlias { Name = invitation.Label, ImageUrl = invitation.ImageUrl }; if (string.IsNullOrEmpty(invitation.Label)) { connection.SetTag(TagConstants.Alias, invitation.Label); } } await RecordService.AddAsync(agentContext.Wallet, connection); EventAggregator.Publish(new ServiceMessageProcessingEvent { MessageType = invitation.Type, RecordId = connection.Id, ThreadId = invitation.GetThreadId() }); return(connection); }
public async Task TestSignWorks() { var msg = "{\n" + " \"reqId\":1496822211362017764,\n" + " \"identifier\":\"GJ1SzoWzavQYfNL9XkaJdrQejfztN4XqdsiV4ct3LXKL\",\n" + " \"operation\":{\n" + " \"type\":\"1\",\n" + " \"dest\":\"VsKV7grR1BUE29mG2Fm2kX\",\n" + " \"verkey\":\"GjZWsBLgZCR18aL468JAT7w9CZRiBnpxUPPgyQxh4voa\"\n" + " }\n" + " }"; var expectedSignature = "\"signature\":\"65hzs4nsdQsTUqLCLy2qisbKLfwYKZSWoyh1C6CU59p5pfG3EHQXGAsjW4Qw4QdwkrvjSgQuyv8qyABcXRBznFKW\""; var result = await Did.CreateAndStoreMyDidAsync(wallet, TRUSTEE_IDENTITY_JSON); var did = result.Did; var signedMessage = await Ledger.SignRequestAsync(wallet, did, msg); Assert.IsTrue(signedMessage.Contains(expectedSignature)); }
public async Task PackAndUnpackAuth() { var message = new ConnectionInvitationMessage { RecipientKeys = new[] { "123" } }.ToByteArray(); var my = await Did.CreateAndStoreMyDidAsync(_wallet, "{}"); var anotherMy = await Did.CreateAndStoreMyDidAsync(_wallet, "{}"); var packed = await CryptoUtils.PackAsync(_wallet, anotherMy.VerKey, message, my.VerKey); var unpack = await CryptoUtils.UnpackAsync(_wallet, packed); var jObject = JObject.Parse(unpack.Message); Assert.NotNull(unpack); Assert.NotNull(unpack.SenderVerkey); Assert.NotNull(unpack.RecipientVerkey); Assert.Equal(unpack.RecipientVerkey, anotherMy.VerKey); Assert.Equal(unpack.SenderVerkey, my.VerKey); Assert.Equal(MessageTypes.ConnectionInvitation, jObject["@type"].ToObject <string>()); }
public IStorable Deserialize(Did dbId, SerializedStorable serializedStorable) { var storable = new Storable(); storable.Oid = serializedStorable.Oid; int streamLength = serializedStorable.Data.Length; int position = 0; while (position < streamLength) { var id = BitConverter.ToInt64(serializedStorable.Data, position); var length = BitConverter.ToInt32(serializedStorable.Data, position + _longSize); var data = new byte[length]; Buffer.BlockCopy(serializedStorable.Data, position + _longSize + _intSize, data, 0, length); position += _longSize + _intSize + length; var property = _metadata.Databases[dbId].Schema.Properties.Single(p => p.Key.Id == id).Value; storable.Properties.Add(property, DeserializeValueType(property, data)); } return(storable); }