-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
3,972 additions
and
1,963 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
.env | ||
yarn-error.log | ||
|
||
.yarn/* | ||
!.yarn/releases | ||
node_modules | ||
out |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
nodeLinker: node-modules | ||
|
||
yarnPath: .yarn/releases/yarn-3.6.0.cjs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
"att-key-set": "ts-node src/att-key-set.ts", | ||
"del-key-set": "ts-node src/del-key-set.ts", | ||
"did-create": "ts-node src/did-create.ts", | ||
"dip-sign:parent": "ts-node src/dip-parent-sign.ts", | ||
"dip-sign:sibling": "ts-node src/dip-sibling-sign.ts", | ||
"call-authorize": "ts-node src/call-sign", | ||
"check-ts": "tsc src/** --skipLibCheck --noEmit", | ||
"lint": "eslint . --ext .ts --format=codeframe", | ||
|
@@ -15,7 +17,7 @@ | |
"fix": "yarn lint:fix && yarn style:fix" | ||
}, | ||
"dependencies": { | ||
"@kiltprotocol/sdk-js": "^0.32.0", | ||
"@kiltprotocol/sdk-js": "0.33.2-dip-2", | ||
"dotenv": "^16.0.1" | ||
}, | ||
"devDependencies": { | ||
|
@@ -27,5 +29,6 @@ | |
"prettier": "^2.7.1", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^4.7.4" | ||
} | ||
} | ||
}, | ||
"packageManager": "[email protected]" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import 'dotenv/config' | ||
|
||
import * as Kilt from '@kiltprotocol/sdk-js' | ||
import { ApiPromise, WsProvider } from '@polkadot/api' | ||
import { dipProviderCalls, types } from '@kiltprotocol/type-definitions' | ||
import { cryptoWaitReady } from '@polkadot/util-crypto' | ||
|
||
import * as utils from './utils' | ||
|
||
async function main() { | ||
const relayWsAddress = process.env[utils.envNames.relayWsAddress] | ||
const providerWsAddress = process.env[utils.envNames.providerWsAddress] | ||
if (relayWsAddress === undefined) { | ||
throw new Error( | ||
`No ${utils.envNames.relayWsAddress} env variable specified.` | ||
) | ||
} | ||
if (providerWsAddress === undefined) { | ||
throw new Error( | ||
`No ${utils.envNames.providerWsAddress} env variable specified.` | ||
) | ||
} | ||
const submitterAddress = process.env[ | ||
utils.envNames.submitterAddress | ||
] as Kilt.KiltAddress | ||
if (submitterAddress === undefined) { | ||
throw new Error( | ||
`No "${utils.envNames.submitterAddress}" env variable specified.` | ||
) | ||
} | ||
|
||
await cryptoWaitReady() | ||
// eslint-disable-next-line max-len | ||
const authKey = | ||
utils.generateAuthenticationKey() ?? | ||
Kilt.Utils.Crypto.makeKeypairFromUri('//Alice') | ||
const assertionKey = utils.generateAttestationKey() | ||
const delegationKey = utils.generateDelegationKey() | ||
|
||
const didUri = process.env[utils.envNames.didUri] as Kilt.DidUri | ||
if (didUri === undefined) { | ||
throw new Error(`"${utils.envNames.didUri}" not specified.`) | ||
} | ||
|
||
const consumerApi = await ApiPromise.create({ | ||
provider: new WsProvider(relayWsAddress), | ||
}) | ||
|
||
const encodedCall = process.env[utils.envNames.encodedCall] | ||
const decodedCall = consumerApi.createType('Call', encodedCall) | ||
|
||
const [requiredKey, verificationMethod] = (() => { | ||
const providedMethod = utils.parseVerificationMethod() | ||
switch (providedMethod) { | ||
case 'authentication': | ||
return [authKey, providedMethod] | ||
case 'assertionMethod': | ||
return [assertionKey, providedMethod] | ||
case 'capabilityDelegation': | ||
return [delegationKey, providedMethod] | ||
} | ||
})() | ||
if (requiredKey === undefined) { | ||
throw new Error( | ||
'The DID key to authorize the operation is not part of the DID Document. Please add such a key before re-trying.' | ||
) | ||
} | ||
|
||
// eslint-disable-next-line max-len | ||
const dipProofVersion = (() => { | ||
if (process.env[utils.envNames.dipProofVersion] !== undefined) { | ||
return parseInt(process.env[utils.envNames.dipProofVersion] as string) | ||
} else { | ||
return utils.defaults.dipProofVersion | ||
} | ||
})() | ||
|
||
const providerApi = await ApiPromise.create({ | ||
provider: new WsProvider(providerWsAddress), | ||
runtime: dipProviderCalls, | ||
types, | ||
}) | ||
const didKeyId = utils.computeDidKeyId( | ||
providerApi, | ||
requiredKey.publicKey, | ||
requiredKey.type | ||
) | ||
|
||
const includeWeb3Name = | ||
process.env[utils.envNames.includeWeb3Name]?.toLowerCase() === 'true' || | ||
utils.defaults.includeWeb3Name | ||
const signedExtrinsic = await utils.generateParentDipTx( | ||
consumerApi, | ||
providerApi, | ||
didUri, | ||
decodedCall, | ||
submitterAddress, | ||
didKeyId, | ||
verificationMethod, | ||
includeWeb3Name, | ||
dipProofVersion, | ||
utils.getKeypairTxSigningCallback(requiredKey) | ||
) | ||
|
||
const encodedOperation = signedExtrinsic.toHex() | ||
console.log( | ||
` | ||
DIP tx: ${encodedOperation}. | ||
Please add these details to the "dipConsumer.dispatchAs" function in PolkadotJS. | ||
` | ||
) | ||
console.log( | ||
`Direct link: ${utils.generatePolkadotJSLink( | ||
relayWsAddress, | ||
encodedOperation | ||
)}` | ||
) | ||
} | ||
|
||
main() | ||
.catch((e) => console.error(e)) | ||
.then(() => process.exit(0)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import 'dotenv/config' | ||
|
||
import * as Kilt from '@kiltprotocol/sdk-js' | ||
import { ApiPromise, WsProvider } from '@polkadot/api' | ||
import { dipProviderCalls, types } from '@kiltprotocol/type-definitions' | ||
import { cryptoWaitReady } from '@polkadot/util-crypto' | ||
|
||
import * as utils from './utils' | ||
|
||
async function main() { | ||
const relayWsAddress = process.env[utils.envNames.relayWsAddress] | ||
const providerWsAddress = process.env[utils.envNames.providerWsAddress] | ||
const consumerWsAddress = process.env[utils.envNames.consumerWsAddress] | ||
if (relayWsAddress === undefined) { | ||
throw new Error( | ||
`No ${utils.envNames.relayWsAddress} env variable specified.` | ||
) | ||
} | ||
if (providerWsAddress === undefined) { | ||
throw new Error( | ||
`No ${utils.envNames.providerWsAddress} env variable specified.` | ||
) | ||
} | ||
if (consumerWsAddress === undefined) { | ||
throw new Error( | ||
`No ${utils.envNames.consumerWsAddress} env variable specified.` | ||
) | ||
} | ||
|
||
const submitterAddress = process.env[ | ||
utils.envNames.submitterAddress | ||
] as Kilt.KiltAddress | ||
if (submitterAddress === undefined) { | ||
throw new Error( | ||
`No "${utils.envNames.submitterAddress}" env variable specified.` | ||
) | ||
} | ||
|
||
await cryptoWaitReady() | ||
// eslint-disable-next-line max-len | ||
const authKey = | ||
utils.generateAuthenticationKey() ?? | ||
Kilt.Utils.Crypto.makeKeypairFromUri('//Alice') | ||
const assertionKey = utils.generateAttestationKey() | ||
const delegationKey = utils.generateDelegationKey() | ||
|
||
const didUri = process.env[utils.envNames.didUri] as Kilt.DidUri | ||
if (didUri === undefined) { | ||
throw new Error(`"${utils.envNames.didUri}" not specified.`) | ||
} | ||
|
||
const consumerApi = await ApiPromise.create({ | ||
provider: new WsProvider(consumerWsAddress), | ||
}) | ||
|
||
const encodedCall = process.env[utils.envNames.encodedCall] | ||
const decodedCall = consumerApi.createType('Call', encodedCall) | ||
|
||
const [requiredKey, verificationMethod] = (() => { | ||
const providedMethod = utils.parseVerificationMethod() | ||
switch (providedMethod) { | ||
case 'authentication': | ||
return [authKey, providedMethod] | ||
case 'assertionMethod': | ||
return [assertionKey, providedMethod] | ||
case 'capabilityDelegation': | ||
return [delegationKey, providedMethod] | ||
} | ||
})() | ||
if (requiredKey === undefined) { | ||
throw new Error( | ||
'The DID key to authorize the operation is not part of the DID Document. Please add such a key before re-trying.' | ||
) | ||
} | ||
|
||
// eslint-disable-next-line max-len | ||
const dipProofVersion = (() => { | ||
if (process.env[utils.envNames.dipProofVersion] !== undefined) { | ||
return parseInt(process.env[utils.envNames.dipProofVersion] as string) | ||
} else { | ||
return utils.defaults.dipProofVersion | ||
} | ||
})() | ||
|
||
const providerApi = await ApiPromise.create({ | ||
provider: new WsProvider(providerWsAddress), | ||
runtime: dipProviderCalls, | ||
types, | ||
}) | ||
const didKeyId = utils.computeDidKeyId( | ||
providerApi, | ||
requiredKey.publicKey, | ||
requiredKey.type | ||
) | ||
|
||
const includeWeb3Name = | ||
process.env[utils.envNames.includeWeb3Name]?.toLowerCase() === 'true' || | ||
utils.defaults.includeWeb3Name | ||
const signedExtrinsic = await utils.generateSiblingDipTx( | ||
await ApiPromise.create({ provider: new WsProvider(relayWsAddress) }), | ||
providerApi, | ||
consumerApi, | ||
didUri, | ||
decodedCall, | ||
submitterAddress, | ||
didKeyId, | ||
verificationMethod, | ||
includeWeb3Name, | ||
dipProofVersion, | ||
utils.getKeypairTxSigningCallback(requiredKey) | ||
) | ||
|
||
const encodedOperation = signedExtrinsic.toHex() | ||
console.log( | ||
` | ||
DIP tx: ${encodedOperation}. | ||
Please add these details to the "dipConsumer.dispatchAs" function in PolkadotJS. | ||
` | ||
) | ||
console.log( | ||
`Direct link: ${utils.generatePolkadotJSLink( | ||
consumerWsAddress, | ||
encodedOperation | ||
)}` | ||
) | ||
} | ||
|
||
main() | ||
.catch((e) => console.error(e)) | ||
.then(() => process.exit(0)) |
Oops, something went wrong.