mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-05-25 00:06:44 +00:00
75 lines
1.8 KiB
Go
75 lines
1.8 KiB
Go
package sample
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
|
|
machinetypes "planetmint-go/x/machine/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
|
|
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
)
|
|
|
|
// KeyPair returns a sample private / public keypair
|
|
func KeyPair() (string, string) {
|
|
secret := "Don't tell anybody"
|
|
sk := secp256k1.GenPrivKeyFromSecret([]byte(secret))
|
|
pk := sk.PubKey()
|
|
return hex.EncodeToString(sk.Bytes()), hex.EncodeToString(pk.Bytes())
|
|
}
|
|
|
|
// AccAddress returns a sample account address
|
|
func AccAddress() string {
|
|
pk := ed25519.GenPrivKey().PubKey()
|
|
addr := pk.Address()
|
|
return sdk.AccAddress(addr).String()
|
|
}
|
|
|
|
func Machine(machineId string, pkPM string, pkL string) machinetypes.Machine {
|
|
m := machinetypes.Machine{
|
|
Name: "machine",
|
|
Ticker: "PM",
|
|
Issued: 1,
|
|
Amount: 1000,
|
|
Precision: 8,
|
|
IssuerPlanetmint: pkPM,
|
|
IssuerLiquid: pkL,
|
|
MachineId: machineId,
|
|
}
|
|
return m
|
|
}
|
|
|
|
func MachineIndex(machineId string, pkPM string, pkL string) machinetypes.MachineIndex {
|
|
return machinetypes.MachineIndex{
|
|
MachineId: machineId,
|
|
IssuerPlanetmint: pkPM,
|
|
IssuerLiquid: pkL,
|
|
}
|
|
}
|
|
|
|
func Metadata() machinetypes.Metadata {
|
|
return machinetypes.Metadata{
|
|
Gps: "{\"Latitude\":\"-48.876667\",\"Longitude\":\"-123.393333\"}",
|
|
Device: "{\"Manufacturer\": \"RDDL\",\"Serial\":\"AdnT2uyt\"}",
|
|
AssetDefinition: "{\"Version\": \"0.1\"}",
|
|
AdditionalDataCID: "CID",
|
|
}
|
|
}
|
|
|
|
func Asset(sk string) (string, string) {
|
|
cid := "cid"
|
|
|
|
skBytes, _ := hex.DecodeString(sk)
|
|
privKey := &secp256k1.PrivKey{Key: skBytes}
|
|
|
|
cidBytes, _ := hex.DecodeString(cid)
|
|
hash := sha256.Sum256(cidBytes)
|
|
|
|
sign, _ := privKey.Sign(hash[:])
|
|
|
|
signatureHex := hex.EncodeToString(sign)
|
|
|
|
return cid, signatureHex
|
|
}
|