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 |
Returns:
- Type:
- Artifact
Methods
(static) getArtifactSubtype() → {string}
Return the Artifact Subtype (to be used before class initialization)
Returns:
- Type:
- string
(static) getArtifactType() → {string}
Returns the Artifact Type (to be used before class initialization)
Returns:
- Type:
- string
addFile(file)
Add a File to the Artifact
Parameters:
Name | Type | Description |
---|---|---|
file |
ArtifactFile |
The file you wish to add |
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 |
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 |
createPreimage() → {string}
Create message to use for signature
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 |
Returns:
- Type:
- StatusObject
getArtifact() → {Object}
Get the Artifact object
Returns:
- Type:
- Object
getBlock()
Get block [height]
getBlockHash()
Get block hash
getClassName() → {string}
Get the Class Name. This is used to check the passed object in ArtifactFile (since InstanceOf could not be done).
Returns:
Returns "Artifact"
- Type:
- string
getDeactivated() → {boolean}
Get deactivation status
Returns:
- Type:
- boolean
getDescription() → {string}
Get the Description of the Artifact
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") |
Returns:
- Type:
- Object
getDuration() → {number}
Get the "simple" Duration of the Artifact. This gets the duration of the first file that has a duration.
Returns:
Returns undefined if there is no match to a duration
- Type:
- number
getEditVersion()
Get Record Edit Version
Returns:
The txid of the Edit Record
getFiles() → {Array.<ArtifactFile>}
Get all the Files on the Artifact
Returns:
- Type:
- Array.<ArtifactFile>
getLocation() → {string}
Get the Storage Location
Returns:
- Type:
- string
getMaxDiscount() → {number}
Get the maximum discount percent that Retailers can discount the content by during a sale
Returns:
- Type:
- number
getMeta() → {Object}
Get the Meta Object
Returns:
- Type:
- Object
getNetwork() → {string}
Get the Storage Network for the Artifact
Returns:
- Type:
- string
getNSFW() → {Boolean}
Get if the Artifact is marked NSFW
Returns:
- Type:
- Boolean
getOriginalTXID() → {String}
Get the Original Record TXID (getTXID will be different if edits have been performed)
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 |
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
Returns:
- keyValue => [string][string] === [coin][address]
- Type:
- Object
getPaymentFiat() → {string}
Get the Fiat type to be used in Payment Calculations
Returns:
Returns undefined if no fiat is set
- Type:
- string
getPaymentScale() → {number}
Get the payment scale for use in Payment Calculations
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
Returns:
- Type:
- number
getPubAddress() → {string}
Get the Main Address that the Artifact is signed with
Returns:
- Type:
- string
getPublisherName() → {string}
Get the Publisher Name for the Artifact
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
Returns:
- Type:
- number
getSignature() → {string}
Get the Signature of the Artifact
Returns:
Returns undefined
if signature is not set
- Type:
- string
getSubtype() → {string}
Get the Subtype of the Artifact
Returns:
- Type:
- string
getSuggestedTip() → {Array.<number>}
Get what the user has defined as their suggested tip values
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 |
Returns:
- Type:
- String | Array.<String>
getTags() → {Array.<string>}
Get the Tags for the Artifact
Returns:
- Type:
- Array.<string>
getThumbnail() → {ArtifactFile}
Get the Thumbnail file if it exists
Returns:
Returns undefined if no file is matched
- Type:
- ArtifactFile
getTime() → {undefined|*}
Get the unix timestamp of the block creation)
Returns:
- Type:
- undefined | *
getTimestamp() → {number}
Get the publish/signature timestamp for the Artifact
Returns:
Returns undefined
if timestamp is not yet set
- Type:
- number
getTipAddresses() → {Object}
Get the Addresses to send Tips to
Returns:
- keyValue => [string][string] === [coin][address]
- Type:
- Object
getTitle() → {string}
Get the Artifact Title
Returns:
- Type:
- string
getTokenRules() → {Array.<TokenRule>}
!!! NOT YET IMPLEMENTED !!! Get Token Rules from the Artifact
Returns:
- Type:
- Array.<TokenRule>
getTXID() → {string}
Get TXID
Returns:
txid
- Type:
- string
getType() → {string}
Get the Type of the Artifact
Returns:
- Type:
- string
getVersion()
Get Artifact Version type
getYear() → {number}
Get the Year that the content was originally published
Returns:
- Type:
- number
import041(artifact)
Hydrate an oip041 JSON object
Parameters:
Name | Type | Description |
---|---|---|
artifact |
import042(artifact)
Hydrate an oip042 JSON object
Parameters:
Name | Type | Description |
---|---|---|
artifact |
importAlexandriaMedia(artifact)
Hydrate an alexandria-media JSON object
Parameters:
Name | Type | Description |
---|---|---|
artifact |
isPaid() → {Boolean}
Check if the Artifact is Paid. An Artifact is defined as paid if any files have a cost.
Returns:
- Type:
- Boolean
isValid() → {StatusObject}
Check if an Artifact is Valid and has all the required fields to be Published
Returns:
- Type:
- StatusObject
setBlock()
Set block [height]
setBlockHash(blockHash)
Set block hash
Parameters:
Name | Type | Description |
---|---|---|
blockHash |
setDeactivated(status)
Set deactivation status
Parameters:
Name | Type | Description |
---|---|---|
status |
boolean |
setDescription(description)
Set the Description of the Artifact
Parameters:
Name | Type | Description |
---|---|---|
description |
string |
The Description you wish to set |
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 |
setEditVersion(editTxid)
Set Record Edit Version
Parameters:
Name | Type | Description |
---|---|---|
editTxid |
The txid of the Edit Record |
setLocation(location)
Set the Storage Location
Parameters:
Name | Type | Description |
---|---|---|
location |
string |
The Location of the files on the Storage Network |
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 |
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 |
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 |
|
setOriginalTXID(originalTxid)
Set the Original Record TXID (setTXID will be different if edits have been performed)
Parameters:
Name | Type | Description |
---|---|---|
originalTxid |
string |
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 |
setPaymentScale(newScale)
Set the Payment Scale to use in Payment Calculations
Parameters:
Name | Type | Description |
---|---|---|
newScale |
number |
The new Scale that should be used |
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 |
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 |
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 |
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 |
setSignature(signature)
Set the Signature of the Artifact
Parameters:
Name | Type | Description |
---|---|---|
signature |
string |
The signature of the Artifact |
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 |
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 |
setTags(tags)
Set the Tags for the Artifact
Parameters:
Name | Type | Description |
---|---|---|
tags |
Array.<string> |
Pass in an Array of tags |
setTime(time)
Set time (unix timestamp of block creation)
Parameters:
Name | Type | Description |
---|---|---|
time |
setTimestamp(time)
Set publish/signature timestamp for the Artifact
Parameters:
Name | Type | Description |
---|---|---|
time |
number |
The Timestamp you wish to set the Artifact to |
setTitle(title)
Set the Artifact Title
Parameters:
Name | Type | Description |
---|---|---|
title |
string |
The desired Title you wish to set the Artifact to |
setTXID(txid)
Set TXID
Parameters:
Name | Type | Description |
---|---|---|
txid |
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"] |
setVersion(version)
Set Artifact Version
Parameters:
Name | Type | Description |
---|---|---|
version |
'alexandria-media', 'oip041', or 'oip042' |
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 |
toJSON() → {Object}
Get the Artifact JSON. This is the "Dehydrated" version of this class.
Returns:
- Type:
- Object
toString() → {string}
Returns a string version of the .toJSON() function
Returns:
- Type:
- string