Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
[
'@context':'https://w3id.org/did/v1',
id:'did:geo:QmdDEcQbiFEY5YWvKgk2exd6XLetgfVmswZvXRgNkpehre',
publicKey: [
{
id: 'did:geo:QmdDEcQbiFEY5YWvKgk2exd6XLetgfVmswZvXRgNkpehre#controller',
type: 'Secp256k1VerificationKey2018',
controller: 'did:geo:QmdDEcQbiFEY5YWvKgk2exd6XLetgfVmswZvXRgNkpehre',
ethereumAddress: '0x4B11B9A1582E455c2C5368BEe0FF5d2F1dd4d28e'
}
],
did_metadata:{
type:'collection',
created:'2019-03-23T06:35:22Z',
updated:'2019-03-23T06:37:45Z'
},
links:[
{
id: 'did:geo:QmdDEcQbiFEY5YWvKgk2exd6XLetgfVmswZvXRgNkpehre',
type: 'collection',
rel: 'root'
},
{
id: 'did:geo:QmdDEcQbiFEY5YWvKgk2exd6XLetgfVmswZvXRgNkpehre',
type: 'collection',
rel: 'self'
}
],
service:[
{
id: 'did:geo:QmdDEcQbiFEY5YWvKgk2exd6XLetgfVmswZvXRgNkpehre#collection-metadata'
type: collection-metadata
serviceEndpoint: <CID or URL>
}
]
]Common Types used throughout the Project
[
{
'@context': 'https://w3id.org/did/v1',
id: 'did:geo:QmdDEcQbiFEY5YWvKgk2exd6XLetgfVmswZvXRgNkpehre',
publicKey: [
{
id: 'did:geo:QmdDEcQbiFEY5YWvKgk2exd6XLetgfVmswZvXRgNkpehre#controller',
type: 'Secp256k1VerificationKey2018',
controller: 'did:geo:QmdDEcQbiFEY5YWvKgk2exd6XLetgfVmswZvXRgNkpehre',
ethereumAddress: '0x4B11B9A1582E455c2C5368BEe0FF5d2F1dd4d28e'
}
],
didmetadata: { type: 'item', created: '2021-03-12T15:56:10.937Z' },
links: [
{
id: 'did:geo:QmdDEcQbiFEY5YWvKgk2exd6XLetgfVmswZvXRgNkpehre',
type: 'item',
rel: 'root'
},
{
id: 'did:geo:QmdDEcQbiFEY5YWvKgk2exd6XLetgfVmswZvXRgNkpehre',
type: 'item',
rel: 'self'
}
],
service: [
{
id: 'did:geo:QmdDEcQbiFEY5YWvKgk2exd6XLetgfVmswZvXRgNkpehre#item-metadata-1'
type: item-metadata
serviceEndpoint: <CID or URL>
},
{
id: 'did:geo:QmdDEcQbiFEY5YWvKgk2exd6XLetgfVmswZvXRgNkpehre#geojson-1'
type: geojson
serviceEndpoint: <CID or URL>
},
{
id: 'did:geo:QmdDEcQbiFEY5YWvKgk2exd6XLetgfVmswZvXRgNkpehre#geojson-2'
type: geojson
serviceEndpoint: <CID or URL>
},
{
id: 'did:geo:QmdDEcQbiFEY5YWvKgk2exd6XLetgfVmswZvXRgNkpehre#geotiff-1'
type: geotiff
serviceEndpoint: <CID or URL>
},
{
id: 'did:geo:QmdDEcQbiFEY5YWvKgk2exd6XLetgfVmswZvXRgNkpehre#json-1'
type: json
serviceEndpoint: <CID or URL>
},
{
id: 'did:geo:QmdDEcQbiFEY5YWvKgk2exd6XLetgfVmswZvXRgNkpehre#misc-1'
type: misc
serviceEndpoint: <CID or URL>
}
]
}
]The Core Specification of the GeoDID; includes default fields for specification.
[
{
'@context': 'https://w3id.org/did/v1',
id: 'did:geo:QmdDEcQbiFEY5YWvKgk2exd6XLetgfVmswZvXRgNkpehre',
publicKey: [
{
id: 'did:geo:QmdDEcQbiFEY5YWvKgk2exd6XLetgfVmswZvXRgNkpehre#controller',
type: 'Secp256k1VerificationKey2018',
controller: 'did:geo:QmdDEcQbiFEY5YWvKgk2exd6XLetgfVmswZvXRgNkpehre',
ethereumAddress: '0x4B11B9A1582E455c2C5368BEe0FF5d2F1dd4d28e'
}
],
didmetadata: { type: 'collection', created: '2021-03-12T15:56:10.937Z' },
links: [
{
id: 'did:geo:QmdDEcQbiFEY5YWvKgk2exd6XLetgfVmswZvXRgNkpehre',
type: 'collection',
rel: 'root'
},
{
id: 'did:geo:QmdDEcQbiFEY5YWvKgk2exd6XLetgfVmswZvXRgNkpehre',
type: 'collection',
rel: 'self'
}
],
service: [
{
id: 'did:geo:QmdDEcQbiFEY5YWvKgk2exd6XLetgfVmswZvXRgNkpehre#' + `${<ServiceType>}` + `${index}`
type: <ServiceType>
serviceEndpoint: <CID or URL>
}
]
}
]yarn add -D @astralprotocol/core
OR
npm install -D @astralprotocol/core
import AstralClient from '@astralprotocol/core';
OR
const AstralClient = require('@astralprotocol/core');import AstralClient from '@astralprotocol/core';
async function run(){
// Create a new Astral Client Instance with the user's ethAddress
// and a subgraph endpoint (check the latest one @astralprotocol/subgraph)
let astral = new AstralClient(
'0xa3e1c2602f628112E591A18004bbD59BDC3cb512',
'https://api.thegraph.com/subgraphs/name/astralprotocol/spatialassetsv06'
);
try{
// Creates a Genesis GeoDID
const genDocRes = await astral.createGenesisGeoDID('collection')
console.log(genDocRes);
// With the returned IDocumentInfo from the last function, we can pin it.
// Since no token was specified the client will assign a new auth Token to the user.
const results = await astral.pinDocument(genDocRes);
console.log(results);
const token = results.token;
// With the Auth Token and the GeoDID ID we can load the document with the loadDocument function
const loadResults = await astral.loadDocument(results.geodidid, token);
console.log(loadResults);
console.log('\n');
console.log('\n');
// Creates a Child GeoDID Item of the priviously created Genesis GeoDID
const itemres = await astral.createChildGeoDID('item', results.geodidid, 'item1');
console.log(itemres)
console.log('\n');
// With the returned IDocumentInfo from the last function, we can pin it.
// This time we reuse the same token that was created earlier to pin the child document to the same instance.
const itemresults = await astral.pinDocument(itemres, token);
console.log(itemresults);
console.log('\n');
// With the Auth Token and the GeoDID ID we can load the document with the loadDocument function
const loadItemResults = await astral.loadDocument(itemresults.geodidid, token);
console.log(loadItemResults);
console.log('\n');
// Here we can display the string representation of the DID Document
console.log(JSON.stringify(loadItemResults.documentInfo.documentVal));
}catch(e){
console.log(e);
}
}node testScript.jsinterface IDocumentInfo {
geodidid: string;
documentVal: any;
parentid?: string;
}interface IDocumentInfo {
geodidid: string;
documentVal: any;
parentid?: string;
}interface IPinInfo {
geodidid: string;
cid: string;
pinDate: Date;
token: string
} interface LoadInfo {
documentInfo: IDocumentInfo;
powergateInstance: Powergate
}
yarn add @astralprotocol/core @astralprotocol/contracts dotenv bs58 truffle @truffle/hdwallet-providerconst HDWalletProvider = require("@truffle/hdwallet-provider");
require('dotenv').config();
// Create a .env file with your MNEMONIC and a ROPSTEN API key from INFURA
// Must have the following format:
// MNEMONIC="words here "
// ROPSTEN_API_KEY=https://ropsten.infura.io/v3/key
let mnemonic = process.env.MNEMONIC
let ropstenURL = process.env.ROPSTEN_API_KEY
let provider = new HDWalletProvider({
mnemonic: {
phrase: mnemonic,
},
providerOrUrl: ropstenURL,
});
module.exports = {
networks: {
development: {
host: "127.0.0.1",
port: 8545,
network_id: "*",
},
ropsten: {
provider: provider,
network_id: "3",
},
},
compilers: {
solc: {
version: "0.6.12",
},
},
};const { AstralClient } = require('@astralprotocol/core');
const SpatialAssets = require("@astralprotocol/contracts/build/contracts/SpatialAssets.json")
const bs58 = require('bs58')
module.exports = async function (callback) {
const stringToBytes = (string) => web3.utils.asciiToHex(string)
// based on https://ethereum.stackexchange.com/questions/17094/how-to-store-ipfs-hash-using-bytes32
// Return bytes32 hex string from base58 encoded ipfs hash,
// stripping leading 2 bytes from 34 byte IPFS hash
// Assume IPFS defaults: function:0x12=sha2, size:0x20=256 bits
// E.g. "QmNSUYVKDSvPUnRLKmuxk9diJ6yS96r1TrAXzjTiBcCLAL" -->
// "0x017dfd85d4f6cb4dcd715a88101f7b1f06cd1e009b2327a0809d01eb9c91f231"
function getBytes32FromIpfsHash(ipfsListing) {
return "0x"+bs58.decode(ipfsListing).slice(2).toString('hex')
}
try {
const accounts = await web3.eth.getAccounts()
const userAccount = accounts[0]
// find contract in network 3 (Ropsten)
const SpatialAssetsContract = new web3.eth.Contract(SpatialAssets.abi, SpatialAssets.networks['3'].address, {
from: userAccount,
data: SpatialAssets.deployedBytecode,
});
// update the endpoint to the latest
const subgraphEndpoint = "https://api.thegraph.com/subgraphs/name/astralprotocol/spatialassetsfinalv1"
const astral = await AstralClient.build(userAccount, subgraphEndpoint, "https://astralinstance.tk");
const storage = stringToBytes('FILECOIN');
// Creates a Genesis GeoDID
const genDocRes = await astral.createGenesisGeoDID('collection')
console.log(genDocRes);
// With the returned IDocumentInfo from the last function, we can pin it.
// Since no token was specified the client will assign a new auth Token to the user.
const results = await astral.pinDocument(genDocRes);
console.log(results);
// register the geodid id and cid obtained. Type 0 because it is a collection
console.log(results.geodidid)
console.log(results.cid)
const bytes32GeoDID= getBytes32FromIpfsHash(results.geodidid.substring(8));
const bytes32Cid = getBytes32FromIpfsHash(results.cid);
try {
await SpatialAssetsContract.methods.registerSpatialAsset(userAccount, bytes32GeoDID, stringToBytes(''),[], bytes32Cid, storage,0).send()
.on('receipt', function(receipt){
// receipt example
console.log(receipt);
})
.on('error', function(error) { // If the transaction was rejected by the network with a receipt, the second parameter will be the receipt.
console.log(error);
});
}
catch (err) {
// Will throw an error if tx reverts
console.log(err)
}
// With the Auth Token and the GeoDID ID we can load the document with the loadDocument function
const loadResults = await astral.loadDocument(results.geodidid);
console.log(loadResults);
}
catch(error) {
console.log(error)
}
callback()
};"deployGeoDIDs": "truffle exec scripts/deployGeoDIDs.js --network ropsten",yarn deployGeoDIDshttps://api.thegraph.com/subgraphs/name/astralprotocol/spatialassetsfinalv1
wss://api.thegraph.com/subgraphs/name/astralprotocol/spatialassetsfinalv1yarn add @astralprotocol/subgraph{
geoDIDs {
id
owner
cid
storage
root
parent
edges {
id
childGeoDID {
id
}
}
active
type
}
}yarn add @astralprotocol/contractsgit clone git@github.com:AstralProtocol/astralprotocol.git
cd astralprotocol/packages/contractsMNEMONIC="mnemonic phrase goes here with testnet ether in address[0] on ropsten cool"
ROPSTEN_API_KEY=https://ropsten.infura.io/v3/<PROJECT ID HERE>constructor(string memory uri) publicfunction registerRole() publicfunction enableStorage(bytes32 offChainStorage) publicfunction disableStorage(bytes32 offChainStorage) publicfunction registerSpatialAsset (
address owner,
bytes32 geoDIDId,
bytes32 parentGeoDIDId ,
bytes32[] memory childrenGeoDIDIds,
bytes32 cid,
bytes32 offChainStorage,
uint256 geoDIDtype
) publicfunction addChildrenGeoDIDs(
bytes32 geoDIDId,
bytes32[] memory childrenGeoDIDIds
) publicfunction addParentGeoDID(
bytes32 geoDIDId,
bytes32 parentGeoDIDId
) publicfunction removeChildrenGeoDIDs(
bytes32 geoDIDId,
bytes32[] memory childrenGeoDIDIds
) publicfunction removeParentGeoDID(
bytes32 geoDIDId,
bytes32 parentGeoDIDId
) publicfunction deactivateSpatialAsset(
bytes32 geoDIDId,
bytes32[] memory childrenToRemove
) publicPlanned upgrades to the GeoDID Method Specification

