Documentation
¶
Overview ¶
Example (B) ¶
package main
import (
"fmt"
cert "github.com/aviate-labs/agent-go/certificate"
)
func main() {
fmt.Printf("%X", cert.Leaf("good").Reconstruct())
}
Output: 7B32AC0C6BA8CE35AC82C255FC7906F7FC130DAB2A090F80FE12F9C2CAE83BA6
Example (C) ¶
package main
import (
"fmt"
cert "github.com/aviate-labs/agent-go/certificate"
)
func main() {
fmt.Printf("%X", cert.Labeled{
Label: []byte("c"),
Tree: cert.Empty{},
}.Reconstruct())
}
Output: EC8324B8A1F1AC16BD2E806EDBA78006479C9877FED4EB464A25485465AF601D
Example (Root) ¶
package main
import (
"fmt"
cert "github.com/aviate-labs/agent-go/certificate"
)
var tree = cert.Fork{
LeftTree: cert.Fork{
LeftTree: cert.Labeled{
Label: []byte("a"),
Tree: cert.Fork{
LeftTree: cert.Fork{
LeftTree: cert.Labeled{
Label: []byte("x"),
Tree: cert.Leaf("hello"),
},
RightTree: cert.Empty{},
},
RightTree: cert.Labeled{
Label: []byte("y"),
Tree: cert.Leaf("world"),
},
},
},
RightTree: cert.Labeled{
Label: []byte("b"),
Tree: cert.Leaf("good"),
},
},
RightTree: cert.Fork{
LeftTree: cert.Labeled{
Label: []byte("c"),
Tree: cert.Empty{},
},
RightTree: cert.Labeled{
Label: []byte("d"),
Tree: cert.Leaf("morning"),
},
},
}
func main() {
fmt.Printf("%X", tree.Reconstruct())
}
Output: EB5C5B2195E62D996B84C9BCC8259D19A83786A2F59E0878CEC84C811F669AA0
Example (X) ¶
Source: https://sdk.dfinity.org/docs/interface-spec/index.html#_example ─┬─┬╴"a" ─┬─┬╴"x" ─╴"hello"
│ │ │ └╴Empty │ │ └╴ "y" ─╴"world" │ └╴"b" ──╴"good" └─┬╴"c" ──╴Empty └╴"d" ──╴"morning"
package main
import (
"fmt"
cert "github.com/aviate-labs/agent-go/certificate"
)
func main() {
fmt.Printf("%X", cert.Fork{
LeftTree: cert.Labeled{
Label: []byte("x"),
Tree: cert.Leaf("hello"),
},
RightTree: cert.Empty{},
}.Reconstruct())
}
Output: 1B4FEFF9BEF8131788B0C9DC6DBAD6E81E524249C879E9F10F71CE3749F5A638
Index ¶
- Constants
- func DomainSeparator(t string) []byte
- func Lookup(path [][]byte, node Node) []byte
- func LookupPath(p ...string) [][]byte
- func Serialize(node Node) ([]byte, error)
- type Cert
- type Certificate
- type Delegation
- type Empty
- type Fork
- type HashTree
- type Label
- type Labeled
- type Leaf
- type Node
- type Pruned
Examples ¶
Constants ¶
View Source
const DerPrefix = "308182301d060d2b0601040182dc7c0503010201060c2b0601040182dc7c05030201036100"
DerPrefix is the DER prefix of IC main net.
View Source
const RootKey = "" /* 266-byte string literal not displayed */
RootKey is the root key of IC main net.
Variables ¶
This section is empty.
Functions ¶
func DomainSeparator ¶ added in v0.3.0
func Lookup ¶
Lookup looks up the given path in the certificate tree.
Example ¶
fmt.Println(string(certificate.Lookup(certificate.LookupPath("a", "x"), tree)))
fmt.Println(string(certificate.Lookup(certificate.LookupPath("a", "y"), tree)))
fmt.Println(string(certificate.Lookup(certificate.LookupPath("b"), tree)))
fmt.Println(string(certificate.Lookup(certificate.LookupPath("d"), tree)))
Output: hello world good morning
func LookupPath ¶
LookupPath returns a path from the given labels.
func Serialize ¶
Example ¶
package main
import (
"fmt"
cert "github.com/aviate-labs/agent-go/certificate"
)
var tree = cert.Fork{
LeftTree: cert.Fork{
LeftTree: cert.Labeled{
Label: []byte("a"),
Tree: cert.Fork{
LeftTree: cert.Fork{
LeftTree: cert.Labeled{
Label: []byte("x"),
Tree: cert.Leaf("hello"),
},
RightTree: cert.Empty{},
},
RightTree: cert.Labeled{
Label: []byte("y"),
Tree: cert.Leaf("world"),
},
},
},
RightTree: cert.Labeled{
Label: []byte("b"),
Tree: cert.Leaf("good"),
},
},
RightTree: cert.Fork{
LeftTree: cert.Labeled{
Label: []byte("c"),
Tree: cert.Empty{},
},
RightTree: cert.Labeled{
Label: []byte("d"),
Tree: cert.Leaf("morning"),
},
},
}
func main() {
b, _ := cert.Serialize(tree)
fmt.Printf("%x", b)
}
Output: 8301830183024161830183018302417882034568656c6c6f810083024179820345776f726c6483024162820344676f6f648301830241638100830241648203476d6f726e696e67
Types ¶
type Cert ¶
type Cert struct {
// Tree is the certificate tree.
Tree HashTree `cbor:"tree"`
// Signature is the signature of the certificate tree.
Signature []byte `cbor:"signature"`
// Delegation is the delegation of the certificate.
Delegation *Delegation `cbor:"delegation"`
}
Cert is a certificate gets returned by the IC.
type Certificate ¶
Certificate is a certificate gets returned by the IC and can be used to verify the state root based on the root key and canister ID.
type Delegation ¶
type Delegation struct {
// SubnetId is the subnet ID of the delegation.
SubnetId principal.Principal `cbor:"subnet_id"`
// The nested certificate typically does not itself again contain a
// delegation, although there is no reason why agents should enforce that
// property.
Certificate Certificate `cbor:"certificate"`
}
Delegation is a delegation of a certificate.
func (*Delegation) UnmarshalCBOR ¶
func (d *Delegation) UnmarshalCBOR(bytes []byte) error
UnmarshalCBOR unmarshals a delegation.
type Fork ¶
func (Fork) Reconstruct ¶
type HashTree ¶
type HashTree struct {
Root Node
}
HashTree is a hash tree.
func (HashTree) MarshalCBOR ¶
MarshalCBOR marshals a hash tree.
func (*HashTree) UnmarshalCBOR ¶
UnmarshalCBOR unmarshals a hash tree.
type Labeled ¶
func (Labeled) Reconstruct ¶
type Node ¶
func Deserialize ¶
Example ¶
package main
import (
"encoding/hex"
"fmt"
cert "github.com/aviate-labs/agent-go/certificate"
)
func main() {
data, _ := hex.DecodeString("8301830183024161830183018302417882034568656c6c6f810083024179820345776f726c6483024162820344676f6f648301830241638100830241648203476d6f726e696e67")
fmt.Println(cert.Deserialize(data))
}
Output: {{a:{{x:hello|∅}|y:world}|b:good}|{c:∅|d:morning}} <nil>
func DeserializeNode ¶
func LookupNode ¶ added in v0.3.1
type Pruned ¶
type Pruned [32]byte
Example ¶
package main
import (
"encoding/hex"
"fmt"
cert "github.com/aviate-labs/agent-go/certificate"
)
var pruned = cert.Fork{
LeftTree: cert.Fork{
LeftTree: cert.Labeled{
Label: []byte("a"),
Tree: cert.Fork{
LeftTree: cert.Pruned(h2b("1B4FEFF9BEF8131788B0C9DC6DBAD6E81E524249C879E9F10F71CE3749F5A638")),
RightTree: cert.Labeled{
Label: []byte("y"),
Tree: cert.Leaf("world"),
},
},
},
RightTree: cert.Labeled{
Label: []byte("b"),
Tree: cert.Pruned(h2b("7B32AC0C6BA8CE35AC82C255FC7906F7FC130DAB2A090F80FE12F9C2CAE83BA6")),
},
},
RightTree: cert.Fork{
LeftTree: cert.Pruned(h2b("EC8324B8A1F1AC16BD2E806EDBA78006479C9877FED4EB464A25485465AF601D")),
RightTree: cert.Labeled{
Label: []byte("d"),
Tree: cert.Leaf("morning"),
},
},
}
func main() {
fmt.Printf("%X", pruned.Reconstruct())
}
func h2b(s string) [32]byte {
var bs [32]byte
b, _ := hex.DecodeString(s)
copy(bs[:], b)
return bs
}
Output: EB5C5B2195E62D996B84C9BCC8259D19A83786A2F59E0878CEC84C811F669AA0
func (Pruned) Reconstruct ¶
Click to show internal directories.
Click to hide internal directories.