import { AstralSDK, MockPlugin } from '@decentralized-geo/astral-sdk';
import { ethers } from 'ethers';
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY);
const astral = new AstralSDK({
chainId: 84532,
signer: wallet,
apiUrl: 'https://api.astral.global'
});
// Register MockPlugin
astral.plugins.register(new MockPlugin({
lat: 48.8584,
lon: 2.2945,
accuracy: 15,
jitterMeters: 10
}));
// 1. Collect
const signals = (await astral.stamps.collect({ plugins: ['mock'] }))[0];
// 2. Create
const unsigned = await astral.stamps.create({ plugin: 'mock' }, signals);
// 3. Sign
const stamp = await astral.stamps.sign(
{ plugin: 'mock' },
unsigned,
{
algorithm: 'secp256k1',
signer: { scheme: 'eth-address', value: wallet.address },
sign: (data) => wallet.signMessage(data)
}
);
// 4. Verify
const result = await astral.stamps.verify(stamp);
console.log('Valid:', result.valid);
// 5. Build a proof
const claim = {
lpVersion: '0.2',
locationType: 'geojson-point',
location: { type: 'Point', coordinates: [2.2945, 48.8584] },
srs: 'EPSG:4326',
subject: { scheme: 'eth-address', value: wallet.address },
radius: 50,
time: {
start: Math.floor(Date.now() / 1000) - 120,
end: Math.floor(Date.now() / 1000)
}
};
const proof = astral.proofs.create(claim, [stamp]);
const vector = await astral.proofs.verify(proof);
console.log('Spatial:', vector.dimensions.spatial.meanDistanceMeters, 'm');
console.log('Temporal:', vector.dimensions.temporal.meanOverlap);