Artifact

Artifact




new Artifact(input) → {Artifact}

An Artifact contains metadata about a file/piece of content, along with a location on a network to find that file, and optionally payment information.

Create a new Artifact This function is an es5 constructor that returns a new Artifact class based on the version of the artifact/record

Examples

Create a blank Artifact

import { Artifact } from 'oip-index'

let artifact = Artifact()

Create an Artifact from JSON

import { Artifact } from 'oip-index'

let artifact = Artifact({
  "artifact": {
    "publisher": "FPkvwEHjddvva2smpYwQ4trgudwFcrXJ1X",
    "payment": {
      "addresses": [],
      "retailer": 15,
      "sugTip": [],
      "fiat": "USD",
      "scale": "1000:1",
      "promoter": 15,
      "maxdisc": 30
    },
    "storage": {
      "files": [
        {
          "fname": "headshot.jpg",
          "fsize": 100677,
          "type": "Image"
        }
      ],
      "location": "QmUjSCcBda9YdEUKVLPQomHzSatwytPqQPAh4fdMiRV8bp",
      "network": "IPFS"
    },
    "type": "Image-Basic",
    "info": {
      "title": "Headshot",
      "extraInfo": {
        "artist": "David Vasandani",
        "genre": "People"
      }
    },
    "timestamp": 1531065099
  },
  "meta": {
    "block_hash": "a2ca4c3f06032dc4f9df7eca829b42b91da9595dbe9f4623a1c7f92a5508cfb9",
    "txid": "5f399eef8f93c03502efbd51691350cbacbf3c16eba228409bf7453ffff78207",
    "block": 2832215,
    "time": 1531065167,
    "type": "oip041"
  }
})

Create an Artifact from a JSON string

import { Artifact } from 'oip-index'

let artifact = new Artifact("{"artifact":{"publisher":"FPkvwEHjddvva2smpYwQ4trgudwFcrXJ1X","payment":{"addresses":[],"retailer":15,"sugTip":[],"fiat":"USD","scale":"1000:1","promoter":15,"maxdisc":30},"storage":{"files":[{"fname":"headshot.jpg","fsize":100677,"type":"Image"}],"location":"QmUjSCcBda9YdEUKVLPQomHzSatwytPqQPAh4fdMiRV8bp","network":"IPFS"},"type":"Image-Basic","info":{"title":"Headshot","extraInfo":{"artist":"David Vasandani","genre":"People"}},"timestamp":1531065099},"meta":{"block_hash":"a2ca4c3f06032dc4f9df7eca829b42b91da9595dbe9f4623a1c7f92a5508cfb9","txid":"5f399eef8f93c03502efbd51691350cbacbf3c16eba228409bf7453ffff78207","block":2832215,"time":1531065167,"type":"oip041"}}")
Parameters:
Name Type Description
input Array.<Multipart> | string | Object

Pass in either an array of Multiparts, an Artifact JSON string, or an Artifact JSON object to be loaded from

Source:
Returns:
Type:
Artifact

Methods




(static) getArtifactSubtype() → {string}

Return the Artifact Subtype (to be used before class initialization)

Source:
Returns:
Type:
string



(static) getArtifactType() → {string}

Returns the Artifact Type (to be used before class initialization)

Source:
Returns:
Type:
string



addFile(file)

Add a File to the Artifact

Parameters:
Name Type Description
file ArtifactFile

The file you wish to add

Source:



addSinglePaymentAddress(coin, address)

Accept Payments for a specific coin

Parameters:
Name Type Description
coin string

The string coin ticker

address string

Base58 Public Key to send payments

Source:



addTokenRule(tokenRule)

!!! NOT YET IMPLEMENTED !!! Add Token Rule to the Artifact

Parameters:
Name Type Description
tokenRule TokenRule

The Token Rule to add to the Artifact

Source:



createPreimage() → {string}

Create message to use for signature

Source:
Returns:
Type:
string



fromJSON(artifact) → {StatusObject}

Load the Artifact from JSON. This "Hydrates" this class with the "Dehydrated" info.

Parameters:
Name Type Description
artifact Object

The specific Artifact JSON

Source:
Returns:
Type:
StatusObject



getArtifact() → {Object}

Get the Artifact object

Source:
Returns:
Type:
Object



getBlock()

Get block [height]

Source:



getBlockHash()

Get block hash

Source:



getClassName() → {string}

Get the Class Name. This is used to check the passed object in ArtifactFile (since InstanceOf could not be done).

Source:
Returns:

Returns "Artifact"

Type:
string



getDeactivated() → {boolean}

Get deactivation status

Source:
Returns:
Type:
boolean



getDescription() → {string}

Get the Description of the Artifact

Source:
Example
let description = artifact.getDescription()
Returns:
Type:
string



getDetail(detail) → {Object}

Get a specific Detail back from the Artifact

Parameters:
Name Type Description
detail string

The detail you want pack (i.e. "artist")

Source:
Example
let artist = artifact.getDetail("artist")
Returns:
Type:
Object



getDuration() → {number}

Get the "simple" Duration of the Artifact. This gets the duration of the first file that has a duration.

Source:
Returns:

Returns undefined if there is no match to a duration

Type:
number



getEditVersion()

Get Record Edit Version

Source:
Returns:

The txid of the Edit Record




getFiles() → {Array.<ArtifactFile>}

Get all the Files on the Artifact

Source:
Returns:
Type:
Array.<ArtifactFile>



getLocation() → {string}

Get the Storage Location

Source:
Example
let location = artifact.getLocation()
Returns:
Type:
string



getMaxDiscount() → {number}

Get the maximum discount percent that Retailers can discount the content by during a sale

Source:
Example
let maxDiscount = artifact.getMaxDiscount()
Returns:
Type:
number



getMeta() → {Object}

Get the Meta Object

Source:
Returns:
Type:
Object



getNetwork() → {string}

Get the Storage Network for the Artifact

Source:
Example
let mainAddress = artifact.getPubAddress()
Returns:
Type:
string



getNSFW() → {Boolean}

Get if the Artifact is marked NSFW

Source:
Example
let nsfw = artifact.getNSFW()
Returns:
Type:
Boolean



getOriginalTXID() → {String}

Get the Original Record TXID (getTXID will be different if edits have been performed)

Source:
Returns:

originalTxid

Type:
String



getPaymentAddress(coins) → {Object}

Get the Address(es) to send Payments to for specific coins

Parameters:
Name Type Description
coins string | Array.<string>

A string or an array of strings of the coins you wish to fetch the addresses for

Source:
Example
let address = artifact.getPaymentAddress(["btc", "ltc"])
{ btc: "19HuaNprtc8MpG6bmiPoZigjaEu9xccxps",
    ltc: "LbpjYYPwYBjoPQ44PrNZr7nTq7HkYgcoXN"}
Returns:
  • keyValue => [string][string] === [coin][address]
Type:
Object



getPaymentAddresses() → {Object}

Get the Addresses to send Payment to

Source:
Example
let addresses = artifact.getPaymentAddresses()
Returns:
  • keyValue => [string][string] === [coin][address]
Type:
Object



getPaymentFiat() → {string}

Get the Fiat type to be used in Payment Calculations

Source:
Example
let fiat = artifact.getPaymentFiat()
Returns:

Returns undefined if no fiat is set

Type:
string



getPaymentScale() → {number}

Get the payment scale for use in Payment Calculations

Source:
Example
let scale = artifact.getPaymentScale()
Returns:

Returns 1 if no payment scale is set (aka, 1:1 scale)

Type:
number



getPromoterCut() → {number}

Get the cut that the user wants to send to Promoters for sharing their content

Source:
Example
let promoterCut = artifact.getPromoterCut()
Returns:
Type:
number



getPubAddress() → {string}

Get the Main Address that the Artifact is signed with

Source:
Example
let mainAddress = artifact.getPubAddress()
Returns:
Type:
string



getPublisherName() → {string}

Get the Publisher Name for the Artifact

Source:
Example
let pubName = artifact.getPublisherName()
Returns:

Returns the Publisher Name if defined, or the Main Address if the publisher name is undefined

Type:
string



getRetailerCut() → {number}

Get the cut that the user wants to send to Retailers for selling their content

Source:
Example
let retailerCut = artifact.getRetailerCut()
Returns:
Type:
number



getSignature() → {string}

Get the Signature of the Artifact

Source:
Example
let signature = artifact.getSignature()
Returns:

Returns undefined if signature is not set

Type:
string



getSubtype() → {string}

Get the Subtype of the Artifact

Source:
Example
let subtype = artifact.getSubtype()
Returns:
Type:
string



getSuggestedTip() → {Array.<number>}

Get what the user has defined as their suggested tip values

Source:
Example
let tips = artifact.getSuggestedTip()
Returns:
Type:
Array.<number>



getSupportedCoins(coinsopt) → {String|Array.<String>}

Get the supported payment coins

Parameters:
Name Type Attributes Description
coins string | Array.<String> <optional>

coins you want to check against

Source:
Example
let supportedCoins = artifact.getSupportedCoins()
Returns:
Type:
String | Array.<String>



getTags() → {Array.<string>}

Get the Tags for the Artifact

Source:
Example
let tags = artifact.getTags()
Returns:
Type:
Array.<string>



getThumbnail() → {ArtifactFile}

Get the Thumbnail file if it exists

Source:
Returns:

Returns undefined if no file is matched

Type:
ArtifactFile



getTime() → {undefined|*}

Get the unix timestamp of the block creation)

Source:
Returns:
Type:
undefined | *



getTimestamp() → {number}

Get the publish/signature timestamp for the Artifact

Source:
Example
let timestamp = artifact.getTimestamp()
Returns:

Returns undefined if timestamp is not yet set

Type:
number



getTipAddresses() → {Object}

Get the Addresses to send Tips to

Source:
Example
let addresses = artifact.getPaymentAddresses()
Returns:
  • keyValue => [string][string] === [coin][address]
Type:
Object



getTitle() → {string}

Get the Artifact Title

Source:
Example
let title = artifact.getTitle()
Returns:
Type:
string



getTokenRules() → {Array.<TokenRule>}

!!! NOT YET IMPLEMENTED !!! Get Token Rules from the Artifact

Source:
Returns:
Type:
Array.<TokenRule>



getTXID() → {string}

Get TXID

Source:
Returns:

txid

Type:
string



getType() → {string}

Get the Type of the Artifact

Source:
Example
let type = artifact.getType()
Returns:
Type:
string



getVersion()

Get Artifact Version type

Source:



getYear() → {number}

Get the Year that the content was originally published

Source:
Example
let year = artifact.getYear()
Returns:
Type:
number



import041(artifact)

Hydrate an oip041 JSON object

Parameters:
Name Type Description
artifact
Source:



import042(artifact)

Hydrate an oip042 JSON object

Parameters:
Name Type Description
artifact
Source:



importAlexandriaMedia(artifact)

Hydrate an alexandria-media JSON object

Parameters:
Name Type Description
artifact
Source:



isPaid() → {Boolean}

Check if the Artifact is Paid. An Artifact is defined as paid if any files have a cost.

Source:
Returns:
Type:
Boolean



isValid() → {StatusObject}

Check if an Artifact is Valid and has all the required fields to be Published

Source:
Returns:
Type:
StatusObject



setBlock()

Set block [height]

Source:



setBlockHash(blockHash)

Set block hash

Parameters:
Name Type Description
blockHash
Source:



setDeactivated(status)

Set deactivation status

Parameters:
Name Type Description
status boolean
Source:



setDescription(description)

Set the Description of the Artifact

Parameters:
Name Type Description
description string

The Description you wish to set

Source:
Example
artifact.setDescription("My Description")



setDetail(detail, info)

Set a specific Detail on the Artifact

Parameters:
Name Type Description
detail string

Where should we place this detail (i.e. "artist")

info Object

The item you wish to set to the detail node

Source:
Example
artifact.setDetail("artist", "Artist Name")



setEditVersion(editTxid)

Set Record Edit Version

Parameters:
Name Type Description
editTxid

The txid of the Edit Record

Source:



setLocation(location)

Set the Storage Location

Parameters:
Name Type Description
location string

The Location of the files on the Storage Network

Source:
Example
artifact.setLocation("QmNmVHfXuh5Tub76H1fog7wSM8of4Njfm2j1oTg8ZYUBZm")



setMaxDiscount(newMax)

Set the maximum discount percent that Retailers can discount your content by during a sale

Parameters:
Name Type Description
newMax number

The new maximim discount percentage

Source:
Example
artifact.setMaxDiscount(20)



setNetwork(network)

Set the Storage Network of the Artifact

Parameters:
Name Type Description
network string

The Storage Network where we can find the file at Location

Source:
Examples
<caption>Set Network to IPFS</caption
artifact.setNetwork("IPFS")
<caption>Set Network to Storj (Support coming Soon)</caption
artifact.setNetwork("Storj")



setNSFW(nsfwToggle)

Set if the Artifact is NSFW

Parameters:
Name Type Description
nsfwToggle Boolean

true or false depending on the content of the Artifact

Source:
Example
artifact.setNSFW(true)



setOriginalTXID(originalTxid)

Set the Original Record TXID (setTXID will be different if edits have been performed)

Parameters:
Name Type Description
originalTxid string
Source:



setPaymentFiat(fiat)

Set the Fiat to be used in Payment Calculations. Only "usd" is supported right now.

Parameters:
Name Type Description
fiat string

The Fiat type you wish to accept

Source:
Example
artifact.setPaymentFiat("usd")



setPaymentScale(newScale)

Set the Payment Scale to use in Payment Calculations

Parameters:
Name Type Description
newScale number

The new Scale that should be used

Source:
Example
artifact.setPaymentScale(1000)



setPromoterCut(newCut)

Set the cut you want to send to Promoters for sharing your content

Parameters:
Name Type Description
newCut number

The new cut you want sent to Retailers

Source:
Example
artifact.setPromoterCut(10)



setPubAddress(address)

Set the Main Address that you will be signing the Artifact with

Parameters:
Name Type Description
address string

The Main Address that will be signing the Artifact

Source:
Example
artifact.setPubAddress("FLZXRaHzVPxJJfaoM32CWT4GZHuj2rx63k")



setPublisherName(publisherName)

Set the Publisher name String, please note that this does not set it when you publish to the blockchain!

Parameters:
Name Type Description
publisherName string

The Publisher Name you wish to set the Artifact to

Source:
Example
artifact.setPublisherName("My Publisher Name")



setRetailerCut(newCut)

Set the cut you want to send to Retailers for selling your content

Parameters:
Name Type Description
newCut number

The new cut you want sent to Retailers

Source:
Example
artifact.setRetailerCut(10)



setSignature(signature)

Set the Signature of the Artifact

Parameters:
Name Type Description
signature string

The signature of the Artifact

Source:
Example
artifact.setSignature("IO0i5yhuwDy5p93VdNvEAna6vsH3UmIert53RedinQV+ScLzESIX8+QrL4vsquCjaCY0ms0ZlaSeTyqRDXC3Iw4=")



setSubtype(subtype)

Set the Subtype of the Artifact

Parameters:
Name Type Description
subtype string

The desired Subtype for the Artifact

Source:
Example
artifact.setSubtype("Album")



setSuggestedTip(suggestedTipArray)

Set suggested tip values to use. These tip values are the fiat value, divided by the scale you set.

Parameters:
Name Type Description
suggestedTipArray Array.<number>

The Suggested Tips you wish to define

Source:
Example
artifact.setSuggestedTip([10, 100, 1000])



setTags(tags)

Set the Tags for the Artifact

Parameters:
Name Type Description
tags Array.<string>

Pass in an Array of tags

Source:
Example
artifact.setTags(["Tag 1", "Tag 2", "Tag 3"])



setTime(time)

Set time (unix timestamp of block creation)

Parameters:
Name Type Description
time
Source:



setTimestamp(time)

Set publish/signature timestamp for the Artifact

Parameters:
Name Type Description
time number

The Timestamp you wish to set the Artifact to

Source:
Example
artifact.setTimestamp(Date.now())



setTitle(title)

Set the Artifact Title

Parameters:
Name Type Description
title string

The desired Title you wish to set the Artifact to

Source:
Example
artifact.setTitle("Example Title")



setTXID(txid)

Set TXID

Parameters:
Name Type Description
txid
Source:



setType(type)

Set the Type of the Artifact

Parameters:
Name Type Description
type string

Must be one of the following supported Artifact Main Types ["Audio", "Video", "Image", "Text", "Software", "Web", "Research", "Property"]

Source:
Example
artifact.setType("Video")



setVersion(version)

Set Artifact Version

Parameters:
Name Type Description
version

'alexandria-media', 'oip041', or 'oip042'

Source:



setYear(year)

Set the Year that the content was originally published

Parameters:
Name Type Description
year number

The Year that the content was originally published

Source:
Example
artifact.setYear(2018)



toJSON() → {Object}

Get the Artifact JSON. This is the "Dehydrated" version of this class.

Source:
Returns:
Type:
Object



toString() → {string}

Returns a string version of the .toJSON() function

Source:
Returns:
Type:
string