skadnetwork

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2023 License: MIT Imports: 12 Imported by: 0

README

skadnetwork

ci

This library provides an implementation of skadnetwork.

Note

Parameter signing and postback validation only support version 2.1 and above.

Example

Sign the parameter data:

s, _ := skadnetwork.NewSigner(
    "-----BEGIN EC PRIVATE KEY-----\n...\n-----END EC PRIVATE KEY-----"
)
nonce := uuid.MustParse("68483ef6-0ada-40df-ab6b-3d19a66330fa")
timestamp, _ := time.Parse(time.RFC3339, "2022-05-06T10:00:00Z")

// For version 2.1
sig, _ := s.Sign(&skadnetwork.Params{
    Version:          "2.1",
    AdNetworkID:      "example123.skadnetwork",
    CampaignID:       42,
    ItunesItemID:     525463029,
    Nonce:            nonce,
    SourceAppStoreID: 1234567891,
    Timestamp:        timestamp,
})

// For version 2.2
sig, _ := s.Sign(&skadnetwork.Params{
    Version:          "2.2",
    AdNetworkID:      "example123.skadnetwork",
    CampaignID:       42,
    ItunesItemID:     525463029,
    Nonce:            nonce,
    SourceAppStoreID: 1234567891,
    FidelityType: skadnetwork.SKRenderedAds,
    Timestamp:        timestamp,
})

// For version 3.0
sig, _ := s.Sign(&skadnetwork.Params{
    Version:          "3.0",
    AdNetworkID:      "example123.skadnetwork",
    CampaignID:       42,
    ItunesItemID:     525463029,
    Nonce:            nonce,
    SourceAppStoreID: 1234567891,
    FidelityType: skadnetwork.SKRenderedAds,
    Timestamp:        timestamp,
})

Verify the signed parameter data:

ok, _ := s.Verify(&skadnetwork.Params{ ... }, sig)

Verify the Apple's postback data:

ok, _ := skadnetwork.Verify(&skadnetwork.Postback{ ... })

How to generate your public-private key pair

Please see Apple's documentation.

# Generate private key
openssl ecparam -name prime256v1 -genkey -noout -out companyname_skadnetwork_private_key.pem

# Generate pubilc key
openssl ec -in companyname_skadnetwork_private_key.pem -pubout -out companyname_skadnetwork_public_key.pem

License

Licensed under the MIT license.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

Types

type FidelityType

type FidelityType int

https://developer.apple.com/documentation/storekit/skadnetwork/signing_and_providing_ads

const (
	// App Store product page, rendered by StoreKit All SKAdNetwork versions.
	SKRenderedAds FidelityType = 1
	// Custom, provided by ad network SKAdNetwork version 2.2 and later.
	ViewThroughAds FidelityType = 0
)

func (FidelityType) String

func (f FidelityType) String() string

type Params

type Params struct {
	// Version 2.0 and later.
	// The SKAdNetwork API version number.
	Version string `json:"version,omitempty"`
	// Version 1.0 and later.
	// Your ad network identifier you registered with Apple.
	AdNetworkID string `json:"ad-network-id"`
	// Version 1.0 and later.
	// A campaign number you provide.
	CampaignID int `json:"campaign-id"`
	// Version 1.0 and later.
	// The App Store ID of the product to advertise.
	ItunesItemID int64 `json:"itunes-item-id"`
	// Version 1.0 and later.
	// A unique UUID value that you provide for each ad impression.
	// You must lowercase the string representation of the nonce value in the signature.
	Nonce uuid.UUID `json:"nonce"`
	// Version 2.0 and later.
	// The App Store ID of the app that displays the ad.
	// During testing, use an ID of 0 if you’re using a development-signed build and not an app from App Store.
	SourceAppStoreID int64 `json:"source-app-store-id,omitempty"`
	// Version 2.2 and later.
	// A value of 0 indicates a view-through ad presentation; a value of 1 indicates a StoreKit-rendered ad.
	FidelityType FidelityType `json:"fidelity-type,omitempty"`
	// Version 1.0 and later.
	// A timestamp you generate near the time of the ad impression.
	Timestamp time.Time `json:"timestamp"`
}

https://developer.apple.com/documentation/storekit/skadnetwork/generating_the_signature_to_validate_storekit-rendered_ads

type Postback

type Postback struct {
	// Version 2.0 and later.
	// Set this key to version number "3.0", "2.2", “2.1", or "2.0".
	// For version availability, see SKAdNetwork Release Notes.
	Version string `json:"version,omitempty"`
	// Version 1.0 and later.
	// Your ad network identifier, that matches the value you provided
	// for SKStoreProductParameterAdNetworkIdentifier or adNetworkIdentifier.
	AdNetworkID string `json:"ad-network-id"`
	// Version 1.0 and later.
	// A unique value for this validation; use to deduplicate install validation messages.
	TransactionID string `json:"transaction-id"`
	// Version 1.0 and later.
	// The campaign ID you provided when displaying the ad,
	// that matches SKStoreProductParameterAdNetworkCampaignIdentifier or adCampaignIdentifier.
	CampaignID int `json:"campaign-id,omitempty"`
	// Version 4.0 and later.
	// Replace the campaign-id
	SourceIdentifier string `json:"source-identifier,omitempty"`
	// Version 1.0 and later.
	// The item identifier of the advertised product.
	AppID int64 `json:"app-id"`
	// Version 2.0 and later.
	// Apple’s attribution signature, that you verify.
	AttributionSignature string `json:"attribution-signature,omitempty"`
	// Version 2.0 and later.
	// A Boolean flag that indicates that the customer redownloaded
	// and reinstalled the app when the value is true.
	Redownload *bool `json:"redownload,omitempty"`
	// Version 2.0 and later.
	// The item identifier of the app that displayed the ad.
	// During testing, if you’re using a development-signed build to display the ads
	// and not an app from App Store, use 0 as the item identifier.
	// Note: The source-app-id only appears in the postback if providing the parameter meets Apple’s privacy threshold.
	SourceAppID *int64 `json:"source-app-id,omitempty"`
	// Version 4.0 and later.
	SourceDomain *string `json:"source-domain,omitempty"`
	// Version 2.2 and later.
	// A value of 0 indicates a view-through ad presentation; a value of 1 indicates a StoreKit-rendered ad.
	FidelityType *FidelityType `json:"fidelity-type,omitempty"`
	// Version 2.0 and later.
	// An unsigned 6-bit value that the installed app provided by calling updateConversionValue(_:).
	// Note: The conversion-value only appears in the postback if the installed app provides it,
	// and if providing the parameter meets Apple’s privacy threshold.
	ConversionValue *uint8 `json:"conversion-value,omitempty"`
	// Version 4.0 and later.
	CoarseConversionValue *string `json:"coarse-conversion-value,omitempty"`
	// Version 3.0 and later.
	// A Boolean value that’s true if the ad network won the attribution,
	// and false if the postback represents a qualifying ad impression that didn’t win the attribution.
	DidWin *bool `json:"did-win,omitempty"`
	// Version 4.0 and later,
	PostbackSequenceIndex *int64 `json:"postback-sequence-index,omitempty"`
}

type Signer

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

func NewSigner

func NewSigner(pem string) (*Signer, error)

func (*Signer) Sign

func (s *Signer) Sign(p *Params) (string, error)

func (*Signer) Verify

func (s *Signer) Verify(p *Params, sig string) (bool, error)

Jump to

Keyboard shortcuts

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