-
Notifications
You must be signed in to change notification settings - Fork 1
/
orbitdb.go
58 lines (51 loc) · 1.58 KB
/
orbitdb.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"encoding/hex"
"fmt"
"log"
"orbitdb/go-orbitdb/identities/identitytypes"
"orbitdb/go-orbitdb/oplog"
)
func main() {
// Define the same entry data as in JavaScript
entry := oplog.Entry{
ID: "test-log-id",
Payload: "hello world",
Next: []string{},
Refs: []string{},
Clock: oplog.Clock{ID: "test-user-id", Time: 0},
V: 2,
Key: "test-public-key",
Identity: "test-identity-hash",
Signature: "test-signature",
}
// Encode the entry using your Encode function
encodedEntry := oplog.Encode(entry)
fmt.Println("CID in Go:", encodedEntry.CID)
// Output the bytes in hex format for easy comparison
fmt.Println("CBOR Encoded Bytes in Go:", hex.EncodeToString(encodedEntry.Bytes))
// Define the test identity details
id := "0x01234567890abcdefghijklmnopqrstuvwxyz"
publicKey := "<pubkey>"
signatures := map[string]string{
"id": "signature for <id>",
"publicKey": "signature for <publicKey + idSignature>",
}
idType := "orbitdb"
// Create an Identity struct without a PrivateKey
testIdentity := identitytypes.Identity{
ID: id,
PublicKey: publicKey,
Signatures: signatures,
Type: idType,
}
// Encode the identity to get the CBOR-encoded bytes and CID hash
hash, encodedBytes, err := identitytypes.EncodeIdentity(testIdentity)
if err != nil {
log.Fatalf("Error encoding identity: %v", err)
}
// Display the encoded values
fmt.Printf("Encoded Hash: %s\n", hash)
fmt.Printf("Encoded Bytes (CBOR): %x\n", encodedBytes)
// expected hash: 'zdpuArx43BnXdDff5rjrGLYrxUomxNroc2uaocTgcWK76UfQT'
}