Bidirectional Connections
Bidirectional Connections API is used to query fields of bidirectional connections between a given address and another address or a list of other addresses (50 max).
You can find the step by step instructions on how to set up GraphQL client in your application and write a simple Get Bidirectional Connection query in the Read Connections section.
Structure
The general pattern of Bidirectional Connection
query is:
biConnections(fromAddr String!, toAddrList [String!]!, network Network) [BidirectionalConnection!]!
Field | Type | Description | Required/Optional |
---|---|---|---|
fromAddr | String! | The source address that you want to query bidirectional connections about | Required |
toAddrList | [String!]! | A string list of addresses that you want to check if they have bidirectional connections with fromAddr | Required |
network | Network | The blockchain network of the address you are querying about | Optional. Default value is ETH . |
With correct inputs, you will get a list of BidirectionalConnection
objects, consisting of the following fields:
Field | Type | Description |
---|---|---|
fromAddr | String | The source address that you want to query bidirectional connections about |
toAddr | String | An address that is given in toAddrList |
state | BiConnState | The bidirectional connection state between fromAddr and toAddr . |
direction | Direction | The direction of bidirectional connection state. |
namespace | String | The namespace of this connection |
network | Network | The network that is given as the querying parameter |
createdAt | String | The creation time of this connection |
updatedAt | String | The latest update time of this connection |
latestHash | String | The proof hash of this connection. Please see Proof of Connection for detail design and implementation |
latestEvent | ConnectionEvent | The latest event of this connection including the proof. Please see Proof of Connection for detail design and implementation. |
latestAnchorEvent | ConnectionEvent | The latest event of this connection which can be found on Arweave |
For followStatus
, there will be two boolean variables: isFollowed
and isFollowing
.
For state
, there will be four enum values: EMPTY
、PENDING
、CONNECTD
and BLACKLIST
. Our protocol defines a state machine to show relationship among these states and different bidirectional connection:
You also need direction
to determine final state between fromAddr
and toAddr
, there will be three enum values: BIDIRECTION
、FROM_TO
and TO_FROM
.
If state is EMPTY
, the direction should be BIDIRECTION
, it means the initial state between fromAddr
and toAddr
.
if state is PENDING
, the direction can either be FROM_TO
or TO_FROM
, it means the direction of request sent from fromAddr
to toAddr
or from toAddr
to fromAddr
.
If state is CONNECTED
, the direction should be BIDIRECTION
, it means the bidirectional connection has been connected for both fromAddr
and toAddr
.
If state is BLACKLIST
, the direction can either be BIDIRECTION
, FROM_TO
or TO_FROM
, it means mutually block or the direction of block.
Examples
Fetch Proof Example
This is an example of a query to fetch proof
data that you can also test out in the Playground:
- Query
- Response
query ProofQuery {
bidirectionalConnections(
fromAddr: "0xd45D6496DC32AA91E069C1D7870C5363bC5c8Fbd"
toAddrList: ["0xC76fbE40144ac56822C651B6e02497D4A576F23d"]
network: ETH
) {
from
to
latestEvent {
...event
}
latestAnchorEvent {
...event
}
}
}
fragment event on BiConnEvent {
hash
parentHash
fromAddr
toAddr
network
namespace
createdAt
isAnchor
proof {
content
digest
signature
signingKey
signingKeyAuth {
message
signature
address
}
arweaveTxHash
}
instruction
}
{
"data": {
"bidirectionalConnections": [
{
"from": "0xd45d6496dc32aa91e069c1d7870c5363bc5c8fbd",
"to": "0xc76fbe40144ac56822c651b6e02497d4a576f23d",
"latestEvent": {
"hash": "0xb01af668596a4299eada36a82d6598a28880902aadbd146cba6cd511e28927dc",
"parentHash": "0xf082a91e1af31a3d7cf0fad006b96a7a7c8347612789197ea585225e3baa15c1",
"fromAddr": "0xc76fbe40144ac56822c651b6e02497d4a576f23d",
"toAddr": "0xd45d6496dc32aa91e069c1d7870c5363bc5c8fbd",
"network": "ETH",
"namespace": "CyberConnect",
"createdAt": "2022-06-10T17:56:45Z",
"isAnchor": true,
"proof": {
"content": "{\"name\":\"ACCEPT\",\"from\":\"0xc76fbe40144ac56822c651b6e02497d4a576f23d\",\"to\":\"0xd45D6496DC32AA91E069C1D7870C5363bC5c8Fbd\",\"namespace\":\"CyberConnect\",\"network\":\"ETH\",\"timestamp\":1654883805555}",
"digest": "0x9f1c215b4d1d50906385d379b2bfc5a6d08f385264e151092d53bbccc81f75a5",
"signature": "0x17835e2173aa10d1870fc9f4780d0b9a0afc84594687d0a8e4d862df22509de01426923fc062db3c991210b380a865e40b6b22b3692b5397a0318268755eeff8",
"signingKey": "SubjectPublicKeyInfo:MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEzMJQc/4ZrUlJME3gACoSffOCH+UNrpegzJ+U2HbtddLHR0QYiaFS+p45I9nHNJ6OM416F8I4viQJfSnb3ljBdQ==",
"signingKeyAuth": {
"message": "I authorize CyberConnect from this device using signing key:\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEzMJQc/4ZrUlJME3gACoSffOCH+UNrpegzJ+U2HbtddLHR0QYiaFS+p45I9nHNJ6OM416F8I4viQJfSnb3ljBdQ==",
"signature": "0xcdae12e5acd0ad05b8a3456820266b4a7e5ff5f23da83f6e46062392b68971ab5f4e3d853058ea84ea0faa816b19b0d9d1b3035b10ab4814b1570574a966f3b51c",
"address": "0xc76fbe40144ac56822c651b6e02497d4a576f23d"
},
"arweaveTxHash": "Z5HPm7q7BjMLNE407U7dKPFvukJizkWqRipAb5j2kG8"
},
"instruction": "ACCEPT"
},
"latestAnchorEvent": {
"hash": "0xb01af668596a4299eada36a82d6598a28880902aadbd146cba6cd511e28927dc",
"parentHash": "0xf082a91e1af31a3d7cf0fad006b96a7a7c8347612789197ea585225e3baa15c1",
"fromAddr": "0xc76fbe40144ac56822c651b6e02497d4a576f23d",
"toAddr": "0xd45d6496dc32aa91e069c1d7870c5363bc5c8fbd",
"network": "ETH",
"namespace": "CyberConnect",
"createdAt": "2022-06-10T17:56:45Z",
"isAnchor": true,
"proof": {
"content": "{\"name\":\"ACCEPT\",\"from\":\"0xc76fbe40144ac56822c651b6e02497d4a576f23d\",\"to\":\"0xd45D6496DC32AA91E069C1D7870C5363bC5c8Fbd\",\"namespace\":\"CyberConnect\",\"network\":\"ETH\",\"timestamp\":1654883805555}",
"digest": "0x9f1c215b4d1d50906385d379b2bfc5a6d08f385264e151092d53bbccc81f75a5",
"signature": "0x17835e2173aa10d1870fc9f4780d0b9a0afc84594687d0a8e4d862df22509de01426923fc062db3c991210b380a865e40b6b22b3692b5397a0318268755eeff8",
"signingKey": "SubjectPublicKeyInfo:MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEzMJQc/4ZrUlJME3gACoSffOCH+UNrpegzJ+U2HbtddLHR0QYiaFS+p45I9nHNJ6OM416F8I4viQJfSnb3ljBdQ==",
"signingKeyAuth": {
"message": "I authorize CyberConnect from this device using signing key:\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEzMJQc/4ZrUlJME3gACoSffOCH+UNrpegzJ+U2HbtddLHR0QYiaFS+p45I9nHNJ6OM416F8I4viQJfSnb3ljBdQ==",
"signature": "0xcdae12e5acd0ad05b8a3456820266b4a7e5ff5f23da83f6e46062392b68971ab5f4e3d853058ea84ea0faa816b19b0d9d1b3035b10ab4814b1570574a966f3b51c",
"address": "0xc76fbe40144ac56822c651b6e02497d4a576f23d"
},
"arweaveTxHash": "Z5HPm7q7BjMLNE407U7dKPFvukJizkWqRipAb5j2kG8"
},
"instruction": "ACCEPT"
}
}
]
}
}
Fetch State Example
This is an example of a query to fetch the state
and direction
that you can also test out in the Playground:
- Query
- Response
query StateQuery {
bidirectionalConnections(
fromAddr: "0xd45D6496DC32AA91E069C1D7870C5363bC5c8Fbd",
toAddrList:["0xc76fbe40144ac56822c651b6e02497d4a576f23d"],
network: ETH) {
from
to
state
direction
}
}
{
"data": {
"bidirectionalConnections": [
{
"from": "0xd45d6496dc32aa91e069c1d7870c5363bc5c8fbd",
"to": "0xc76fbe40144ac56822c651b6e02497d4a576f23d",
"state": "CONNECTED",
"direction": "BIDIRECTION"
}
]
}
}
Full Example
This is a full example for the Bidirectional Connections query that you can also test out in the Playground
With arweaveTxHash
you can query it on Arweave to proof the connection.
- Query
- Response
query BidirectionalConnectionsQuery {
bidirectionalConnections(
fromAddr: "0xd45D6496DC32AA91E069C1D7870C5363bC5c8Fbd",
toAddrList:["0xC76fbE40144ac56822C651B6e02497D4A576F23d"],
network: ETH) {
from
to
network
state
direction
namespace
updatedAt
latestEvent {
...event
}
latestAnchorEvent {
...event
}
}
}
fragment event on BiConnEvent {
hash
parentHash
fromAddr
toAddr
network
namespace
createdAt
isAnchor
proof {
content
digest
signature
signingKey
signingKeyAuth {
address
message
signature
}
arweaveTxHash
}
instruction
}
{
"data": {
"bidirectionalConnections": [
{
"from": "0xd45d6496dc32aa91e069c1d7870c5363bc5c8fbd",
"to": "0xc76fbe40144ac56822c651b6e02497d4a576f23d",
"network": "ETH",
"state": "CONNECTED",
"direction": "BIDIRECTION",
"namespace": "CyberConnect",
"updatedAt": "2022-06-10T17:56:45Z",
"latestEvent": {
"hash": "0xb01af668596a4299eada36a82d6598a28880902aadbd146cba6cd511e28927dc",
"parentHash": "0xf082a91e1af31a3d7cf0fad006b96a7a7c8347612789197ea585225e3baa15c1",
"fromAddr": "0xc76fbe40144ac56822c651b6e02497d4a576f23d",
"toAddr": "0xd45d6496dc32aa91e069c1d7870c5363bc5c8fbd",
"network": "ETH",
"namespace": "CyberConnect",
"createdAt": "2022-06-10T17:56:45Z",
"isAnchor": true,
"instruction": "ACCEPT",
"proof": {
"content": "{\"name\":\"ACCEPT\",\"from\":\"0xc76fbe40144ac56822c651b6e02497d4a576f23d\",\"to\":\"0xd45D6496DC32AA91E069C1D7870C5363bC5c8Fbd\",\"namespace\":\"CyberConnect\",\"network\":\"ETH\",\"timestamp\":1654883805555}",
"digest": "0x9f1c215b4d1d50906385d379b2bfc5a6d08f385264e151092d53bbccc81f75a5",
"signature": "0x17835e2173aa10d1870fc9f4780d0b9a0afc84594687d0a8e4d862df22509de01426923fc062db3c991210b380a865e40b6b22b3692b5397a0318268755eeff8",
"signingKey": "SubjectPublicKeyInfo:MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEzMJQc/4ZrUlJME3gACoSffOCH+UNrpegzJ+U2HbtddLHR0QYiaFS+p45I9nHNJ6OM416F8I4viQJfSnb3ljBdQ==",
"signingKeyAuth": {
"message": "I authorize CyberConnect from this device using signing key:\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEzMJQc/4ZrUlJME3gACoSffOCH+UNrpegzJ+U2HbtddLHR0QYiaFS+p45I9nHNJ6OM416F8I4viQJfSnb3ljBdQ==",
"signature": "0xcdae12e5acd0ad05b8a3456820266b4a7e5ff5f23da83f6e46062392b68971ab5f4e3d853058ea84ea0faa816b19b0d9d1b3035b10ab4814b1570574a966f3b51c",
"address": "0xc76fbe40144ac56822c651b6e02497d4a576f23d"
},
"arweaveTxHash": "Z5HPm7q7BjMLNE407U7dKPFvukJizkWqRipAb5j2kG8"
}
},
"latestAnchorEvent": {
"hash": "0xb01af668596a4299eada36a82d6598a28880902aadbd146cba6cd511e28927dc",
"parentHash": "0xf082a91e1af31a3d7cf0fad006b96a7a7c8347612789197ea585225e3baa15c1",
"fromAddr": "0xc76fbe40144ac56822c651b6e02497d4a576f23d",
"toAddr": "0xd45d6496dc32aa91e069c1d7870c5363bc5c8fbd",
"network": "ETH",
"namespace": "CyberConnect",
"createdAt": "2022-06-10T17:56:45Z",
"isAnchor": true,
"instruction": "ACCEPT",
"proof": {
"content": "{\"name\":\"ACCEPT\",\"from\":\"0xc76fbe40144ac56822c651b6e02497d4a576f23d\",\"to\":\"0xd45D6496DC32AA91E069C1D7870C5363bC5c8Fbd\",\"namespace\":\"CyberConnect\",\"network\":\"ETH\",\"timestamp\":1654883805555}",
"digest": "0x9f1c215b4d1d50906385d379b2bfc5a6d08f385264e151092d53bbccc81f75a5",
"signature": "0x17835e2173aa10d1870fc9f4780d0b9a0afc84594687d0a8e4d862df22509de01426923fc062db3c991210b380a865e40b6b22b3692b5397a0318268755eeff8",
"signingKey": "SubjectPublicKeyInfo:MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEzMJQc/4ZrUlJME3gACoSffOCH+UNrpegzJ+U2HbtddLHR0QYiaFS+p45I9nHNJ6OM416F8I4viQJfSnb3ljBdQ==",
"signingKeyAuth": {
"message": "I authorize CyberConnect from this device using signing key:\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEzMJQc/4ZrUlJME3gACoSffOCH+UNrpegzJ+U2HbtddLHR0QYiaFS+p45I9nHNJ6OM416F8I4viQJfSnb3ljBdQ==",
"signature": "0xcdae12e5acd0ad05b8a3456820266b4a7e5ff5f23da83f6e46062392b68971ab5f4e3d853058ea84ea0faa816b19b0d9d1b3035b10ab4814b1570574a966f3b51c",
"address": "0xc76fbe40144ac56822c651b6e02497d4a576f23d"
},
"arweaveTxHash": "Z5HPm7q7BjMLNE407U7dKPFvukJizkWqRipAb5j2kG8"
}
}
}
]
}
}