@ceramicnetwork/blockchain-utils-linking
Version:
Blockchain utils for linking blockchain accounts to DID
41 lines • 1.55 kB
JavaScript
import { AccountId } from 'caip';
import { asOldCaipString, getConsentMessage } from './util.js';
import * as uint8arrays from 'uint8arrays';
const stringHex = (str) => `0x${uint8arrays.toString(uint8arrays.fromString(str), 'base16')}`;
const CHAIN_ID = 'polkadot:b0a8d493285c2df73290dfb7e61f870f';
export class PolkadotAuthProvider {
constructor(provider, address) {
this.provider = provider;
this.address = address;
this.isAuthProvider = true;
console.warn('WARN: PolkadotAuthProvider is not fully supported. You may encounter issues using this.');
}
async authenticate(message) {
throw new Error(`Not Implemented: PolkadotAuthProvider#authenticate, ${message}`);
}
async createLink(did) {
const { message, timestamp } = getConsentMessage(did);
const linkMessageHex = stringHex(message);
const account = await this.accountId();
const res = await this.provider.signRaw({
address: this.address,
data: linkMessageHex,
type: 'bytes',
});
return {
version: 2,
type: 'eoa',
message: message,
signature: res.signature,
account: asOldCaipString(account),
timestamp: timestamp,
};
}
async accountId() {
return new AccountId({ address: this.address, chainId: CHAIN_ID });
}
withAddress(address) {
return new PolkadotAuthProvider(this.provider, address);
}
}
//# sourceMappingURL=polkadot.js.map