-
Notifications
You must be signed in to change notification settings - Fork 1
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
17 changed files
with
402 additions
and
167 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
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,2 @@ | ||
// | ||
export const ADDRESS_BYTES_LENGTH = 24; |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './compact'; | ||
export * from './core'; | ||
export * from './signatures'; | ||
export { default as withTemplateAddress } from './withTemplateAddress'; |
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,15 +1,34 @@ | ||
import { Bytes, CodecType, Struct, u8, Vector } from 'scale-ts'; | ||
import { Bytes, CodecType, createCodec, Struct, u8 } from 'scale-ts'; | ||
import { toBytes } from '../utils/hex'; | ||
|
||
export const SingleSig = Bytes(64); | ||
export type SingleSig = Uint8Array; | ||
|
||
export const MultiSig = (n: number) => | ||
Struct({ | ||
SigCfg: u8, | ||
Signatures: Vector(SingleSig, n), | ||
}); | ||
export type MultiSig = CodecType<ReturnType<typeof MultiSig>>; | ||
export const Signatures = createCodec( | ||
(input: Uint8Array[]) => { | ||
const buffer = new Uint8Array(input.length * 64); | ||
input.forEach((sig, i) => { | ||
buffer.set(sig, i * 64); | ||
}); | ||
return buffer; | ||
}, | ||
(input: Uint8Array | string | ArrayBuffer) => { | ||
const signatures: Uint8Array[] = []; | ||
const inputArray = | ||
input instanceof Uint8Array | ||
? input | ||
: typeof input === 'string' | ||
? toBytes(input) | ||
: new Uint8Array(input); | ||
for (let i = 0; i < inputArray.length; i += 64) { | ||
signatures.push(inputArray.slice(i, i + 64)); | ||
} | ||
return signatures; | ||
} | ||
); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export const isMultiSigData = (x: any): x is MultiSig => | ||
x.SigCfg && x.Signatures; | ||
export const MultiSig = Struct({ | ||
SigCfg: u8, | ||
Signatures, | ||
}); | ||
export type MultiSig = CodecType<typeof MultiSig>; |
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,16 +1,17 @@ | ||
export { default as TemplateRegistry } from './registry'; | ||
export { default as Transaction } from './transaction'; | ||
export { default as hash } from './utils/hash'; | ||
export { padBytes, padAddress } from './utils/padBytes'; | ||
export * from './template'; | ||
export * from './codecs/core'; | ||
export * from './codecs/compact'; | ||
export * from './codecs/signatures'; | ||
export { StdTemplates, StdPublicKeys } from './std'; | ||
export { default as SingleSigTemplate } from './std/singlesig'; | ||
|
||
export * as Codecs from './codecs'; | ||
export { default as TemplateRegistry } from './registry'; | ||
|
||
export * from './std'; | ||
export type { | ||
SpawnPayload, | ||
SpendPayload, | ||
TemeplateArgumentsMap, | ||
SpawnTransaction, | ||
SpendTransaction, | ||
} from './std/singlesig'; | ||
} from './std'; | ||
|
||
export { default as SingleSigTemplate } from './std/singlesig'; | ||
export { default as MultiSigTemplate } from './std/multisig'; | ||
export { default as VaultTemplate } from './std/vault'; | ||
export { default as VestingTemplate } from './std/vesting'; |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Codec, Struct } from 'scale-ts'; | ||
import { GasPrice, Nonce } from '../codecs/core'; | ||
|
||
export const TxPayload = <T>(Arguments: Codec<T>) => | ||
Struct({ | ||
Nonce, | ||
GasPrice, | ||
Arguments, | ||
}); |
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,9 +1,67 @@ | ||
import SingleSigTemplate from './singlesig'; | ||
import MultiSigTemplate, { | ||
SpawnArguments as MultiSigSpawnArguments, | ||
} from './multisig'; | ||
import SingleSigTemplate, { | ||
SpawnArguments as SingleSigSpawnArguments, | ||
SpendArguments, | ||
} from './singlesig'; | ||
import VaultTemplate, { SpawnArguments as VaultSpawnArguments } from './vault'; | ||
import VestingTemplate, { | ||
SpawnArguments as VestingSpawnArguments, | ||
DrainArguments, | ||
} from './vesting'; | ||
|
||
export type { | ||
SpawnArguments as SingleSigSpawnArguments, | ||
SpendArguments, | ||
SpawnTransaction, | ||
SpendTransaction, | ||
} from './singlesig'; | ||
export type { SpawnArguments as MultiSigSpawnArguments } from './multisig'; | ||
export type { SpawnArguments as VaultSpawnArguments } from './vault'; | ||
export type { | ||
SpawnArguments as VestingSpawnArguments, | ||
DrainArguments, | ||
} from './vesting'; | ||
|
||
export const StdTemplates = { | ||
[SingleSigTemplate.key]: SingleSigTemplate, | ||
[MultiSigTemplate.key]: MultiSigTemplate, | ||
[VaultTemplate.key]: VaultTemplate, | ||
[VestingTemplate.key]: VestingTemplate, | ||
}; | ||
|
||
export const StdPublicKeys = { | ||
SingleSig: SingleSigTemplate.key, | ||
MultiSig: MultiSigTemplate.key, | ||
Vault: VaultTemplate.key, | ||
Vesting: VestingTemplate.key, | ||
}; | ||
|
||
export const StdMethods = { | ||
Spawn: 0, | ||
Spend: 16, | ||
Drain: 17, | ||
} as const; | ||
|
||
export type StdTemplateKeys = keyof typeof StdTemplates; | ||
|
||
export type StdMethodSelectors = keyof typeof StdMethods; | ||
|
||
export type TemeplateArgumentsMap = { | ||
[SingleSigTemplate.key]: { | ||
[StdMethods.Spawn]: SingleSigSpawnArguments; | ||
[StdMethods.Spend]: SpendArguments; | ||
}; | ||
[MultiSigTemplate.key]: { | ||
[StdMethods.Spawn]: MultiSigSpawnArguments; | ||
[StdMethods.Spend]: SpendArguments; | ||
}; | ||
[VaultTemplate.key]: { | ||
[StdMethods.Spawn]: VaultSpawnArguments; | ||
}; | ||
[VestingTemplate.key]: { | ||
[StdMethods.Spawn]: VestingSpawnArguments; | ||
[StdMethods.Drain]: DrainArguments; | ||
}; | ||
}; |
Oops, something went wrong.