bundlr

package
v0.1.205 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 25, 2023 License: MIT Imports: 31 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// Setting this flag disables retrying request with peers
	ContextDisablePeers = value("disablePeers")

	// Forces the URL of the peer, otherwise the default one is picked
	ContextForcePeer = value("forcePeer")
)
View Source
const ARWEAVE_OWNER_LENGTH = 512
View Source
const ARWEAVE_SIGNATURE_LENGHT = 512

Arweave signature

Variables

View Source
var (
	ErrFailedToParse = errors.New("failed to parse response")
	ErrIdEmpty       = errors.New("bundle id is empty")
)
View Source
var CONFIG = map[int]struct {
	Signature int
	Owner     int
	Verify    func(hash []byte, self *BundleItem) error
}{
	1: {
		Signature: 512,
		Owner:     512,
		Verify: func(hash []byte, self *BundleItem) error {
			ownerPublicKey := &rsa.PublicKey{
				N: new(big.Int).SetBytes([]byte(self.Owner)),
				E: 65537,
			}

			return rsa.VerifyPSS(ownerPublicKey, crypto.SHA256, hash, []byte(self.Signature), &rsa.PSSOptions{
				SaltLength: rsa.PSSSaltLengthAuto,
				Hash:       crypto.SHA256,
			})
		},
	},
	3: {
		Signature: 65,
		Owner:     65,
		Verify: func(hash []byte, self *BundleItem) (err error) {

			publicKeyECDSA, err := etherum_crypto.UnmarshalPubkey(self.Owner)
			if err != nil {
				err = errors.New("can not unmarshal etherum pubkey")
				return
			}
			publicKeyBytes := etherum_crypto.FromECDSAPub(publicKeyECDSA)

			sigPublicKey, err := etherum_crypto.Ecrecover(hash, self.Signature)
			if err != nil {
				return
			}

			if !bytes.Equal(sigPublicKey, publicKeyBytes) {
				err = errors.New("verify etherum signature failed")
				return
			}

			return
		},
	},
}

Functions

func LongTo8ByteArray

func LongTo8ByteArray(long int) (out []byte)

func ShortTo2ByteArray

func ShortTo2ByteArray(long int) []byte

Types

type BaseClient

type BaseClient struct {
	// contains filtered or unexported fields
}

func (*BaseClient) Request

func (self *BaseClient) Request(ctx context.Context) (*resty.Request, context.CancelFunc)

func (*BaseClient) Reset

func (self *BaseClient) Reset()

func (*BaseClient) SetPeers

func (self *BaseClient) SetPeers(peers []string)

Set the list of potential peers in order they should be used Uses only peers that are proper urls

type BundleItem

type BundleItem struct {
	SignatureType int                  `json:"signature_type"`
	Signature     arweave.Base64String `json:"signature"`
	Owner         arweave.Base64String `json:"owner"`  //  utils.Base64Encode(pubkey)
	Target        arweave.Base64String `json:"target"` // optional, if exist must length 32, and is base64 str
	Anchor        arweave.Base64String `json:"anchor"` // optional, if exist must length 32, and is base64 str
	Tags          Tags                 `json:"tags"`
	Data          arweave.Base64String `json:"data"`
	Id            arweave.Base64String `json:"id"`
	// contains filtered or unexported fields
}

func (*BundleItem) Encode added in v0.1.205

func (self *BundleItem) Encode(signer *Signer, out *bytes.Buffer) (err error)

func (*BundleItem) MarshalTo added in v0.1.205

func (self *BundleItem) MarshalTo(buf []byte) (n int, err error)

func (*BundleItem) Reader

func (self *BundleItem) Reader(signer *Signer) (out *bytes.Buffer, err error)

func (*BundleItem) Size added in v0.1.205

func (self *BundleItem) Size() (out int)

func (*BundleItem) Unmarshal added in v0.1.201

func (self *BundleItem) Unmarshal(buf []byte) (err error)

func (*BundleItem) UnmarshalFromReader added in v0.1.205

func (self *BundleItem) UnmarshalFromReader(reader io.Reader) (err error)

Reverse operation of Reader

func (*BundleItem) VerifySignature added in v0.1.202

func (self *BundleItem) VerifySignature() (err error)

type Client

type Client struct {
	*BaseClient
}

func NewClient

func NewClient(ctx context.Context, config *config.Bundlr) (self *Client)

func (*Client) GetStatus

func (self *Client) GetStatus(ctx context.Context, id string) (out *responses.Status, err error)

func (*Client) Upload

func (self *Client) Upload(ctx context.Context, signer *Signer, item *BundleItem) (out *responses.Upload, resp *resty.Response, err error)

type Signer

type Signer struct {
	PrivateKey *rsa.PrivateKey
	Owner      []byte
}

func NewSigner

func NewSigner(privateKeyJWK string) (self *Signer, err error)

func (*Signer) GetType added in v0.1.204

func (self *Signer) GetType() int

type Tag

type Tag struct {
	Name  string `json:"name" avro:"name"`
	Value string `json:"value" avro:"value"`
}

type Tags

type Tags []Tag

func (Tags) Marshal

func (self Tags) Marshal() ([]byte, error)

func (Tags) Size added in v0.1.205

func (self Tags) Size() int

func (Tags) Unmarshal added in v0.1.201

func (self Tags) Unmarshal(data []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL